shop product refactoring
This commit is contained in:
@@ -183,9 +183,9 @@ class TestShopsAPI:
|
||||
|
||||
def test_add_product_to_shop_success(self, client, auth_headers, test_shop, unique_product):
|
||||
"""Test adding product to shop successfully"""
|
||||
shop_product_data = {
|
||||
product_data = {
|
||||
"marketplace_product_id": unique_product.marketplace_product_id, # Use string marketplace_product_id, not database id
|
||||
"shop_price": 29.99,
|
||||
"price": 29.99,
|
||||
"is_active": True,
|
||||
"is_featured": False,
|
||||
}
|
||||
@@ -193,7 +193,7 @@ class TestShopsAPI:
|
||||
response = client.post(
|
||||
f"/api/v1/shop/{test_shop.shop_code}/products",
|
||||
headers=auth_headers,
|
||||
json=shop_product_data
|
||||
json=product_data
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -201,21 +201,21 @@ class TestShopsAPI:
|
||||
|
||||
# The response structure contains nested product data
|
||||
assert data["shop_id"] == test_shop.id
|
||||
assert data["shop_price"] == 29.99
|
||||
assert data["price"] == 29.99
|
||||
assert data["is_active"] is True
|
||||
assert data["is_featured"] is False
|
||||
|
||||
# MarketplaceProduct details are nested in the 'product' field
|
||||
assert "product" in data
|
||||
assert data["product"]["marketplace_product_id"] == unique_product.marketplace_product_id
|
||||
assert data["product"]["id"] == unique_product.id
|
||||
# MarketplaceProduct details are nested in the 'marketplace_product' field
|
||||
assert "marketplace_product" in data
|
||||
assert data["marketplace_product"]["marketplace_product_id"] == unique_product.marketplace_product_id
|
||||
assert data["marketplace_product"]["id"] == unique_product.id
|
||||
|
||||
def test_add_product_to_shop_already_exists_conflict(self, client, auth_headers, test_shop, shop_product):
|
||||
"""Test adding product that already exists in shop returns ShopProductAlreadyExistsException"""
|
||||
# shop_product fixture already creates a relationship, get the marketplace_product_id string
|
||||
existing_product = shop_product.product
|
||||
def test_add_product_to_shop_already_exists_conflict(self, client, auth_headers, test_shop, test_product):
|
||||
"""Test adding product that already exists in shop returns ProductAlreadyExistsException"""
|
||||
# test_product fixture already creates a relationship, get the marketplace_product_id string
|
||||
existing_product = test_product.marketplace_product
|
||||
|
||||
shop_product_data = {
|
||||
product_data = {
|
||||
"marketplace_product_id": existing_product.marketplace_product_id, # Use string marketplace_product_id
|
||||
"shop_price": 29.99,
|
||||
}
|
||||
@@ -223,19 +223,19 @@ class TestShopsAPI:
|
||||
response = client.post(
|
||||
f"/api/v1/shop/{test_shop.shop_code}/products",
|
||||
headers=auth_headers,
|
||||
json=shop_product_data
|
||||
json=product_data
|
||||
)
|
||||
|
||||
assert response.status_code == 409
|
||||
data = response.json()
|
||||
assert data["error_code"] == "SHOP_PRODUCT_ALREADY_EXISTS"
|
||||
assert data["error_code"] == "PRODUCT_ALREADY_EXISTS"
|
||||
assert data["status_code"] == 409
|
||||
assert test_shop.shop_code in data["message"]
|
||||
assert existing_product.marketplace_product_id in data["message"]
|
||||
|
||||
def test_add_nonexistent_product_to_shop_not_found(self, client, auth_headers, test_shop):
|
||||
"""Test adding nonexistent product to shop returns MarketplaceProductNotFoundException"""
|
||||
shop_product_data = {
|
||||
product_data = {
|
||||
"marketplace_product_id": "NONEXISTENT_PRODUCT", # Use string marketplace_product_id that doesn't exist
|
||||
"shop_price": 29.99,
|
||||
}
|
||||
@@ -243,7 +243,7 @@ class TestShopsAPI:
|
||||
response = client.post(
|
||||
f"/api/v1/shop/{test_shop.shop_code}/products",
|
||||
headers=auth_headers,
|
||||
json=shop_product_data
|
||||
json=product_data
|
||||
)
|
||||
|
||||
assert response.status_code == 404
|
||||
@@ -252,7 +252,7 @@ class TestShopsAPI:
|
||||
assert data["status_code"] == 404
|
||||
assert "NONEXISTENT_PRODUCT" in data["message"]
|
||||
|
||||
def test_get_shop_products_success(self, client, auth_headers, test_shop, shop_product):
|
||||
def test_get_products_success(self, client, auth_headers, test_shop, test_product):
|
||||
"""Test getting shop products successfully"""
|
||||
response = client.get(
|
||||
f"/api/v1/shop/{test_shop.shop_code}/products",
|
||||
@@ -266,7 +266,7 @@ class TestShopsAPI:
|
||||
assert "shop" in data
|
||||
assert data["shop"]["shop_code"] == test_shop.shop_code
|
||||
|
||||
def test_get_shop_products_with_filters(self, client, auth_headers, test_shop):
|
||||
def test_get_products_with_filters(self, client, auth_headers, test_shop):
|
||||
"""Test getting shop products with filtering"""
|
||||
# Test active_only filter
|
||||
response = client.get(
|
||||
|
||||
Reference in New Issue
Block a user