Skip to content

Commit

Permalink
update requirements for unittest-xml (#656)
Browse files Browse the repository at this point in the history
* update deprecated requirement for tests

* Update main.yml

* Update main.yml

* fixed tests not working in python 3.12
  • Loading branch information
FilMar authored Nov 3, 2024
1 parent 40d7f07 commit e5e07f3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
needs: [build]
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
django-version: ['3.2', '4.2', '5.0']
exclude:
- python-version: '3.8'
Expand Down
2 changes: 1 addition & 1 deletion dj_rest_auth/tests/requirements.pip
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ django-allauth==0.61.1
djangorestframework-simplejwt>=5.3.1
flake8==3.8.4
responses==0.12.1
unittest-xml-reporting==3.0.4
unittest-xml-reporting==3.2.0
62 changes: 31 additions & 31 deletions dj_rest_auth/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def test_cookie_authentication(self):
resp = self.post(self.login_url, data=payload, status_code=200)
self.assertEqual(['jwt-auth'], list(resp.cookies.keys()))
resp = self.get('/protected-view/')
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

@modify_settings(INSTALLED_APPS={'remove': ['rest_framework_simplejwt.token_blacklist']})
@override_api_settings(USE_JWT=True)
Expand Down Expand Up @@ -794,9 +794,9 @@ def test_custom_jwt_claims(self):
self.assertEqual('access' in self.response.json.keys(), True)
self.token = self.response.json['access']
claims = decode_jwt(self.token, settings.SECRET_KEY, algorithms='HS256')
self.assertEquals(claims['user_id'], 1)
self.assertEquals(claims['name'], 'person')
self.assertEquals(claims['email'], '[email protected]')
self.assertEqual(claims['user_id'], 1)
self.assertEqual(claims['name'], 'person')
self.assertEqual(claims['email'], '[email protected]')

@override_api_settings(USE_JWT=True)
@override_api_settings(JWT_AUTH_COOKIE='jwt-auth')
Expand All @@ -819,11 +819,11 @@ def test_custom_jwt_claims_cookie_w_authentication(self):
self.assertEqual(['jwt-auth'], list(resp.cookies.keys()))
token = resp.cookies.get('jwt-auth').value
claims = decode_jwt(token, settings.SECRET_KEY, algorithms='HS256')
self.assertEquals(claims['user_id'], 1)
self.assertEquals(claims['name'], 'person')
self.assertEquals(claims['email'], '[email protected]')
self.assertEqual(claims['user_id'], 1)
self.assertEqual(claims['name'], 'person')
self.assertEqual(claims['email'], '[email protected]')
resp = self.get('/protected-view/')
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

@override_api_settings(USE_JWT=True)
@override_api_settings(JWT_AUTH_COOKIE='jwt-auth')
Expand All @@ -850,22 +850,22 @@ def test_wo_csrf_enforcement(self):

resp = client.post(self.login_url, payload)
self.assertTrue('jwt-auth' in list(client.cookies.keys()))
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

# TEST WITH JWT AUTH HEADER
jwtclient = APIClient(enforce_csrf_checks=True)
token = resp.data['access']
resp = jwtclient.get('/protected-view/', HTTP_AUTHORIZATION='Bearer ' + token)
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)
resp = jwtclient.post('/protected-view/', {}, HTTP_AUTHORIZATION='Bearer ' + token)
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

# TEST WITH COOKIES
resp = client.get('/protected-view/')
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

resp = client.post('/protected-view/', {})
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

@override_api_settings(USE_JWT=True)
@override_api_settings(JWT_AUTH_COOKIE='jwt-auth')
Expand Down Expand Up @@ -896,30 +896,30 @@ def test_csrf_wo_login_csrf_enforcement(self):
resp = client.post(self.login_url, payload)
self.assertTrue('jwt-auth' in list(client.cookies.keys()))
self.assertTrue('csrftoken' in list(client.cookies.keys()))
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

# TEST WITH JWT AUTH HEADER
jwtclient = APIClient(enforce_csrf_checks=True)
token = resp.data['access']
resp = jwtclient.get('/protected-view/')
self.assertEquals(resp.status_code, 403)
self.assertEqual(resp.status_code, 403)
resp = jwtclient.get('/protected-view/', HTTP_AUTHORIZATION='Bearer ' + token)
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)
resp = jwtclient.post('/protected-view/', {})
self.assertEquals(resp.status_code, 403)
self.assertEqual(resp.status_code, 403)
resp = jwtclient.post('/protected-view/', {}, HTTP_AUTHORIZATION='Bearer ' + token)
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

# TEST WITH COOKIES
resp = client.get('/protected-view/')
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)
# fail w/o csrftoken in payload
resp = client.post('/protected-view/', {})
self.assertEquals(resp.status_code, 403)
self.assertEqual(resp.status_code, 403)

csrfparam = {'csrfmiddlewaretoken': csrftoken}
resp = client.post('/protected-view/', csrfparam)
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

@override_api_settings(USE_JWT=True)
@override_api_settings(JWT_AUTH_COOKIE='jwt-auth')
Expand Down Expand Up @@ -949,26 +949,26 @@ def test_csrf_w_login_csrf_enforcement(self):

# fail w/o csrftoken in payload
resp = client.post(self.login_url, payload)
self.assertEquals(resp.status_code, 403)
self.assertEqual(resp.status_code, 403)

payload['csrfmiddlewaretoken'] = csrftoken
resp = client.post(self.login_url, payload)
self.assertTrue('jwt-auth' in list(client.cookies.keys()))
self.assertTrue('csrftoken' in list(client.cookies.keys()))
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

# TEST WITH JWT AUTH HEADER does not make sense

# TEST WITH COOKIES
resp = client.get('/protected-view/')
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)
# fail w/o csrftoken in payload
resp = client.post('/protected-view/', {})
self.assertEquals(resp.status_code, 403)
self.assertEqual(resp.status_code, 403)

csrfparam = {'csrfmiddlewaretoken': csrftoken}
resp = client.post('/protected-view/', csrfparam)
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

@override_api_settings(USE_JWT=True)
@override_api_settings(JWT_AUTH_COOKIE='jwt-auth')
Expand Down Expand Up @@ -998,26 +998,26 @@ def test_csrf_w_login_csrf_enforcement_2(self):

# fail w/o csrftoken in payload
resp = client.post(self.login_url, payload)
self.assertEquals(resp.status_code, 403)
self.assertEqual(resp.status_code, 403)

payload['csrfmiddlewaretoken'] = csrftoken
resp = client.post(self.login_url, payload)
self.assertTrue('jwt-auth' in list(client.cookies.keys()))
self.assertTrue('csrftoken' in list(client.cookies.keys()))
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

# TEST WITH JWT AUTH HEADER does not make sense

# TEST WITH COOKIES
resp = client.get('/protected-view/')
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)
# fail w/o csrftoken in payload
resp = client.post('/protected-view/', {})
self.assertEquals(resp.status_code, 403)
self.assertEqual(resp.status_code, 403)

csrfparam = {'csrfmiddlewaretoken': csrftoken}
resp = client.post('/protected-view/', csrfparam)
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

@override_api_settings(JWT_AUTH_RETURN_EXPIRATION=True)
@override_api_settings(USE_JWT=True)
Expand Down

0 comments on commit e5e07f3

Please sign in to comment.