53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
# tests/test_marketplace.py
|
|
import pytest
|
|
from unittest.mock import patch, AsyncMock
|
|
|
|
|
|
class TestMarketplaceAPI:
|
|
def test_import_from_marketplace(self, client, auth_headers, test_shop):
|
|
"""Test marketplace import endpoint - just test job creation"""
|
|
|
|
import_data = {
|
|
"url": "https://example.com/products.csv",
|
|
"marketplace": "TestMarket",
|
|
"shop_code": test_shop.shop_code
|
|
}
|
|
|
|
response = client.post("/api/v1/marketplace/import-product",
|
|
headers=auth_headers, json=import_data)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "pending"
|
|
assert data["marketplace"] == "TestMarket"
|
|
assert "job_id" in data
|
|
|
|
# Don't test the background task here - test it separately
|
|
|
|
def test_import_from_marketplace_invalid_shop(self, client, auth_headers):
|
|
"""Test marketplace import with invalid shop"""
|
|
import_data = {
|
|
"url": "https://example.com/products.csv",
|
|
"marketplace": "TestMarket",
|
|
"shop_code": "NONEXISTENT"
|
|
}
|
|
|
|
response = client.post("/api/v1/marketplace/import-product",
|
|
headers=auth_headers, json=import_data)
|
|
|
|
assert response.status_code == 404
|
|
assert "Shop not found" in response.json()["detail"]
|
|
|
|
def test_get_marketplace_import_jobs(self, client, auth_headers):
|
|
"""Test getting marketplace import jobs"""
|
|
response = client.get("/api/v1/marketplace/import-jobs", headers=auth_headers)
|
|
|
|
assert response.status_code == 200
|
|
assert isinstance(response.json(), list)
|
|
|
|
def test_get_marketplace_without_auth(self, client):
|
|
"""Test that marketplace endpoints require authentication"""
|
|
response = client.get("/api/v1/marketplace/import-jobs")
|
|
assert response.status_code == 401 # No authorization header
|
|
|