testing - Django test module ignores choice restrictions -
so have model has restricted choices, 'developer' , 'charity'. if change radiobutton values on actual form other those, django comes error message should. in testing accepts value seems. in short test shouldn't fail does. or django should raise integrity error or something.
i have problem testing foreign key field in profile, that's perhaps best saved different question.
model code snippet:
# models.py user_type = models.charfield(max_length=30, choices={ ('developer', 'developer'), ('charity', 'charity'), }, blank=false, null=false)
however, when following in testing, there's no error message:
# tests.py def test_no_user_type(self): my_values = self.default_values my_values[self.user_type] = 'something' # row creates , saves user , profile. user, profile = self.save_user(my_values) # thought bit irrelevant @ point because # there should error message test_correct = (profile.user_type != 'something') self.assertequal(test_correct, true) def save_user(self, values): user = user.objects.create() user.username = values[self.username] user.email = values[self.email] user.set_password(values[self.password]) user.save() profile = user.get_profile() ... profile.user_type = values[self.user_type] ... profile.save() return user, profile # constants top password = 1 email = 2 user_type = 3 ... field_list = ['username', 'password', 'email', 'user_type'] ... default_values = ['test_username', 'test_password', 'test_email@test.com', 'developer'] ...
when use model form (including django admin), django validate model instance. in other cases, must call instance's full_clean
method manually validate it.
Comments
Post a Comment