Files
orion/tests/unit/models/database/test_vendor.py
Samir Boulahtit ca9f17fc37 refactor: split database model tests into organized modules
Split the monolithic test_database_models.py into focused test modules:

Database model tests (tests/unit/models/database/):
- test_customer.py: Customer model and authentication tests
- test_inventory.py: Inventory model tests
- test_marketplace_import_job.py: Import job model tests
- test_marketplace_product.py: Marketplace product model tests
- test_order.py: Order and OrderItem model tests
- test_product.py: Product model tests
- test_team.py: Team invitation and membership tests
- test_user.py: User model tests
- test_vendor.py: Vendor model tests

Schema validation tests (tests/unit/models/schema/):
- test_auth.py: Auth schema validation tests
- test_customer.py: Customer schema validation tests
- test_inventory.py: Inventory schema validation tests
- test_marketplace_import_job.py: Import job schema tests
- test_order.py: Order schema validation tests
- test_product.py: Product schema validation tests

This improves test organization and makes it easier to find
and maintain tests for specific models.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 21:42:26 +01:00

138 lines
4.4 KiB
Python

# tests/unit/models/database/test_vendor.py
"""Unit tests for Vendor database model."""
import pytest
from sqlalchemy.exc import IntegrityError
from models.database.vendor import Vendor
@pytest.mark.unit
@pytest.mark.database
class TestVendorModel:
"""Test Vendor model."""
def test_vendor_creation(self, db, test_company):
"""Test Vendor model creation with company relationship."""
vendor = Vendor(
company_id=test_company.id,
vendor_code="DBTEST",
subdomain="dbtest",
name="Database Test Vendor",
description="Testing vendor model",
contact_email="contact@dbtest.com",
contact_phone="+1234567890",
business_address="123 Test Street",
is_active=True,
is_verified=False,
)
db.add(vendor)
db.commit()
db.refresh(vendor)
assert vendor.id is not None
assert vendor.vendor_code == "DBTEST"
assert vendor.subdomain == "dbtest"
assert vendor.name == "Database Test Vendor"
assert vendor.company_id == test_company.id
assert vendor.contact_email == "contact@dbtest.com"
assert vendor.is_active is True
assert vendor.is_verified is False
assert vendor.created_at is not None
def test_vendor_with_letzshop_urls(self, db, test_company):
"""Test Vendor model with multi-language Letzshop URLs."""
vendor = Vendor(
company_id=test_company.id,
vendor_code="MULTILANG",
subdomain="multilang",
name="Multi-Language Vendor",
letzshop_csv_url_fr="https://example.com/feed_fr.csv",
letzshop_csv_url_en="https://example.com/feed_en.csv",
letzshop_csv_url_de="https://example.com/feed_de.csv",
is_active=True,
)
db.add(vendor)
db.commit()
db.refresh(vendor)
assert vendor.letzshop_csv_url_fr == "https://example.com/feed_fr.csv"
assert vendor.letzshop_csv_url_en == "https://example.com/feed_en.csv"
assert vendor.letzshop_csv_url_de == "https://example.com/feed_de.csv"
def test_vendor_code_uniqueness(self, db, test_company):
"""Test vendor_code unique constraint."""
vendor1 = Vendor(
company_id=test_company.id,
vendor_code="UNIQUE",
subdomain="unique1",
name="Unique Vendor 1",
)
db.add(vendor1)
db.commit()
# Duplicate vendor_code should raise error
with pytest.raises(IntegrityError):
vendor2 = Vendor(
company_id=test_company.id,
vendor_code="UNIQUE",
subdomain="unique2",
name="Unique Vendor 2",
)
db.add(vendor2)
db.commit()
def test_subdomain_uniqueness(self, db, test_company):
"""Test subdomain unique constraint."""
vendor1 = Vendor(
company_id=test_company.id,
vendor_code="VENDOR1",
subdomain="testsubdomain",
name="Vendor 1",
)
db.add(vendor1)
db.commit()
# Duplicate subdomain should raise error
with pytest.raises(IntegrityError):
vendor2 = Vendor(
company_id=test_company.id,
vendor_code="VENDOR2",
subdomain="testsubdomain",
name="Vendor 2",
)
db.add(vendor2)
db.commit()
def test_vendor_default_values(self, db, test_company):
"""Test Vendor model default values."""
vendor = Vendor(
company_id=test_company.id,
vendor_code="DEFAULTS",
subdomain="defaults",
name="Default Vendor",
)
db.add(vendor)
db.commit()
db.refresh(vendor)
assert vendor.is_active is True # Default
assert vendor.is_verified is False # Default
def test_vendor_company_relationship(self, db, test_company):
"""Test Vendor-Company relationship."""
vendor = Vendor(
company_id=test_company.id,
vendor_code="RELTEST",
subdomain="reltest",
name="Relationship Test Vendor",
)
db.add(vendor)
db.commit()
db.refresh(vendor)
assert vendor.company is not None
assert vendor.company.id == test_company.id
assert vendor.company.name == test_company.name