0

in my company we have a Django monolithic application. To be clear, we are not looking into moving to micro-services. For the past few months, I have reading and implementing a DDD architecture inside the monolith, trying to setup the django modules as isolated as possible from the rest of the application. I have somehow successfully done this, except for the testing part.

The application and domain layer tests are fine because they are unit tests and they do not need to import anything from other modules. Nonetheless, the integration tests of the data access layer need access to data models (Django ORM classes) from other bounded contexts. This is due to Foreign Key constraints in our database model. For instance, we base almost all modules on having a User associated with a model inside the bounded context. In turn, we also group users in companies, so for every integration test of a data access in a bounded context, we need a reference to the User and Company model. Let me show the structure in case it helps:

module N/
   application/
   domain/
   infrastructure/
   tests/
       infrastructure/
            db/
                # here I need to create Users and Companies 
                # and some other things to keep foreign key integrity rules
                some_data_access_test.py 

The test would be something like this:

# this is inside module N bounded context
from companies.models import Company, User

class SomeDataAccessTestCase(TestCase):
    def setUp(self):
         self._setup_company()
         self._setup_user_in_company() 

I see this as a problem because it's harder to manage the coupling of all the modules with the user and companies, so when we make a refactor inside that bounded context, lot of other things are affected.

Maybe this is not a big problem, but I would like to get your opinion on this topic and see if at least we can improve a little bit the situation. Any additional information you need, let me know and I will add it. Thanks :D.

0