Beispiel #1
0
        def test_must_be_str(self, valid_update_hero_dto):
            with pytest.raises(ValidationError) as excinfo:
                UpdateHeroDto(**{
                    **valid_update_hero_dto, "nickname": ["Some nickname"]
                })

            self.assert_validation_error("type_error.str", excinfo)
Beispiel #2
0
        def test_max_length(self, valid_update_hero_dto):
            with pytest.raises(ValidationError) as excinfo:
                UpdateHeroDto(**{
                    **valid_update_hero_dto, "nickname": "a" * 101
                })

            self.assert_validation_error("value_error.any_str.max_length",
                                         excinfo)
Beispiel #3
0
async def update(user_id: int, dto: UpdateHeroDto, id_: int) -> Optional[Hero]:
    if not await exists(id_):
        return None

    values = dto.dict(exclude_unset=True)
    query = (
        HeroModel.update()
        .where(HeroModel.c.user_id == user_id)
        .where(HeroModel.c.id == id_)
        .values(**values)
    )

    try:
        await database.execute(query)
    except UniqueViolationError:
        raise HeroNotUniqueError()

    return await fetch(user_id, id_)
Beispiel #4
0
 def test_is_optional(self, valid_update_hero_dto):
     assert UpdateHeroDto(**dissoc(valid_update_hero_dto, "location"))
Beispiel #5
0
 def test_is_optional(self, valid_update_hero_dto):
     assert UpdateHeroDto(
         **dissoc(valid_update_hero_dto, "power_class"))
Beispiel #6
0
        def test_must_be_power_class(self, valid_update_hero_dto):
            with pytest.raises(ValidationError) as excinfo:
                UpdateHeroDto(**{**valid_update_hero_dto, "power_class": 9000})

            self.assert_validation_error("type_error.enum", excinfo)
Beispiel #7
0
 def test_defaults(self, valid_update_hero_dto):
     assert (UpdateHeroDto(
         **dissoc(valid_update_hero_dto, "name")).name == "Unknown")
Beispiel #8
0
 def test_immutability(self, valid_update_hero_dto):
     entity = UpdateHeroDto(**valid_update_hero_dto)
     for key in entity.dict().keys():
         with pytest.raises(TypeError):
             setattr(entity, key, "some value")
Beispiel #9
0
 def test_invalidation(self, invalid_update_hero_dto):
     with pytest.raises(ValidationError):
         UpdateHeroDto(**invalid_update_hero_dto)
Beispiel #10
0
 def test_validation(self, valid_update_hero_dto):
     assert UpdateHeroDto(**valid_update_hero_dto)