Esempio n. 1
0
    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
Esempio n. 2
0
 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']
Esempio n. 3
0
    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__ = {}
Esempio n. 4
0
 def test_abstract_find(self):
     with pytest.raises(NotImplementedError):
         AbstractRepository.find(1)
Esempio n. 5
0
 def test_abstract_first(self):
     with pytest.raises(NotImplementedError):
         AbstractRepository.first(where=[])
Esempio n. 6
0
 def test_abstract_mapping(self):
     with pytest.raises(NotImplementedError):
         AbstractRepository.mapping('foo', 'bar')
Esempio n. 7
0
 def setup_repo(self, mocker):
     mocker.patch.multiple(AbstractRepository, __abstractmethods__=set())
     return AbstractRepository()