Skip to content

chore: greatly simplify mocking and models API#39

Merged
regisb merged 1 commit intomasterfrom
regisb/mocking
Aug 15, 2024
Merged

chore: greatly simplify mocking and models API#39
regisb merged 1 commit intomasterfrom
regisb/mocking

Conversation

@regisb
Copy link
Copy Markdown
Contributor

@regisb regisb commented Aug 15, 2024

We split the ModelBackend in database/collection. This means that we can override the database globally in unit tests. This also drastically simplifies model constructors.

Comment thread forum/models/base_model.py Outdated
@regisb regisb force-pushed the regisb/mocking branch 2 times, most recently from 3e669fc to 7823d7a Compare August 15, 2024 13:38
The MongoBackend now provides access only to a database, and it is the
responsibility of each child model to access the collection. This is
done transparently via the _collection property.

The MongoBackend constructor was also simplified. Because we are now
using a single database object, we can drastically simplify mocking in
tests. That's because we don't have to mock models one by one.

And it turns out that we don't need to store the client attribute. Neither do we
need to store a diffent collection name for every model instance, so we
can simply store it as a class attribute. This means that we no longer
need constructors for models.
Copy link
Copy Markdown
Contributor

@taimoor-ahmed-1 taimoor-ahmed-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@regisb regisb merged commit 56496bf into master Aug 15, 2024
@regisb regisb deleted the regisb/mocking branch August 15, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants