Search⌘ K

Domain Models

Explore how to build and test domain models in clean architecture using Python. Learn to implement the Room domain model with dataclasses, initialize it from dictionaries, convert it for serialization, and write tests for initialization and comparison using TDD.

The Room domain model

Let’s start with a simple definition of the Room domain model. As we mentioned before, clean architecture models are lighter than their counterparts in common web frameworks.

Implementing test case for initialization

Following the TDDTest-Driven Development methodology, the first thing we’ll write is the test. The test ensures that the model initializes with the correct values.

Python 3.8
import uuid
from rentomatic.domain.room import Room
def test_room_model_init():
code = uuid.uuid4()
room = Room(
code,
size=200,
price=10,
longitude=-0.09998975,
latitude=51.75436293,
)
assert room.code == code
assert room.size == 200
assert room.price == 10
assert room.longitude == -0.09998975
assert room.latitude == 51.75436293

Let’s make a note to create ...