Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
    def testInvalidKey(self):
        data = utils.create(self.user)
        invalid_key = '%s-invalid' % data.key

        res = self.backend.authenticate(invalid_key)
        self.assertEqual(res, None)
Ejemplo n.º 13
0
    def testInvalid(self):
        data = utils.create(self.user, usage_left=0)

        res = self.backend.authenticate(data.key)
        self.assertEqual(res, None)
Ejemplo n.º 14
0
 def testOneWeek(self):
     oneweek = datetime.now() + timedelta(days=7)
     data = utils.create(self.user, expires=oneweek)
     self.assertEqual(data.expires, oneweek)
Ejemplo n.º 15
0
 def testTenTimes(self):
     data = utils.create(self.user, usage_left=10)
     self.assertEqual(data.usage_left, 10)
Ejemplo n.º 16
0
    def testGetUser(self):
        data = utils.create(self.user, usage_left=0)

        user = self.backend.get_user(self.user.id)
        self.assertEqual(user, self.user)
Ejemplo n.º 17
0
    def testInvalid(self):
        data = utils.create(self.user, usage_left=0)

        res = self.backend.authenticate(data.key)
        self.assertEqual(res, None)
Ejemplo n.º 18
0
    def testValid(self):
        data = utils.create(self.user)

        res = self.backend.authenticate(data.key)
        self.assertEqual(res, self.user)
Ejemplo n.º 19
0
    def testInvalidKey(self):
        data = utils.create(self.user)
        invalid_key = '{}-invalid'.format(data.key)

        res = self.backend.authenticate(invalid_key)
        self.assertEqual(res, None)
Ejemplo n.º 20
0
 def testNextPage(self):
     next = '/next/page/'
     data = utils.create(self.user, next=next)
     self.assertEqual(data.next, next)
Ejemplo n.º 21
0
    def testGetUser(self):
        data = utils.create(self.user, usage_left=0)

        user = self.backend.get_user(self.user.id)
        self.assertEqual(user, self.user)
Ejemplo n.º 22
0
    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)
Ejemplo n.º 23
0
 def testOneWeek(self):
     oneweek = timezone.now() + timedelta(days=7)
     data = utils.create(self.user, expires=oneweek)
     self.assertEqual(data.expires, oneweek)
Ejemplo n.º 24
0
    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)
Ejemplo n.º 25
0
 def testTenTimes(self):
     data = utils.create(self.user, usage_left=10)
     self.assertEqual(data.usage_left, 10)
Ejemplo n.º 26
0
    def testValid(self):
        data = utils.create(self.user)

        res = self.backend.authenticate(data.key)
        self.assertEqual(res, self.user)
Ejemplo n.º 27
0
 def testNextPage(self):
     next = '/next/page/'
     data = utils.create(self.user, next=next)
     self.assertEqual(data.next, next)
Ejemplo n.º 28
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)
Ejemplo n.º 29
0
def create_login_url(user):
    key = create(user)
    url = '/loginurl/%s' % key.key

    return url    
Ejemplo n.º 30
0
def create_login_url(user):
    key = create(user)

    return reverse('loginurl-login', args=[key.key])