Esempio n. 1
0
        def test_must_be_power_class(self, valid_hero):
            with pytest.raises(ValidationError) as excinfo:
                Hero(**{**valid_hero, "power_class": 9000})

            self.assert_validation_error("type_error.enum", excinfo)
Esempio n. 2
0
        def test_is_required(self, valid_hero):
            with pytest.raises(ValidationError) as excinfo:
                Hero(**dissoc(valid_hero, "location"))

            self.assert_validation_error("value_error.missing", excinfo)
Esempio n. 3
0
        def test_must_be_str(self, valid_hero):
            with pytest.raises(ValidationError) as excinfo:
                Hero(**{**valid_hero, "nickname": ["Some nickname"]})

            self.assert_validation_error("type_error.str", excinfo)
Esempio n. 4
0
        def test_max_length(self, valid_hero):
            with pytest.raises(ValidationError) as excinfo:
                Hero(**{**valid_hero, "nickname": "a" * 101})

            self.assert_validation_error("value_error.any_str.max_length",
                                         excinfo)
Esempio n. 5
0
 def test_defaults(self, valid_hero):
     assert Hero(**dissoc(valid_hero, "name")).name == "Unknown"
Esempio n. 6
0
        def test_must_be_int(self, valid_hero):
            with pytest.raises(ValidationError) as excinfo:
                Hero(**{**valid_hero, "user_id": "some_id"})

            self.assert_validation_error("type_error.integer", excinfo)
Esempio n. 7
0
 def test_immutability(self, valid_hero):
     entity = Hero(**valid_hero)
     for key in entity.dict().keys():
         with pytest.raises(TypeError):
             setattr(entity, key, "some value")
Esempio n. 8
0
 def test_invalidation(self, invalid_hero):
     with pytest.raises(ValidationError):
         Hero(**invalid_hero)
Esempio n. 9
0
 def test_validation(self, valid_hero):
     assert Hero(**valid_hero)