예제 #1
0
 def test_token_wrong_user(self):
     token = login_token_generator.make_token(self.user)
     response = self.client.post(self.token_login_url,
                                 data={
                                     'user_id': self.other_user.pk,
                                     'token': token
                                 })
     self.assertEqual(response.status_code, 404)
예제 #2
0
 def test_token_missing_user(self):
     token = login_token_generator.make_token(self.user)
     response = self.client.post(self.token_login_url,
                                 data={
                                     'user_id': '1234567890',
                                     'token': token
                                 })
     self.assertEqual(response.status_code, 404)
예제 #3
0
 def test_token_login(self):
     token = login_token_generator.make_token(self.user)
     response = self.client.post(self.token_login_url,
                                 data={
                                     'user_id': self.user.pk,
                                     'token': token
                                 })
     self.assertEqual(response.status_code, 201)
     self.assertEqual(list(response.data.keys()), ['token'])
예제 #4
0
    def test_token_expired(self):
        past_time = time.time() - 35
        with mock.patch('django.core.signing.time.time',
                        return_value=past_time):
            token = login_token_generator.make_token(self.user)

        response = self.client.post(self.token_login_url,
                                    data={
                                        'user_id': self.user.pk,
                                        'token': token
                                    })
        self.assertEqual(response.status_code, 404)
예제 #5
0
 def get_login_token(self):
     return login_token_generator.make_token(self)
예제 #6
0
 def test_token_missing_argument(self):
     token = login_token_generator.make_token(self.user)
     response = self.client.post(self.token_login_url,
                                 data={'token': token})
     self.assertEqual(response.status_code, 400)