code quality run
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
# tests/test_admin_service.py
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.services.admin_service import AdminService
|
||||
from models.database_models import User, Shop, MarketplaceImportJob
|
||||
from models.database_models import MarketplaceImportJob, Shop, User
|
||||
|
||||
|
||||
class TestAdminService:
|
||||
@@ -91,7 +92,7 @@ class TestAdminService:
|
||||
shop_name="Test Shop 2",
|
||||
owner_id=test_shop.owner_id,
|
||||
is_active=True,
|
||||
is_verified=False
|
||||
is_verified=False,
|
||||
)
|
||||
db.add(additional_shop)
|
||||
db.commit()
|
||||
@@ -173,13 +174,17 @@ class TestAdminService:
|
||||
|
||||
assert len(result) >= 1
|
||||
# Find our test job in the results
|
||||
test_job = next((job for job in result if job.job_id == test_marketplace_job.id), None)
|
||||
test_job = next(
|
||||
(job for job in result if job.job_id == test_marketplace_job.id), None
|
||||
)
|
||||
assert test_job is not None
|
||||
assert test_job.marketplace == test_marketplace_job.marketplace
|
||||
assert test_job.shop_name == test_marketplace_job.shop_name
|
||||
assert test_job.status == test_marketplace_job.status
|
||||
|
||||
def test_get_marketplace_import_jobs_with_marketplace_filter(self, db, test_marketplace_job, test_user, test_shop):
|
||||
def test_get_marketplace_import_jobs_with_marketplace_filter(
|
||||
self, db, test_marketplace_job, test_user, test_shop
|
||||
):
|
||||
"""Test getting marketplace import jobs filtered by marketplace"""
|
||||
# Create additional job with different marketplace
|
||||
other_job = MarketplaceImportJob(
|
||||
@@ -188,20 +193,24 @@ class TestAdminService:
|
||||
status="completed",
|
||||
source_url="https://ebay.example.com/import",
|
||||
shop_id=test_shop.id,
|
||||
user_id=test_user.id # Fixed: Added missing user_id
|
||||
user_id=test_user.id, # Fixed: Added missing user_id
|
||||
)
|
||||
db.add(other_job)
|
||||
db.commit()
|
||||
|
||||
# Filter by the test marketplace job's marketplace
|
||||
result = self.service.get_marketplace_import_jobs(db, marketplace=test_marketplace_job.marketplace)
|
||||
result = self.service.get_marketplace_import_jobs(
|
||||
db, marketplace=test_marketplace_job.marketplace
|
||||
)
|
||||
|
||||
assert len(result) >= 1
|
||||
# All results should match the marketplace filter
|
||||
for job in result:
|
||||
assert test_marketplace_job.marketplace.lower() in job.marketplace.lower()
|
||||
|
||||
def test_get_marketplace_import_jobs_with_shop_filter(self, db, test_marketplace_job, test_user, test_shop):
|
||||
def test_get_marketplace_import_jobs_with_shop_filter(
|
||||
self, db, test_marketplace_job, test_user, test_shop
|
||||
):
|
||||
"""Test getting marketplace import jobs filtered by shop name"""
|
||||
# Create additional job with different shop name
|
||||
other_job = MarketplaceImportJob(
|
||||
@@ -210,20 +219,24 @@ class TestAdminService:
|
||||
status="completed",
|
||||
source_url="https://different.example.com/import",
|
||||
shop_id=test_shop.id,
|
||||
user_id=test_user.id # Fixed: Added missing user_id
|
||||
user_id=test_user.id, # Fixed: Added missing user_id
|
||||
)
|
||||
db.add(other_job)
|
||||
db.commit()
|
||||
|
||||
# Filter by the test marketplace job's shop name
|
||||
result = self.service.get_marketplace_import_jobs(db, shop_name=test_marketplace_job.shop_name)
|
||||
result = self.service.get_marketplace_import_jobs(
|
||||
db, shop_name=test_marketplace_job.shop_name
|
||||
)
|
||||
|
||||
assert len(result) >= 1
|
||||
# All results should match the shop name filter
|
||||
for job in result:
|
||||
assert test_marketplace_job.shop_name.lower() in job.shop_name.lower()
|
||||
|
||||
def test_get_marketplace_import_jobs_with_status_filter(self, db, test_marketplace_job, test_user, test_shop):
|
||||
def test_get_marketplace_import_jobs_with_status_filter(
|
||||
self, db, test_marketplace_job, test_user, test_shop
|
||||
):
|
||||
"""Test getting marketplace import jobs filtered by status"""
|
||||
# Create additional job with different status
|
||||
other_job = MarketplaceImportJob(
|
||||
@@ -232,20 +245,24 @@ class TestAdminService:
|
||||
status="pending",
|
||||
source_url="https://pending.example.com/import",
|
||||
shop_id=test_shop.id,
|
||||
user_id=test_user.id # Fixed: Added missing user_id
|
||||
user_id=test_user.id, # Fixed: Added missing user_id
|
||||
)
|
||||
db.add(other_job)
|
||||
db.commit()
|
||||
|
||||
# Filter by the test marketplace job's status
|
||||
result = self.service.get_marketplace_import_jobs(db, status=test_marketplace_job.status)
|
||||
result = self.service.get_marketplace_import_jobs(
|
||||
db, status=test_marketplace_job.status
|
||||
)
|
||||
|
||||
assert len(result) >= 1
|
||||
# All results should match the status filter
|
||||
for job in result:
|
||||
assert job.status == test_marketplace_job.status
|
||||
|
||||
def test_get_marketplace_import_jobs_with_multiple_filters(self, db, test_marketplace_job, test_shop, test_user):
|
||||
def test_get_marketplace_import_jobs_with_multiple_filters(
|
||||
self, db, test_marketplace_job, test_shop, test_user
|
||||
):
|
||||
"""Test getting marketplace import jobs with multiple filters"""
|
||||
# Create jobs that don't match all filters
|
||||
non_matching_job1 = MarketplaceImportJob(
|
||||
@@ -254,7 +271,7 @@ class TestAdminService:
|
||||
status=test_marketplace_job.status,
|
||||
source_url="https://non-matching1.example.com/import",
|
||||
shop_id=test_shop.id,
|
||||
user_id=test_user.id # Fixed: Added missing user_id
|
||||
user_id=test_user.id, # Fixed: Added missing user_id
|
||||
)
|
||||
non_matching_job2 = MarketplaceImportJob(
|
||||
marketplace=test_marketplace_job.marketplace,
|
||||
@@ -262,7 +279,7 @@ class TestAdminService:
|
||||
status=test_marketplace_job.status,
|
||||
source_url="https://non-matching2.example.com/import",
|
||||
shop_id=test_shop.id,
|
||||
user_id=test_user.id # Fixed: Added missing user_id
|
||||
user_id=test_user.id, # Fixed: Added missing user_id
|
||||
)
|
||||
db.add_all([non_matching_job1, non_matching_job2])
|
||||
db.commit()
|
||||
@@ -272,12 +289,14 @@ class TestAdminService:
|
||||
db,
|
||||
marketplace=test_marketplace_job.marketplace,
|
||||
shop_name=test_marketplace_job.shop_name,
|
||||
status=test_marketplace_job.status
|
||||
status=test_marketplace_job.status,
|
||||
)
|
||||
|
||||
assert len(result) >= 1
|
||||
# Find our test job in the results
|
||||
test_job = next((job for job in result if job.job_id == test_marketplace_job.id), None)
|
||||
test_job = next(
|
||||
(job for job in result if job.job_id == test_marketplace_job.id), None
|
||||
)
|
||||
assert test_job is not None
|
||||
assert test_job.marketplace == test_marketplace_job.marketplace
|
||||
assert test_job.shop_name == test_marketplace_job.shop_name
|
||||
@@ -297,7 +316,7 @@ class TestAdminService:
|
||||
updated_count=None,
|
||||
total_processed=None,
|
||||
error_count=None,
|
||||
error_message=None
|
||||
error_message=None,
|
||||
)
|
||||
db.add(job)
|
||||
db.commit()
|
||||
|
||||
Reference in New Issue
Block a user