Skip to content


The FakeRepository is the simplest implementation of the repository pattern, meant to be used for the tests and early phases of development.

It stores the persisted Entities in the entities object attribute in a dictionary where the keys are the Entity class and the values are list of that Entity objects. When you try to make changes to the repository, the actual entities dictionary is copied to the new_entities attribute. The changes are made on that new attribute and once you use the commit method, they get copied back to the entities attribute.

Load it with:

from repository_orm import load_repository

repo = load_repository()


Follow the overview example to see how to use each method.

Appends the Entity object to the new_entities attribute.
Deletes the Entity object from the new_entities attribute.
Obtain an Entity from the entities attribute by it's ID.
Persist the changes of new_entities into entities, clearing up new_entities afterwards.
Obtain all the entities of type Entity from the entities attribute.

Obtain the entities whose attributes match one or multiple conditions.

We use DeepDiff's grep to search for the entities that have the value we're searching for and then we search if the key of those entities match the one we're searching for.


Run the migrations of the repository schema.

As the fake repository doesn't have any schema this method does nothing.

Simulating errors


To simulate a connection error to the database, initialize the object with the wrong_database_url string.

Last update: 2022-08-12