gault-millau/apps/account/tests/tests_common.py
Виктор Гладких 70f9100813 Add test for change-password
2019-09-23 17:31:51 +03:00

68 lines
2.3 KiB
Python

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 = {
"old_password" : self.data["password"],
"password": "new password"
}
response = self.client.patch(self.url, data=data, format='json')
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.patch(self.url, data=data, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)