|
|
@@ -11,7 +11,7 @@ from starsessions import (
|
|
|
|
|
|
from app.main import app
|
|
|
|
|
|
-client = TestClient(app)
|
|
|
+client = TestClient(app, base_url="http://127.0.0.1:5014")
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
@@ -39,31 +39,19 @@ def prepare_request(product_id: str) -> tuple[dict[str, str], str]:
|
|
|
tree = html.fromstring(response_get.content)
|
|
|
csrf_token = tree.xpath("//input[@name='csrftoken']")[0].get("value")
|
|
|
|
|
|
- return (headers, csrf_token)
|
|
|
+ return headers, csrf_token
|
|
|
|
|
|
|
|
|
-def test_add_product(capsys, app_csrf, session_store):
|
|
|
- """Run tests for:
|
|
|
- - adding a product with no options (size, style), good
|
|
|
- - adding a product with no options, bad (wrong query, missing param)
|
|
|
- - adding a product with options, good
|
|
|
- - adding a product with options, bad (wrong options)
|
|
|
-
|
|
|
- - removing a product with no options (size, style), good
|
|
|
- - removing a product with no options, bad (wrong query, missing param)
|
|
|
- - removing a product with options, good
|
|
|
- - removing a product with options, bad (wrong options)
|
|
|
-
|
|
|
- - remove a product entirely using the remove button
|
|
|
- """
|
|
|
- # -- product with no options (size, style)
|
|
|
- headers_no_options, csrf_token_no_options = prepare_request("cap-01")
|
|
|
+def test_add_simple_product(capsys, app_csrf, session_store):
|
|
|
+ """Add simple product"""
|
|
|
+
|
|
|
+ headers_no_options, csrf_token_no_options = prepare_request("g-axxi-i")
|
|
|
|
|
|
data_good_no_options_add = {
|
|
|
"page": "product",
|
|
|
"operation": "add",
|
|
|
- "product_id": "stripe_product_abc",
|
|
|
- "product_path": "products/cap-01",
|
|
|
+ "product_id": "price_1PTPnFKMYdpilqPdArvtszSN",
|
|
|
+ "product_path": "products/g-axxi-i",
|
|
|
"price": 30,
|
|
|
"quantity": 2,
|
|
|
"csrftoken": csrf_token_no_options,
|
|
|
@@ -78,11 +66,16 @@ def test_add_product(capsys, app_csrf, session_store):
|
|
|
|
|
|
assert response_good_no_options_add.status_code == 200
|
|
|
|
|
|
+def test_remove_simple_product(capsys, app_csrf, session_store):
|
|
|
+ """removing a product with no options (size, style), good """
|
|
|
+
|
|
|
+ headers_no_options, csrf_token_no_options = prepare_request("g-axxi-i")
|
|
|
+
|
|
|
data_good_no_options_remove = {
|
|
|
"page": "product",
|
|
|
"operation": "remove",
|
|
|
- "product_id": "stripe_product_abc",
|
|
|
- "product_path": "products/cap-01",
|
|
|
+ "product_id": "price_1PTPnFKMYdpilqPdArvtszSN",
|
|
|
+ "product_path": "products/g-axxi-i",
|
|
|
"price": 30,
|
|
|
"quantity": 1,
|
|
|
"csrftoken": csrf_token_no_options,
|
|
|
@@ -94,14 +87,16 @@ def test_add_product(capsys, app_csrf, session_store):
|
|
|
|
|
|
assert response_good_no_options_remove.status_code == 200
|
|
|
|
|
|
- # wrong options
|
|
|
+def test_wrong_request_simple_product(capsys, app_csrf, session_store):
|
|
|
+ # Product operation with wrong query
|
|
|
+
|
|
|
+ headers_no_options, csrf_token_no_options = prepare_request("g-axxi-i")
|
|
|
+
|
|
|
data_bad_no_options_wrong_add = {
|
|
|
"page": "product",
|
|
|
- "product_id": "stripe_product_abc",
|
|
|
- "product_path": "products/cap-01",
|
|
|
+ "product_id": "price_1PTPnFKMYdpilqPdArvtszSN",
|
|
|
+ "product_path": "products/g-axxi-i",
|
|
|
"price": 30,
|
|
|
- "size": None,
|
|
|
- "style": "black",
|
|
|
"quantity": 2,
|
|
|
"csrftoken": csrf_token_no_options,
|
|
|
}
|
|
|
@@ -112,32 +107,15 @@ def test_add_product(capsys, app_csrf, session_store):
|
|
|
|
|
|
assert response_bad_no_options_add.status_code == 422
|
|
|
|
|
|
- data_bad_no_options_wrong_remove = {
|
|
|
- "page": "product",
|
|
|
- "product_id": "stripe_product_abc",
|
|
|
- "product_path": "products/cap-01",
|
|
|
- "price": 30,
|
|
|
- "size": None,
|
|
|
- "style": "black",
|
|
|
- "quantity": 2,
|
|
|
- "csrftoken": csrf_token_no_options,
|
|
|
- }
|
|
|
-
|
|
|
- response_bad_no_options_remove = client.post(
|
|
|
- "/checkout", data=data_bad_no_options_wrong_remove, headers=headers_no_options
|
|
|
- )
|
|
|
-
|
|
|
- assert response_bad_no_options_remove.status_code == 422
|
|
|
-
|
|
|
- # -- product with options (size, style)
|
|
|
-
|
|
|
- headers_with_options, csrf_token_with_options = prepare_request("tshirt-darkfi")
|
|
|
+def test_add_product(capsys, app_csrf, session_store):
|
|
|
+ """ Adding a product with size/style """
|
|
|
+ headers_with_options, csrf_token_with_options = prepare_request("a-tshirt-01")
|
|
|
|
|
|
data_good_with_options_add = {
|
|
|
"page": "product",
|
|
|
"operation": "add",
|
|
|
- "product_id": "stripe_product_tshirt-df",
|
|
|
- "product_path": "products/tshirt-darkfi",
|
|
|
+ "product_id": "prod_RZBk650b1Tx95N",
|
|
|
+ "product_path": "products/a-tshirt-01",
|
|
|
"price": 50,
|
|
|
"quantity": 3,
|
|
|
"size": "m",
|
|
|
@@ -151,11 +129,15 @@ def test_add_product(capsys, app_csrf, session_store):
|
|
|
|
|
|
assert response_good_with_options_add.status_code == 200
|
|
|
|
|
|
+def test_remove_product(capsys, app_csrf, session_store):
|
|
|
+ """ Removing product with size/style """
|
|
|
+ headers_with_options, csrf_token_with_options = prepare_request("a-tshirt-01")
|
|
|
+
|
|
|
data_good_with_options_remove = {
|
|
|
"page": "product",
|
|
|
"operation": "remove",
|
|
|
- "product_id": "stripe_product_tshirt-df",
|
|
|
- "product_path": "products/tshirt-darkfi",
|
|
|
+ "product_id": "stripe_product_tshirt-aus",
|
|
|
+ "product_path": "products/a-tshirt-01",
|
|
|
"price": 50,
|
|
|
"quantity": 2,
|
|
|
"size": "m",
|
|
|
@@ -169,12 +151,15 @@ def test_add_product(capsys, app_csrf, session_store):
|
|
|
|
|
|
assert response_good_with_options_remove.status_code == 200
|
|
|
|
|
|
- # wrong options
|
|
|
+def test_add_product_wrong_options(capsys, app_csrf, session_store):
|
|
|
+ """ Trying to add product with wrong size/style """
|
|
|
+ headers_with_options, csrf_token_with_options = prepare_request("a-tshirt-01")
|
|
|
+
|
|
|
data_bad_with_options_wrong_add = {
|
|
|
"page": "product",
|
|
|
"operation": "add",
|
|
|
- "product_id": "stripe_product_tshirt-df",
|
|
|
- "product_path": "products/tshirt-darkfi",
|
|
|
+ "product_id": "prod_RZBk650b1Tx95N",
|
|
|
+ "product_path": "products/a-tshirt-01",
|
|
|
"price": 50,
|
|
|
"quantity": 5,
|
|
|
"size": "x",
|
|
|
@@ -188,11 +173,15 @@ def test_add_product(capsys, app_csrf, session_store):
|
|
|
|
|
|
assert response_bad_with_options_add.status_code == 422
|
|
|
|
|
|
+def test_remove_product_wrong_options(capsys, app_csrf, session_store):
|
|
|
+ """ Trying to remove product with wrong size/style """
|
|
|
+ headers_with_options, csrf_token_with_options = prepare_request("a-tshirt-01")
|
|
|
+
|
|
|
data_bad_with_options_wrong_remove = {
|
|
|
"page": "product",
|
|
|
"operation": "remove",
|
|
|
- "product_id": "stripe_product_tshirt-df",
|
|
|
- "product_path": "products/tshirt-darkfi",
|
|
|
+ "product_id": "prod_RZBk650b1Tx95N",
|
|
|
+ "product_path": "products/a-tshirt-01",
|
|
|
"price": 50,
|
|
|
"quantity": 5,
|
|
|
"size": "x",
|