def test_the_update_method_of_the_repository(): """ GIVEN the Repository class WHEN the method update(object) is called THEN check session method calls """ from app.model.repository import Repository Repository.__abstractmethods__ = frozenset() repository = Repository(object) repository.session = AlchemyMagicMock() repository.update(object) repository.session.commit.assert_called_once_with()
def test_the_get_method_of_the_repository(app): """ GIVEN the Repository class WHEN the method get(object) is called THEN check session method calls """ from app.model.repository import Repository Repository.__abstractmethods__ = frozenset() repository = Repository(object) repository.session = AlchemyMagicMock() repository.get(object) repository.session.query.return_value.filter_by.assert_called_once_with( id=object)
def test_the_get_all_method_of_the_repository(app, mocker): """ GIVEN the Repository class WHEN the method get_all(object) is called THEN check session method calls """ from app.model.repository import Repository Repository.__abstractmethods__ = frozenset() # mocking the model class mock = mocker.MagicMock() mock.id = Column(Integer, primary_key=True) repository = Repository(mock) repository.session = AlchemyMagicMock() repository.get_all() repository.session.query.return_value.order_by.assert_called_once_with( desc(mock.id))