def test_from_dict_error_init(self, mocker, capsys, init, output, code): mocker.patch.multiple(AbstractRepository, __init__=init, __abstractmethods__=set()) with pytest.raises(SystemExit) as pytest_wrapped_e: AbstractRepository.from_dict({ 'foo': 'bar', }) assert output in capsys.readouterr().err assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == code
def test_from_dict(self, mocker): mocker.patch.multiple(AbstractRepository, __abstractmethods__=set()) repo = AbstractRepository.from_dict({ 'foo': 'bar', 'foobars': ['foobar', 'foobaz'] }) assert repo.foo == 'bar' assert repo.foobars == ['foobar', 'foobaz']
def test_from_dict_with_one_to_one_relation(self, mocker): mocker.patch.multiple(AbstractRepository, __abstractmethods__=set()) AbstractRepository.__relationships__ = {'foobar': [AbstractRepository]} repo = AbstractRepository.from_dict({ 'foo': 'bar', 'foobar': { 'id': 'foobar' }, }) assert repo.foo == 'bar' assert isinstance(repo.foobar[0], AbstractRepository) assert repo.foobar[0].id == 'foobar' AbstractRepository.__relationships__ = {}
def test_abstract_find(self): with pytest.raises(NotImplementedError): AbstractRepository.find(1)
def test_abstract_first(self): with pytest.raises(NotImplementedError): AbstractRepository.first(where=[])
def test_abstract_mapping(self): with pytest.raises(NotImplementedError): AbstractRepository.mapping('foo', 'bar')
def setup_repo(self, mocker): mocker.patch.multiple(AbstractRepository, __abstractmethods__=set()) return AbstractRepository()