def test_save(self): log = RequestTokenLog(token=self.token, user=self.user).save() self.assertIsNotNone(log.timestamp) log.timestamp = None self.assertRaises(IntegrityError, log.save, update_fields=['timestamp'])
def test_string_repr(self): log = RequestTokenLog(token=self.token, user=self.user) self.assertIsNotNone(str(log)) self.assertIsNotNone(repr(log)) log.user = None self.assertIsNotNone(str(log)) self.assertIsNotNone(repr(log))
def test_defaults(self): log = RequestTokenLog(token=self.token, user=self.user) self.assertEqual(log.user, self.user) self.assertEqual(log.token, self.token) self.assertEqual(log.user_agent, '') self.assertEqual(log.client_ip, '') self.assertIsNone(log.timestamp)
def test_defaults(self): log = RequestTokenLog(token=self.token, user=self.user) self.assertEqual(log.user, self.user) self.assertEqual(log.token, self.token) self.assertEqual(log.user_agent, "") self.assertEqual(log.client_ip, None) self.assertIsNone(log.timestamp) token = RequestToken(user=self.user) self.assertIsNotNone(str(token)) self.assertIsNotNone(repr(token))
def test_create_error_log(self): user = get_user_model().objects.create_user('zoidberg', first_name=u'∂ƒ©˙∆', last_name=u'†¥¨^') token = RequestToken.objects.create_token( scope='foo', user=user, login_mode=RequestToken.LOGIN_MODE_REQUEST) log = RequestTokenLog(token=token, user=user).save() elog = RequestTokenErrorLog.objects.create_error_log( log, MaxUseError('foo')) self.assertEqual(elog.token, token) self.assertEqual(elog.log, log) self.assertEqual(elog.error_type, 'MaxUseError') self.assertEqual(elog.error_message, 'foo') self.assertEqual(str(elog), 'foo')
def test_create_error_log(self): user = get_user_model().objects.create_user("zoidberg", first_name=u"∂ƒ©˙∆", last_name=u"†¥¨^") token = RequestToken.objects.create_token( scope="foo", user=user, login_mode=RequestToken.LOGIN_MODE_REQUEST) log = RequestTokenLog(token=token, user=user).save() elog = RequestTokenErrorLog.objects.create_error_log( log, MaxUseError("foo")) self.assertEqual(elog.token, token) self.assertEqual(elog.log, log) self.assertEqual(elog.error_type, "MaxUseError") self.assertEqual(elog.error_message, "foo") self.assertEqual(str(elog), "foo")
def test_ipv6(self): """Test that IP v4 and v6 are handled.""" log = RequestTokenLog(token=self.token, user=self.user).save() self.assertIsNone(log.client_ip) def assertIP(ip): log.client_ip = ip log.save() self.assertEqual(log.client_ip, ip) assertIP('192.168.0.1') # taken from http://ipv6.com/articles/general/IPv6-Addressing.htm assertIP('2001:cdba:0000:0000:0000:0000:3257:9652') assertIP('2001:cdba:0:0:0:0:3257:9652') assertIP('2001:cdba::3257:9652')