from rest_framework.test import APITestCase from rest_framework import status from authorization.tests.tests import get_tokens_for_user from http.cookies import SimpleCookie # Create your tests here. class AccountUserTests(APITestCase): url = '/api/web/account/user/' def setUp(self): self.data = get_tokens_for_user() def test_user_url(self): response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) self.client.cookies = SimpleCookie( {'access_token': self.data['tokens'].get('access_token'), 'refresh_token': self.data['tokens'].get('access_token')}) response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) data = { "username": self.data["username"], "first_name": "Test first name", "last_name": "Test last name", "cropped_image_url": "http://localhost/image/cropped.png", "image_url": "http://localhost/image/avatar.png", "email": "sedragurdatest@desoz.com", "newsletter": self.data["newsletter"] } response = self.client.patch(self.url, data=data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) data["email"] = "sedragurdatest2@desoz.com" response = self.client.put(self.url, data=data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) class AccountChangePasswordTests(APITestCase): url = '/api/web/account/change-password/' def setUp(self): self.data = get_tokens_for_user() def test_change_password(self): data = { "password": "new password" } response = self.client.patch(self.url, data=data, format='json') self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)