forked from diegopereiraeng/harness-tpm-ci-bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
34 lines (28 loc) · 1 KB
/
test.py
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
# Python API Test Script
import requests
def test_list_products():
response = requests.get("http://localhost:8080/products")
assert response.status_code == 200
assert len(response.json()) == 2
def test_add_to_cart():
response = requests.post("http://localhost:8080/products/cart/1")
assert response.status_code == 200
assert response.text == "Product added to cart"
def test_list_cart():
test_add_to_cart() # Ensure cart is not empty
response = requests.get("http://localhost:8080/products/cart")
assert response.status_code == 200
assert len(response.json()) == 1
def test_pay_cart():
test_add_to_cart() # Ensure cart is not empty
response = requests.post("http://localhost:8080/products/cart/pay")
assert response.status_code == 200
assert response.text == "Payment successful"
def run_tests():
test_list_products()
test_add_to_cart()
test_list_cart()
test_pay_cart()
print("All tests passed.")
if __name__ == "__main__":
run_tests()