def test_user_attribute_is_working_properly(self): """testing if the user attribute value is correctly passed to the user attribute """ from stalker import AuthenticationLog from stalker.models.auth import LOGOUT import datetime import pytz uli = AuthenticationLog(user=self.test_user1, action=LOGOUT, date=datetime.datetime.now(pytz.utc)) self.assertNotEqual(uli.user, self.test_user2) uli.user = self.test_user2 self.assertEqual(uli.user, self.test_user2)
def test_user_attribute_is_not_a_user_instance(self): """testing if a TypeError will be raised when the user attribute is set to value other than a User instance """ from stalker import AuthenticationLog from stalker.models.auth import LOGIN import datetime import pytz uli = AuthenticationLog(user=self.test_user1, action=LOGIN, date=datetime.datetime.now(pytz.utc)) with pytest.raises(TypeError) as cm: uli.user = '******' assert str(cm.value) == \ 'AuthenticationLog.user should be a User instance, not str'
def test_user_attribute_is_not_a_user_instance(self): """testing if a TypeError will be raised when the user attribute is set to value other than a User instance """ from stalker import AuthenticationLog from stalker.models.auth import LOGIN import datetime uli = AuthenticationLog( user=self.test_user1, action=LOGIN, date=datetime.datetime.now() ) with self.assertRaises(TypeError) as cm: uli.user = '******' self.assertEqual( str(cm.exception), 'AuthenticationLog.user should be a User instance, not str' )