Marketplace tests update
This commit is contained in:
@@ -113,7 +113,7 @@ def delete_product(
|
||||
return {"message": "Product and associated stock deleted successfully"}
|
||||
|
||||
|
||||
@router.get("/export-csv")
|
||||
@router.get("/product/export-csv")
|
||||
async def export_csv(
|
||||
marketplace: Optional[str] = Query(None, description="Filter by marketplace"),
|
||||
shop_name: Optional[str] = Query(None, description="Filter by shop name"),
|
||||
|
||||
@@ -85,6 +85,24 @@ def setup_exception_handlers(app):
|
||||
}
|
||||
)
|
||||
|
||||
# Clean up validation errors to ensure JSON serializability
|
||||
clean_errors = []
|
||||
for error in exc.errors():
|
||||
clean_error = {}
|
||||
for key, value in error.items():
|
||||
if key == 'ctx' and isinstance(value, dict):
|
||||
# Handle the 'ctx' field that contains ValueError objects
|
||||
clean_ctx = {}
|
||||
for ctx_key, ctx_value in value.items():
|
||||
if isinstance(ctx_value, Exception):
|
||||
clean_ctx[ctx_key] = str(ctx_value) # Convert exception to string
|
||||
else:
|
||||
clean_ctx[ctx_key] = ctx_value
|
||||
clean_error[key] = clean_ctx
|
||||
else:
|
||||
clean_error[key] = value
|
||||
clean_errors.append(clean_error)
|
||||
|
||||
return JSONResponse(
|
||||
status_code=422,
|
||||
content={
|
||||
@@ -92,7 +110,7 @@ def setup_exception_handlers(app):
|
||||
"message": "Request validation failed",
|
||||
"status_code": 422,
|
||||
"details": {
|
||||
"validation_errors": exc.errors()
|
||||
"validation_errors": clean_errors # Use cleaned errors
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ This module provides classes and functions for:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -81,7 +81,7 @@ class AdminService:
|
||||
try:
|
||||
original_status = user.is_active
|
||||
user.is_active = not user.is_active
|
||||
user.updated_at = datetime.utcnow()
|
||||
user.updated_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
|
||||
@@ -146,11 +146,11 @@ class AdminService:
|
||||
try:
|
||||
original_status = shop.is_verified
|
||||
shop.is_verified = not shop.is_verified
|
||||
shop.updated_at = datetime.utcnow()
|
||||
shop.updated_at = datetime.now(timezone.utc)
|
||||
|
||||
# Add verification timestamp if implementing audit trail
|
||||
if shop.is_verified:
|
||||
shop.verified_at = datetime.utcnow()
|
||||
shop.verified_at = datetime.now(timezone.utc)
|
||||
|
||||
db.commit()
|
||||
db.refresh(shop)
|
||||
@@ -190,7 +190,7 @@ class AdminService:
|
||||
try:
|
||||
original_status = shop.is_active
|
||||
shop.is_active = not shop.is_active
|
||||
shop.updated_at = datetime.utcnow()
|
||||
shop.updated_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
db.refresh(shop)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ This module provides classes and functions for:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import func
|
||||
@@ -106,7 +106,7 @@ class MarketplaceService:
|
||||
shop_id=shop.id, # Foreign key to shops table
|
||||
shop_name=shop.shop_name, # Use shop.shop_name (the display name)
|
||||
user_id=user.id,
|
||||
created_at=datetime.utcnow(),
|
||||
created_at=datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
db.add(import_job)
|
||||
@@ -360,7 +360,7 @@ class MarketplaceService:
|
||||
raise ImportJobCannotBeCancelledException(job_id, job.status)
|
||||
|
||||
job.status = "cancelled"
|
||||
job.completed_at = datetime.utcnow()
|
||||
job.completed_at = datetime.now(timezone.utc)
|
||||
|
||||
db.commit()
|
||||
db.refresh(job)
|
||||
|
||||
@@ -10,7 +10,7 @@ This module provides classes and functions for:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Generator, List, Optional, Tuple
|
||||
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
@@ -250,7 +250,7 @@ class ProductService:
|
||||
for key, value in update_data.items():
|
||||
setattr(product, key, value)
|
||||
|
||||
product.updated_at = datetime.utcnow()
|
||||
product.updated_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ This module provides classes and functions for:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -68,7 +68,7 @@ class StockService:
|
||||
# Update existing stock (SET to exact quantity)
|
||||
old_quantity = existing_stock.quantity
|
||||
existing_stock.quantity = stock_data.quantity
|
||||
existing_stock.updated_at = datetime.utcnow()
|
||||
existing_stock.updated_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
db.refresh(existing_stock)
|
||||
|
||||
@@ -128,7 +128,7 @@ class StockService:
|
||||
# Add to existing stock
|
||||
old_quantity = existing_stock.quantity
|
||||
existing_stock.quantity += stock_data.quantity
|
||||
existing_stock.updated_at = datetime.utcnow()
|
||||
existing_stock.updated_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
db.refresh(existing_stock)
|
||||
|
||||
@@ -207,7 +207,7 @@ class StockService:
|
||||
raise NegativeStockException(normalized_gtin, location, new_quantity)
|
||||
|
||||
existing_stock.quantity = new_quantity
|
||||
existing_stock.updated_at = datetime.utcnow()
|
||||
existing_stock.updated_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
db.refresh(existing_stock)
|
||||
|
||||
@@ -381,7 +381,7 @@ class StockService:
|
||||
self._validate_quantity(stock_update.quantity, allow_zero=True)
|
||||
|
||||
stock_entry.quantity = stock_update.quantity
|
||||
stock_entry.updated_at = datetime.utcnow()
|
||||
stock_entry.updated_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
db.refresh(stock_entry)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ This module provides classes and functions for:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from app.core.database import SessionLocal
|
||||
from models.database.marketplace import MarketplaceImportJob
|
||||
@@ -37,7 +37,7 @@ async def process_marketplace_import(
|
||||
return
|
||||
|
||||
job.status = "processing"
|
||||
job.started_at = datetime.utcnow()
|
||||
job.started_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
|
||||
logger.info(f"Processing import: Job {job_id}, Marketplace: {marketplace}")
|
||||
@@ -49,7 +49,7 @@ async def process_marketplace_import(
|
||||
|
||||
# Update job with results
|
||||
job.status = "completed"
|
||||
job.completed_at = datetime.utcnow()
|
||||
job.completed_at = datetime.now(timezone.utc)
|
||||
job.imported_count = result["imported"]
|
||||
job.updated_count = result["updated"]
|
||||
job.error_count = result.get("errors", 0)
|
||||
@@ -68,7 +68,7 @@ async def process_marketplace_import(
|
||||
try:
|
||||
job.status = "failed"
|
||||
job.error_message = str(e)
|
||||
job.completed_at = datetime.utcnow()
|
||||
job.completed_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
except Exception as commit_error:
|
||||
logger.error(f"Failed to update job status: {commit_error}")
|
||||
|
||||
@@ -8,7 +8,7 @@ This module provides classes and functions for:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from io import StringIO
|
||||
from typing import Any, Dict
|
||||
|
||||
@@ -290,7 +290,7 @@ class CSVProcessor:
|
||||
existing_product, key
|
||||
):
|
||||
setattr(existing_product, key, value)
|
||||
existing_product.updated_at = datetime.utcnow()
|
||||
existing_product.updated_at = datetime.now(timezone.utc)
|
||||
updated += 1
|
||||
logger.debug(
|
||||
f"Updated product {product_data['product_id']} for "
|
||||
|
||||
Reference in New Issue
Block a user