Exemplo n.º 1
0
 def test_get_or_create_with_declared_fields(self, queryset):
     queryset.model._meta.get = 'Read_NotFound'
     queryset.model._meta.declared_fields.extend([
         models.Field(name='No'),
         models.Field(name='Name')
     ])
     with pytest.raises(AttributeError):
         queryset.get_or_create(No='Test', defaults={'Test': 'Test'})
Exemplo n.º 2
0
    def test_run_validators_raise_exception_2(self):
        field = models.Field()
        field._validators.append(utils.MaxLengthValidaiton(5))

        with pytest.raises(exceptions.ValidationError) as e:
            field.run_validators('testing')
        assert e.value.message[0] == 'Max length reached'
Exemplo n.º 3
0
 def test_new_inheritance_with_conflicts_at_the_parents(self):
     nmspc = self.base_dict.copy()
     nmspc.update(var1=models.Field(max_length=10))
     new_parent = type('TestParent', (models.NavModel, ), nmspc)
     with pytest.raises(exceptions.FieldException):
         new_class = type('TestModel', (new_parent, test_models.TestModel1),
                          self.base_dict.copy())
Exemplo n.º 4
0
    def test_new_with_fields(self):
        nmspc = self.base_dict
        nmspc.update(var1=models.Field(max_length=10))
        new_class = type('TestModel', (models.NavModel, ), nmspc)

        assert hasattr(new_class, '_meta')
        assert len(new_class._meta.declared_fields) == 1
        assert len(new_class._meta.discovered_fields) == 0
Exemplo n.º 5
0
    def test_new_raise_error_about_fields_attr_and_custom_fields_together(self):
        class Meta:
            fields = 'all'
        nmspc = self.base_dict
        nmspc.update(Meta=Meta)
        nmspc.update(var2=models.Field())

        with pytest.raises(exceptions.FieldException):
            type('TestModel', (models.NavModel, ), nmspc)
Exemplo n.º 6
0
class TestModel1(models.NavModel):
    var1 = models.Field(max_length=30)
    var2 = models.Field()
Exemplo n.º 7
0
    def test_new_inheritance_with_extra_fields_with_the_same_name(self):
        nmspc = self.base_dict
        nmspc.update(var1=models.Field(max_length=10))

        with pytest.raises(Exception):
            new_class = type('TestModel', (test_models.TestModel1,), nmspc)
Exemplo n.º 8
0
    def test_new_inheritance_with_extra_fields(self):
        nmspc = self.base_dict
        nmspc.update(var3=models.Field(max_length=10))
        new_class = type('TestModel', (test_models.TestModel1, ), nmspc)

        assert len(new_class._meta.declared_fields) == 3
Exemplo n.º 9
0
    def test_clean_with_validators(self):
        field = models.Field(validators=[utils.MaxLengthValidaiton(5)])

        with pytest.raises(exceptions.ValidationError) as e:
            field.clean('testing')
        assert e.value.message[0] == 'Max length reached'
Exemplo n.º 10
0
    def test_clean_with_no_validators(self):
        field = models.Field()

        assert field.clean('testing') == 'testing'
Exemplo n.º 11
0
 def test_run_validators_not_raise_exception(self):
     field = models.Field(validators=[utils.MaxLengthValidaiton(10)])
     try:
         field.run_validators('testing')
     except exceptions.ValidationError:
         pytest.fail('Raised unexcpected ValidationError.')
Exemplo n.º 12
0
    def test_repr_with_name(self):
        field = models.Field(name='Field')

        assert repr(field) == '<lather.models.Field: Field>'
Exemplo n.º 13
0
    def test_repr_without_name(self):
        field = models.Field()

        assert repr(field) == '<lather.models.Field>'
Exemplo n.º 14
0
    def test_new_raise_duplicate_key_error(self):
        nmspc = self.base_dict
        nmspc.update(Key=models.Field(max_length=10))

        with pytest.raises(exceptions.FieldException):
            type('TestModel', (models.NavModel, ), nmspc)