Skip to content

Commit b665a14

Browse files
committed
saving
1 parent 826397e commit b665a14

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed
Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
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+
19
from django.test import TestCase
210
from rest_framework.test import APIClient
311
from rest_framework.authtoken.models import Token
412
from django.contrib.auth.models import User
513
from rest_framework.test import APITestCase
614

715
class AuthenticationRemovetestcase(APITestCase):
16+
fixtures = ['tests/fixtures/test_data']
17+
818
def setUp(self):
919
self.client = APIClient()
1020

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-
2021
def test_success_response(self):
21-
# Successful request with authentication data
22+
"""# Successful request with authentication data
2223
#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

Comments
 (0)