|
|
|
|
@@ -15,7 +15,7 @@ class TestVendorsAPI:
|
|
|
|
|
"description": "A new test vendor ",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
|
|
|
|
|
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
data = response.json()
|
|
|
|
|
@@ -31,7 +31,7 @@ class TestVendorsAPI:
|
|
|
|
|
"description": "Different description",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
|
|
|
|
|
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 409
|
|
|
|
|
data = response.json()
|
|
|
|
|
@@ -47,7 +47,7 @@ class TestVendorsAPI:
|
|
|
|
|
"description": "Missing vendor code",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
|
|
|
|
|
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 422
|
|
|
|
|
data = response.json()
|
|
|
|
|
@@ -64,7 +64,7 @@ class TestVendorsAPI:
|
|
|
|
|
"description": "Vendor with empty name",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
|
|
|
|
|
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 422
|
|
|
|
|
data = response.json()
|
|
|
|
|
@@ -87,7 +87,7 @@ class TestVendorsAPI:
|
|
|
|
|
|
|
|
|
|
def test_get_vendors_success(self, client, auth_headers, test_vendor):
|
|
|
|
|
"""Test getting vendors list successfully"""
|
|
|
|
|
response = client.get("/api/v1/vendor ", headers=auth_headers)
|
|
|
|
|
response = client.get("/api/v1/vendor", headers=auth_headers)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
data = response.json()
|
|
|
|
|
@@ -101,21 +101,21 @@ class TestVendorsAPI:
|
|
|
|
|
def test_get_vendors_with_filters(self, client, auth_headers, test_vendor):
|
|
|
|
|
"""Test getting vendors with filtering options"""
|
|
|
|
|
# Test active_only filter
|
|
|
|
|
response = client.get("/api/v1/vendor ?active_only=true", headers=auth_headers)
|
|
|
|
|
response = client.get("/api/v1/vendor?active_only=true", headers=auth_headers)
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
data = response.json()
|
|
|
|
|
for vendor in data["vendors"]:
|
|
|
|
|
assert vendor ["is_active"] is True
|
|
|
|
|
|
|
|
|
|
# Test verified_only filter
|
|
|
|
|
response = client.get("/api/v1/vendor ?verified_only=true", headers=auth_headers)
|
|
|
|
|
response = client.get("/api/v1/vendor?verified_only=true", headers=auth_headers)
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
# Response should only contain verified vendors
|
|
|
|
|
|
|
|
|
|
def test_get_vendor_by_code_success(self, client, auth_headers, test_vendor):
|
|
|
|
|
"""Test getting specific vendor successfully"""
|
|
|
|
|
response = client.get(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
@@ -125,7 +125,7 @@ class TestVendorsAPI:
|
|
|
|
|
|
|
|
|
|
def test_get_vendor_by_code_not_found(self, client, auth_headers):
|
|
|
|
|
"""Test getting nonexistent vendor returns VendorNotFoundException"""
|
|
|
|
|
response = client.get("/api/v1/vendor /NONEXISTENT", headers=auth_headers)
|
|
|
|
|
response = client.get("/api/v1/vendor/NONEXISTENT", headers=auth_headers)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 404
|
|
|
|
|
data = response.json()
|
|
|
|
|
@@ -144,7 +144,7 @@ class TestVendorsAPI:
|
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
|
|
response = client.get(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 403
|
|
|
|
|
@@ -158,7 +158,7 @@ class TestVendorsAPI:
|
|
|
|
|
"""Test accessing inactive vendor owned by another user returns UnauthorizedVendorAccessException"""
|
|
|
|
|
# inactive_vendor fixture already creates an unverified, inactive vendor owned by other_user
|
|
|
|
|
response = client.get(
|
|
|
|
|
f"/api/v1/vendor /{inactive_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
f"/api/v1/vendor/{inactive_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 403
|
|
|
|
|
@@ -173,7 +173,7 @@ class TestVendorsAPI:
|
|
|
|
|
# verified_vendor fixture creates a verified, active vendor owned by other_user
|
|
|
|
|
# This should allow public access per your business logic
|
|
|
|
|
response = client.get(
|
|
|
|
|
f"/api/v1/vendor /{verified_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
f"/api/v1/vendor/{verified_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
@@ -191,7 +191,7 @@ class TestVendorsAPI:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = client.post(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
|
|
|
|
headers=auth_headers,
|
|
|
|
|
json=product_data
|
|
|
|
|
)
|
|
|
|
|
@@ -221,7 +221,7 @@ class TestVendorsAPI:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = client.post(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
|
|
|
|
headers=auth_headers,
|
|
|
|
|
json=product_data
|
|
|
|
|
)
|
|
|
|
|
@@ -241,7 +241,7 @@ class TestVendorsAPI:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = client.post(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
|
|
|
|
headers=auth_headers,
|
|
|
|
|
json=product_data
|
|
|
|
|
)
|
|
|
|
|
@@ -255,7 +255,7 @@ class TestVendorsAPI:
|
|
|
|
|
def test_get_products_success(self, client, auth_headers, test_vendor, test_product):
|
|
|
|
|
"""Test getting vendor products successfully"""
|
|
|
|
|
response = client.get(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
|
|
|
|
headers=auth_headers
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -263,21 +263,21 @@ class TestVendorsAPI:
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert data["total"] >= 1
|
|
|
|
|
assert len(data["products"]) >= 1
|
|
|
|
|
assert "vendor " in data
|
|
|
|
|
assert data["vendor "]["vendor_code"] == test_vendor.vendor_code
|
|
|
|
|
assert "vendor" in data
|
|
|
|
|
assert data["vendor"]["vendor_code"] == test_vendor.vendor_code
|
|
|
|
|
|
|
|
|
|
def test_get_products_with_filters(self, client, auth_headers, test_vendor):
|
|
|
|
|
"""Test getting vendor products with filtering"""
|
|
|
|
|
# Test active_only filter
|
|
|
|
|
response = client.get(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}/products?active_only=true",
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}/products?active_only=true",
|
|
|
|
|
headers=auth_headers
|
|
|
|
|
)
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
|
|
|
|
# Test featured_only filter
|
|
|
|
|
response = client.get(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}/products?featured_only=true",
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}/products?featured_only=true",
|
|
|
|
|
headers=auth_headers
|
|
|
|
|
)
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
@@ -285,7 +285,7 @@ class TestVendorsAPI:
|
|
|
|
|
def test_get_products_from_nonexistent_vendor_not_found(self, client, auth_headers):
|
|
|
|
|
"""Test getting products from nonexistent vendor returns VendorNotFoundException"""
|
|
|
|
|
response = client.get(
|
|
|
|
|
"/api/v1/vendor /NONEXISTENT/products",
|
|
|
|
|
"/api/v1/vendor/NONEXISTENT/products",
|
|
|
|
|
headers=auth_headers
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -303,7 +303,7 @@ class TestVendorsAPI:
|
|
|
|
|
|
|
|
|
|
# Depending on your business logic, this might return an error
|
|
|
|
|
response = client.get(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}", headers=auth_headers
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# If your service enforces active vendor requirement
|
|
|
|
|
@@ -326,7 +326,7 @@ class TestVendorsAPI:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = client.post(
|
|
|
|
|
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
|
|
|
|
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
|
|
|
|
headers=auth_headers,
|
|
|
|
|
json=product_data
|
|
|
|
|
)
|
|
|
|
|
@@ -340,7 +340,7 @@ class TestVendorsAPI:
|
|
|
|
|
|
|
|
|
|
def test_get_vendor_without_auth_returns_invalid_token(self, client):
|
|
|
|
|
"""Test that vendor endpoints require authentication returns InvalidTokenException"""
|
|
|
|
|
response = client.get("/api/v1/vendor ")
|
|
|
|
|
response = client.get("/api/v1/vendor")
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 401
|
|
|
|
|
data = response.json()
|
|
|
|
|
@@ -350,19 +350,19 @@ class TestVendorsAPI:
|
|
|
|
|
def test_pagination_validation_errors(self, client, auth_headers):
|
|
|
|
|
"""Test pagination parameter validation"""
|
|
|
|
|
# Test negative skip
|
|
|
|
|
response = client.get("/api/v1/vendor ?skip=-1", headers=auth_headers)
|
|
|
|
|
response = client.get("/api/v1/vendor?skip=-1", headers=auth_headers)
|
|
|
|
|
assert response.status_code == 422
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert data["error_code"] == "VALIDATION_ERROR"
|
|
|
|
|
|
|
|
|
|
# Test zero limit
|
|
|
|
|
response = client.get("/api/v1/vendor ?limit=0", headers=auth_headers)
|
|
|
|
|
response = client.get("/api/v1/vendor?limit=0", headers=auth_headers)
|
|
|
|
|
assert response.status_code == 422
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert data["error_code"] == "VALIDATION_ERROR"
|
|
|
|
|
|
|
|
|
|
# Test excessive limit
|
|
|
|
|
response = client.get("/api/v1/vendor ?limit=10000", headers=auth_headers)
|
|
|
|
|
response = client.get("/api/v1/vendor?limit=10000", headers=auth_headers)
|
|
|
|
|
assert response.status_code == 422
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert data["error_code"] == "VALIDATION_ERROR"
|
|
|
|
|
@@ -370,7 +370,7 @@ class TestVendorsAPI:
|
|
|
|
|
def test_exception_structure_consistency(self, client, auth_headers):
|
|
|
|
|
"""Test that all vendor exceptions follow the consistent LetzShopException structure"""
|
|
|
|
|
# Test with a known error case
|
|
|
|
|
response = client.get("/api/v1/vendor /NONEXISTENT", headers=auth_headers)
|
|
|
|
|
response = client.get("/api/v1/vendor/NONEXISTENT", headers=auth_headers)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 404
|
|
|
|
|
data = response.json()
|
|
|
|
|
|