81 lines
2.7 KiB
Python
81 lines
2.7 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
|
|
from account.models import User
|
|
from os import path
|
|
# 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)
|
|
|
|
|
|
class AccountChangePasswordTests(APITestCase):
|
|
# "/web/account/email/confirm/{uidb64}/{token}/"
|
|
url = "/web/account/email/confirm/"
|
|
|
|
def setUp(self):
|
|
self.data = get_tokens_for_user()
|
|
|
|
def test_confirm_email(self):
|
|
user = User.objects.get(email=self.data["email"])
|
|
token = user.confirm_email_token
|
|
uid64 = user.get_user_uidb64
|
|
url = path.join(self.url, uid64, token, "")
|