Exemplo n.º 1
0
 def test_remove_error_wrong_id(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     repo.remove(entity)
     with pytest.raises(QueryError) as error_info:
         repo.remove(entity)
     assert error_info.value == QueryErrors.NOT_FOUND
     assert error_info.value.params == {'id': id_, 'entity': entity}
Exemplo n.º 2
0
 def test_remove_error_wrong_id(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     repo.remove(entity)
     with pytest.raises(QueryError) as error_info:
         repo.remove(entity)
     assert error_info.value == QueryErrors.NOT_FOUND
     assert error_info.value.params == {'id': id_, 'entity': entity}
 def test_remove_error_not_added(self, data, repo: Repository, dao: IDao):
     entity = repo.create(**data)
     with pytest.raises(QueryError) as error_info:
         repo.remove(entity)
     assert error_info.value == QueryErrors.NOT_FOUND
     assert error_info.value.params == {
         "id": entity.__get_id__(),
         "entity": entity
     }
Exemplo n.º 4
0
def add_team_member(
        request_data: RequestModel,
        teams: Repository = Inject(qualifier=Team),
        racers: Repository = Inject(qualifier=Racer),
):
    team: Team = teams.find(request_data['team_id'])
    racer: Racer = racers.find(request_data['racer_id'])
    team.members.append(racer)
    teams.update(team)
    return ResponseModel(data=request_data, errors={})
def add_team_member(
        request_data: RequestModel,
        teams: Repository = Inject(qualifier=Team),
        racers: Repository = Inject(qualifier=Racer),
):
    team: Team = teams.find(request_data['team_id'])
    racer: Racer = racers.find(request_data['racer_id'])
    team.members.append(racer)
    teams.update(team)
    return ResponseModel(data=request_data, errors={})
Exemplo n.º 6
0
 def test_add(self, data, repo: Repository, dao: IDao):
     entity = Bike(**data)
     id_ = repo.add(entity)
     assert dao.get(id_) == data
Exemplo n.º 7
0
 def test_remove_error_not_added(self, data, repo: Repository, dao: IDao):
     entity = repo.create(**data)
     with pytest.raises(QueryError) as error_info:
         repo.remove(entity)
     assert error_info.value == QueryErrors.ENTITY_NOT_YET_ADDED
     assert error_info.value.params == {'entity': entity}
 def test_update_success(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     entity.frame_type = "road"
     repo.update(entity)
     assert dao.get(id_) == {"frame_type": "road", "wheel_type": "road"}
Exemplo n.º 9
0
 def test_find_error(self, data, repo: Repository, dao: IDao):
     id_ = 42
     with pytest.raises(IDao.NotFound) as error_info:
         assert repo.find(id_)
     assert error_info.value.entity == Bike
     assert error_info.value.id_ == id_
Exemplo n.º 10
0
 def test_remove_success(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     assert dao.filter_by(id_=id_).exists()
     repo.remove(entity)
     assert not dao.filter_by(id_=id_).exists()
Exemplo n.º 11
0
 def test_contains_failure(self, data, repo: Repository, dao: IDao):
     id_ = 42
     assert not repo.contains(id_)
Exemplo n.º 12
0
 def test_find_error(self, data, repo: Repository, dao: IDao):
     id_ = 42
     with pytest.raises(QueryError) as error_info:
         assert repo.find(id_)
     assert error_info.value == QueryErrors.NOT_FOUND
     assert error_info.value.params == {'id': id_, 'entity': Bike}
Exemplo n.º 13
0
 def test_create_and_add(self, data, repo: Repository, dao: IDao):
     entity = repo.create_and_add(**data)
     assert dao.get(entity.id) == data
Exemplo n.º 14
0
 def test_create(self, data, repo: Repository, dao: IDao):
     entity = repo.create(**data)
     assert repo.factory.deconstruct(entity) == data
     assert dao.all().count() == 0
Exemplo n.º 15
0
 def test_create(self, data, repo: Repository, dao: IDao):
     entity = repo.create(**data)
     assert repo.schema.deconstruct(entity) == data
     assert dao.all().count() == 0
Exemplo n.º 16
0
 def repo(self, container, schema, dao):
     repo = Repository(container, schema)
     return repo
Exemplo n.º 17
0
 def repo(self, container, schema):
     return Repository(container, schema)
Exemplo n.º 18
0
 def test_remove_error_wrong_id(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     repo.remove(entity)
     with pytest.raises(InvalidQueryError):
         repo.remove(entity)
Exemplo n.º 19
0
 def test_remove_error_not_added(self, data, repo: Repository, dao: IDao):
     entity = repo.create(**data)
     with pytest.raises(InvalidQueryError):
         repo.remove(entity)
Exemplo n.º 20
0
 def repo(self, container, factory, dao):
     repo = Repository(container, factory)
     return repo
Exemplo n.º 21
0
 def test_create_and_add(self, data, repo: Repository, dao: IDao):
     entity = repo.create_and_add(**data)
     assert dao.get(entity.id) == data
Exemplo n.º 22
0
 def test_add(self, data, repo: Repository, dao: IDao):
     entity = Bike(**data)
     id_ = repo.add(entity)
     assert dao.get(id_) == data
Exemplo n.º 23
0
 def test_find_success(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     assert isinstance(entity, Bike)
     assert dataclasses.asdict(entity) == data
Exemplo n.º 24
0
 def test_find_success(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     assert isinstance(entity, Bike)
     assert dataclasses.asdict(entity) == data
Exemplo n.º 25
0
 def test_find_error(self, data, repo: Repository, dao: IDao):
     id_ = 42
     with pytest.raises(QueryError) as error_info:
         assert repo.find(id_)
     assert error_info.value == QueryErrors.NOT_FOUND
     assert error_info.value.params == {'id': id_, 'entity': Bike}
Exemplo n.º 26
0
 def test_contains_success(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     assert repo.contains(id_)
Exemplo n.º 27
0
 def test_contains_success(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     assert repo.contains(id_)
Exemplo n.º 28
0
 def test_update_success(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     entity.frame_type = 'road'
     repo.update(entity)
     assert dao.get(id_) == {'frame_type': 'road', 'wheel_type': 'road'}
Exemplo n.º 29
0
 def test_contains_failure(self, data, repo: Repository, dao: IDao):
     id_ = 42
     assert not repo.contains(id_)
Exemplo n.º 30
0
 def test_remove_error_not_added(self, data, repo: Repository, dao: IDao):
     entity = repo.create(**data)
     with pytest.raises(QueryError) as error_info:
         repo.remove(entity)
     assert error_info.value == QueryErrors.ENTITY_NOT_YET_ADDED
     assert error_info.value.params == {'entity': entity}
Exemplo n.º 31
0
 def test_update_success(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     entity.frame_type = 'road'
     repo.update(entity)
     assert dao.get(id_) == {'frame_type': 'road', 'wheel_type': 'road'}
Exemplo n.º 32
0
 def repo(self, container, factory):
     return Repository(container, factory)
Exemplo n.º 33
0
 def test_remove_success(self, data, repo: Repository, dao: IDao):
     id_ = dao.insert(**data)
     entity = repo.find(id_)
     assert dao.filter_by(id_=id_).exists()
     repo.remove(entity)
     assert not dao.filter_by(id_=id_).exists()