|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +"""Remove Authentication |
| 4 | +Tests for 'New authentication credentials added to existing object' (200), |
| 5 | +'Authentication credentials were created and added' (201), 'Bad request' (400), |
| 6 | +'That object already exists for this account' (409) |
| 7 | +""" |
| 8 | + |
1 | 9 | from django.test import TestCase |
2 | 10 | from rest_framework.test import APIClient |
3 | 11 | from rest_framework.authtoken.models import Token |
4 | 12 | from django.contrib.auth.models import User |
5 | 13 | from rest_framework.test import APITestCase |
6 | 14 |
|
7 | 15 | class AuthenticationRemovetestcase(APITestCase): |
| 16 | + fixtures = ['tests/fixtures/test_data'] |
| 17 | + |
8 | 18 | def setUp(self): |
9 | 19 | self.client = APIClient() |
10 | 20 |
|
11 | | - # Creating a user and a token for authentication |
12 | | - self.user = User.objects.create(username='testuser') |
13 | | - # Checking if user already has token, if not then creating one |
14 | | - if not Token.objects.filter(user=self.user).exists(): |
15 | | - self.token = Token.objects.create(user=self.user) |
16 | | - else: |
17 | | - self.token = Token.objects.get(user=self.user) |
18 | | - |
19 | | - |
20 | 21 | def test_success_response(self): |
21 | | - # Successful request with authentication data |
| 22 | + """# Successful request with authentication data |
22 | 23 | #Gives a 409 instead of 200 |
23 | | - data = { |
24 | | - "iss": "0000-0000-0000-0000", |
25 | | - "sub": "https://example.org" |
26 | | - } |
27 | | - |
28 | | - self.client.force_authenticate(user=self.user) |
29 | | - response = self.client.post('/api/auth/remove/', data=data) |
30 | | - self.assertEqual(response.status_code, 409) |
31 | | - |
32 | | - def test_bad_request_response(self): |
33 | | - # Bad request: Missing required fields |
34 | | - data = {} |
35 | | - self.client.force_authenticate(user=self.user) |
36 | | - response = self.client.post('/api/auth/remove/', data=data) |
37 | | - self.assertEqual(response.status_code, 400) |
38 | | - |
39 | | - def test_object_already_exists_response(self): |
40 | | - # Object already exists for this account |
41 | | - data = { |
42 | | - "iss": "0000-0000-0000-0000", |
43 | | - "sub": "https://example.org" |
44 | | - } |
45 | | - |
46 | | - self.client.force_authenticate(user=self.user) |
47 | | - response = self.client.post('/api/auth/remove/', data=data) |
48 | | - self.assertEqual(response.status_code, 409) |
| 24 | + """ |
| 25 | + token = Token.objects.get(user=User.objects.get(username='bco_api_user')).key |
| 26 | + data = {"iss": "Reeya1","sub": "ReeyaGupta1"} |
| 27 | + |
| 28 | + self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) |
| 29 | + response = self.client.post('/api/auth/remove/', data=data, format='json') |
| 30 | + print(response.json()) |
| 31 | + self.assertEqual(response.status_code, 200) |
| 32 | + |
| 33 | + # def test_bad_request_response(self): |
| 34 | + # # Bad request: Missing required fields |
| 35 | + # data = {} |
| 36 | + # self.client.force_authenticate(user=self.user) |
| 37 | + # response = self.client.post('/api/auth/remove/', data=data) |
| 38 | + # self.assertEqual(response.status_code, 400) |
| 39 | + |
| 40 | + # def test_object_already_exists_response(self): |
| 41 | + # # Object already exists for this account |
| 42 | + # data = { |
| 43 | + # "iss": "0000-0000-0000-0000", |
| 44 | + # "sub": "https://example.org" |
| 45 | + # } |
| 46 | + |
| 47 | + # self.client.force_authenticate(user=self.user) |
| 48 | + # response = self.client.post('/api/auth/remove/', data=data) |
| 49 | + # self.assertEqual(response.status_code, 409) |
0 commit comments