def testExpired(self): oneweekago = datetime.now() - timedelta(days=7) data = utils.create(self.user, usage_left=1, expires=oneweekago) self.assertEqual(len(Key.objects.all()), 1) utils.cleanup() self.assertEqual(len(Key.objects.all()), 0)
def testExpired(self): oneweekago = timezone.now() - timedelta(days=7) data = utils.create(self.user, usage_left=1, expires=oneweekago) self.assertEqual(len(Key.objects.all()), 1) utils.cleanup() self.assertEqual(len(Key.objects.all()), 0)
def testValid(self): oneweek = timezone.now() + timedelta(days=7) data = utils.create(self.user, usage_left=1, expires=oneweek) self.assertEqual(len(Key.objects.all()), 1) utils.cleanup() self.assertEqual(len(Key.objects.all()), 1)
def testValid(self): oneweek = datetime.now() + timedelta(days=7) data = utils.create(self.user, usage_left=1, expires=oneweek) self.assertEqual(len(Key.objects.all()), 1) utils.cleanup() self.assertEqual(len(Key.objects.all()), 1)
def testDefault(self): data = utils.create(self.user) self.assertEqual(data.usage_left, 1) self.assertEqual(data.expires, None) self.assertEqual(data.next, None) uid_b36, key = data.key.split('-') self.assertEqual(int_to_base36(self.user.id), uid_b36) datadb = Key.objects.get(key=data.key) self.assertEqual(data, datadb)
def testNext(self): auth = Mock() auth.authenticate.return_value = self.user req = Mock() req.GET.get.return_value = '/next/query-string/' data = utils.create(self.user, next='/next/database/') self.assertEqual(data.usage_left, 1) @patch.object(views, 'auth', auth) def test(request, key): return views.login(request, key) res = test(req, data.key) self.assertTrue(isinstance(res, HttpResponseRedirect)) self.assertEqual(res['Location'], '/next/database/') datadb = Key.objects.get(key=data.key) self.assertEqual(datadb.usage_left, 0)
def testNext(self): auth = Mock() auth.authenticate.return_value = self.user req = Mock() req.GET.get.return_value = '/next/query-string/' data = utils.create(self.user, next='/next/database/') self.assertEqual(data.usage_left, 1) @patch_object(views, 'auth', auth) def test(request, key): return views.login(request, key) res = test(req, data.key) self.assertTrue(isinstance(res, HttpResponseRedirect)) self.assertEqual(res['Location'], '/next/database/') datadb = Key.objects.get(key=data.key) self.assertEqual(datadb.usage_left, 0)
def testDefault(self): auth = Mock() auth.authenticate.return_value = self.user req = Mock() req.GET.get.return_value = None data = utils.create(self.user) self.assertEqual(data.usage_left, 1) @patch_object(views, 'auth', auth) def test(request, key): return views.login(request, key) res = test(req, data.key) self.assertTrue(isinstance(res, HttpResponseRedirect)) self.assertEqual(res['Location'], settings.LOGIN_REDIRECT_URL) datadb = Key.objects.get(key=data.key) self.assertEqual(datadb.usage_left, 0)
def testDefault(self): auth = Mock() auth.authenticate.return_value = self.user req = Mock() req.GET.get.return_value = None data = utils.create(self.user) self.assertEqual(data.usage_left, 1) @patch.object(views, 'auth', auth) def test(request, key): return views.login(request, key) res = test(req, data.key) self.assertTrue(isinstance(res, HttpResponseRedirect)) self.assertEqual(res['Location'], settings.LOGIN_REDIRECT_URL) datadb = Key.objects.get(key=data.key) self.assertEqual(datadb.usage_left, 0)
def testAlwaysValid(self): data = utils.create(self.user, usage_left=None, expires=None) self.assertEqual(len(Key.objects.all()), 1) utils.cleanup() self.assertEqual(len(Key.objects.all()), 1)
def testInvalidKey(self): data = utils.create(self.user) invalid_key = '%s-invalid' % data.key res = self.backend.authenticate(invalid_key) self.assertEqual(res, None)
def testInvalid(self): data = utils.create(self.user, usage_left=0) res = self.backend.authenticate(data.key) self.assertEqual(res, None)
def testOneWeek(self): oneweek = datetime.now() + timedelta(days=7) data = utils.create(self.user, expires=oneweek) self.assertEqual(data.expires, oneweek)
def testTenTimes(self): data = utils.create(self.user, usage_left=10) self.assertEqual(data.usage_left, 10)
def testGetUser(self): data = utils.create(self.user, usage_left=0) user = self.backend.get_user(self.user.id) self.assertEqual(user, self.user)
def testValid(self): data = utils.create(self.user) res = self.backend.authenticate(data.key) self.assertEqual(res, self.user)
def testInvalidKey(self): data = utils.create(self.user) invalid_key = '{}-invalid'.format(data.key) res = self.backend.authenticate(invalid_key) self.assertEqual(res, None)
def testNextPage(self): next = '/next/page/' data = utils.create(self.user, next=next) self.assertEqual(data.next, next)
def testNegative(self): data = utils.create(self.user, usage_left=-1) self.assertEqual(len(Key.objects.all()), 1) utils.cleanup() self.assertEqual(len(Key.objects.all()), 0)
def testOneWeek(self): oneweek = timezone.now() + timedelta(days=7) data = utils.create(self.user, expires=oneweek) self.assertEqual(data.expires, oneweek)
def create_login_url(user): key = create(user) url = '/loginurl/%s' % key.key return url
def create_login_url(user): key = create(user) return reverse('loginurl-login', args=[key.key])