63 lines
1.4 KiB
Python
63 lines
1.4 KiB
Python
from decimal import Decimal
|
|
from uuid import uuid4
|
|
|
|
from domain.marketplace.classified_ad import ClassifiedAd
|
|
from domain.marketplace.user_id import UserId
|
|
|
|
|
|
def test_classified_ad_creation():
|
|
ad_id = uuid4()
|
|
owner_id = UserId(value=uuid4())
|
|
|
|
ad = ClassifiedAd(
|
|
id=ad_id,
|
|
_ownerId=owner_id,
|
|
title="Test Title",
|
|
text="Test text content",
|
|
_price=Decimal("99.99"),
|
|
)
|
|
|
|
assert ad.id == ad_id
|
|
assert ad._ownerId == owner_id
|
|
assert ad.title == "Test Title"
|
|
assert ad.text == "Test text content"
|
|
assert ad._price == Decimal("99.99")
|
|
|
|
|
|
def test_classified_ad_is_immutable():
|
|
ad = ClassifiedAd(
|
|
id=uuid4(),
|
|
_ownerId=UserId(value=uuid4()),
|
|
title="Title",
|
|
text="Text",
|
|
_price=Decimal("10.00"),
|
|
)
|
|
|
|
try:
|
|
ad.title = "New Title" # type: ignore
|
|
assert False, "Should have raised FrozenInstanceError"
|
|
except AttributeError:
|
|
pass
|
|
|
|
|
|
def test_classified_ad_equality():
|
|
ad_id = uuid4()
|
|
owner_id = UserId(value=uuid4())
|
|
|
|
ad1 = ClassifiedAd(
|
|
id=ad_id,
|
|
_ownerId=owner_id,
|
|
title="Title",
|
|
text="Text",
|
|
_price=Decimal("10.00"),
|
|
)
|
|
ad2 = ClassifiedAd(
|
|
id=ad_id,
|
|
_ownerId=owner_id,
|
|
title="Title",
|
|
text="Text",
|
|
_price=Decimal("10.00"),
|
|
)
|
|
|
|
assert ad1 == ad2
|