53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
# tests/test_marketplace.py
|
|
import pytest
|
|
from unittest.mock import patch, AsyncMock
|
|
|
|
|
|
class TestMarketplaceAPI:
|
|
@patch('utils.csv_processor.CSVProcessor.process_marketplace_csv_from_url')
|
|
def test_import_from_marketplace(self, mock_process, client, auth_headers, test_shop):
|
|
"""Test marketplace import endpoint"""
|
|
mock_process.return_value = AsyncMock()
|
|
|
|
import_data = {
|
|
"url": "https://example.com/products.csv",
|
|
"marketplace": "TestMarket",
|
|
"shop_code": test_shop.shop_code
|
|
}
|
|
|
|
response = client.post("/api/v1/marketplace/import-from-marketplace",
|
|
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
|
|
|
|
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-from-marketplace",
|
|
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/marketplace-import-jobs", headers=auth_headers)
|
|
|
|
assert response.status_code == 200
|
|
assert isinstance(response.json(), list)
|
|
|
|
def test_marketplace_requires_auth(self, client):
|
|
"""Test that marketplace endpoints require authentication"""
|
|
response = client.get("/api/v1/marketplace/marketplace-import-jobs")
|
|
assert response.status_code == 403
|
|
|