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={})
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_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_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()
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'}
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}
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
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()
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'}
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}
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
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)
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_
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"}