This repository was archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 391
Expand file tree
/
Copy pathtest_api.py
More file actions
executable file
·92 lines (72 loc) · 2.19 KB
/
Copy pathtest_api.py
File metadata and controls
executable file
·92 lines (72 loc) · 2.19 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import pytest
import requests
from fixtures import get_order, get_product, iam_auth # pylint: disable=import-error,no-name-in-module
from helpers import compare_dict, get_parameter # pylint: disable=import-error,no-name-in-module
@pytest.fixture(scope="module")
def endpoint_url():
return get_parameter("/ecommerce/{Environment}/delivery-pricing/api/url")
@pytest.fixture(scope="function")
def order(get_order):
return get_order()
def test_backend_pricing(endpoint_url, iam_auth, order):
"""
Test POST /backend/pricing
"""
res = requests.post(
"{}/backend/pricing".format(endpoint_url),
auth=iam_auth(endpoint_url),
json={
"products": order["products"],
"address": order["address"]
}
)
assert res.status_code == 200
body = res.json()
assert "pricing" in body
def test_backend_pricing_no_iam(endpoint_url, iam_auth, order):
"""
Test POST /backend/pricing
"""
res = requests.post(
"{}/backend/pricing".format(endpoint_url),
json={
"products": order["products"],
"address": order["address"]
}
)
assert res.status_code == 403
body = res.json()
assert "message" in body
assert isinstance(body["message"], str)
def test_backend_pricing_no_products(endpoint_url, iam_auth, order):
"""
Test POST /backend/pricing
"""
res = requests.post(
"{}/backend/pricing".format(endpoint_url),
auth=iam_auth(endpoint_url),
json={
"address": order["address"]
}
)
assert res.status_code == 400
body = res.json()
assert "message" in body
assert isinstance(body["message"], str)
assert "products" in body["message"]
def test_backend_pricing_no_address(endpoint_url, iam_auth, order):
"""
Test POST /backend/pricing
"""
res = requests.post(
"{}/backend/pricing".format(endpoint_url),
auth=iam_auth(endpoint_url),
json={
"products": order["products"]
}
)
assert res.status_code == 400
body = res.json()
assert "message" in body
assert isinstance(body["message"], str)
assert "address" in body["message"]