-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatures_load_steps.py
More file actions
34 lines (31 loc) · 1.07 KB
/
features_load_steps.py
File metadata and controls
34 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
from behave import given
# HTTP Return Codes
HTTP_200_OK = 200
HTTP_201_CREATED = 201
HTTP_204_NO_CONTENT = 204
@given('the following products')
def step_impl(context):
""" Delete all Products and load new ones """
#
# List all of the products and delete them one by one
#
rest_endpoint = f"{context.base_url}/products"
context.resp = requests.get(rest_endpoint)
assert(context.resp.status_code == HTTP_200_OK)
for product in context.resp.json():
context.resp = requests.delete(f"{rest_endpoint}/{product['id']}")
assert(context.resp.status_code == HTTP_204_NO_CONTENT)
#
# load the database with new products
#
for row in context.table:
payload = {
"name": row['name'],
"description": row['description'],
"price": row['price'],
"available": row['available'] in ['True', 'true', '1'],
"category": row['category']
}
context.resp = requests.post(rest_endpoint, json=payload)
assert context.resp.status_code == HTTP_201_CREATED