def test_is_valid(self, mock_now):
        now = tz_now()
        mock_now.return_value = now
        token = RequestToken()
        admin = RequestTokenAdmin(RequestToken, None)

        token.not_before_time = now + datetime.timedelta(minutes=1)
        self.assertTrue(token.not_before_time > now)
        self.assertFalse(admin.is_valid(token))

        token.not_before_time = None
        token.expiration_time = now - datetime.timedelta(minutes=1)
        self.assertTrue(token.expiration_time < now)
        self.assertFalse(admin.is_valid(token))

        token.expiration_time = None
        token.max_uses = 1
        token.used_to_date = 1
        self.assertFalse(admin.is_valid(token))

        # finally make it valid
        token.max_uses = 10
        self.assertTrue(admin.is_valid(token))
Ejemplo n.º 2
0
 def test_validate_max_uses(self):
     token = RequestToken(max_uses=1, used_to_date=0)
     token.validate_max_uses()
     token.used_to_date = token.max_uses
     self.assertRaises(MaxUseError, token.validate_max_uses)
 def test_validate_max_uses_disabled(self):
     token = RequestToken(max_uses=0, used_to_date=0)
     token.validate_max_uses()
     token.used_to_date = 1
     token.validate_max_uses()