def test_fails_to_get_absolute_url(self): # this is very uncommon, but this model does not have an url user_alias = UserAlias(alias_name=self.VALID_ALIAS_NAME, alias_of=self.default_user) with pytest.raises(AttributeError) as excinfo: user_alias.get_absolute_url() assert str(excinfo.value) == ( "'UserAlias' object has no attribute 'get_absolute_url'")
def test_alis_name_is_required(self): with pytest.raises(ValidationError) as excinfo: UserAlias(alias_of=self.default_user).full_clean() assert str(excinfo.value) == ( "{'alias_name': [u'This field cannot be blank.']}")
def test_repr(self): # __str__ returns name, but it did not affected __repr__ user_alias = UserAlias(alias_name=self.VALID_ALIAS_NAME, alias_of=self.default_user) assert repr(user_alias) == ( '<UserAlias: {alias_name} (alias of {user_name})>').format( alias_name=self.VALID_ALIAS_NAME, user_name=self.default_user.username)
def test_convert_to_string(self): # __str__ will return name user_alias = UserAlias(alias_name=self.VALID_ALIAS_NAME, alias_of=self.default_user) assert str(user_alias) == ( "{alias_name} (alias of {user_name})").format( alias_name=self.VALID_ALIAS_NAME, user_name=self.default_user.username)