Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ jobs:
uses: astral-sh/ruff-action@v3.2.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: ruff format --check
51 changes: 36 additions & 15 deletions promo_code/user/tests/user/operations/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def setUp(self):
'other': {'age': 23, 'country': 'us'},
}
response = self.client.post(
self.signup_url, signup_data, format='json',
self.signup_url,
signup_data,
format='json',
)
token = response.data.get('access')
self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + token)
Expand All @@ -23,7 +25,8 @@ def setUp(self):
def test_get_profile_initial(self):
response = self.client.get(self.user_profile_url, format='json')
self.assertEqual(
response.status_code, rest_framework.status.HTTP_200_OK,
response.status_code,
rest_framework.status.HTTP_200_OK,
)
expected = {
'name': 'Steve',
Expand All @@ -36,24 +39,31 @@ def test_get_profile_initial(self):
def test_patch_profile_update_name_and_surname(self):
payload = {'name': 'John', 'surname': 'Tsal'}
response = self.client.patch(
self.user_profile_url, payload, format='json',
self.user_profile_url,
payload,
format='json',
)
self.assertEqual(
response.status_code, rest_framework.status.HTTP_200_OK,
response.status_code,
rest_framework.status.HTTP_200_OK,
)
self.assertEqual(response.data.get('name'), 'John')
self.assertEqual(response.data.get('surname'), 'Tsal')

def test_patch_profile_update_avatar_url(self):
payload = {'avatar_url': 'http://nodomain.com/kitten.jpeg'}
response = self.client.patch(
self.user_profile_url, payload, format='json',
self.user_profile_url,
payload,
format='json',
)
self.assertEqual(
response.status_code, rest_framework.status.HTTP_200_OK,
response.status_code,
rest_framework.status.HTTP_200_OK,
)
self.assertEqual(
response.data.get('avatar_url'), 'http://nodomain.com/kitten.jpeg',
response.data.get('avatar_url'),
'http://nodomain.com/kitten.jpeg',
)

def test_patch_password_and_check_persistence(self):
Expand All @@ -69,30 +79,37 @@ def test_patch_password_and_check_persistence(self):
format='json',
)
response = self.client.patch(
self.user_profile_url, {'password': new_password}, format='json',
self.user_profile_url,
{'password': new_password},
format='json',
)
self.assertEqual(
response.status_code, rest_framework.status.HTTP_200_OK,
response.status_code,
rest_framework.status.HTTP_200_OK,
)
data = response.data
self.assertEqual(data.get('name'), 'John')
self.assertEqual(data.get('surname'), 'Tsal')
self.assertEqual(data.get('email'), 'creator@apple.com')
self.assertEqual(data.get('other'), {'age': 23, 'country': 'us'})
self.assertEqual(
data.get('avatar_url'), 'http://nodomain.com/kitten.jpeg',
data.get('avatar_url'),
'http://nodomain.com/kitten.jpeg',
)

# test old token still valid
response = self.client.get(self.user_profile_url, format='json')
self.assertEqual(
response.status_code, rest_framework.status.HTTP_200_OK,
response.status_code,
rest_framework.status.HTTP_200_OK,
)

def test_auth_sign_in_old_password_fails(self):
new_password = 'MegaGiant88888@dooRuveS'
response = self.client.patch(
self.user_profile_url, {'password': new_password}, format='json',
self.user_profile_url,
{'password': new_password},
format='json',
)
self.client.credentials()
response = self.client.post(
Expand All @@ -104,13 +121,16 @@ def test_auth_sign_in_old_password_fails(self):
format='json',
)
self.assertEqual(
response.status_code, rest_framework.status.HTTP_401_UNAUTHORIZED,
response.status_code,
rest_framework.status.HTTP_401_UNAUTHORIZED,
)

def test_auth_sign_in_new_password_succeeds(self):
new_password = 'MegaGiant88888@dooRuveS'
response = self.client.patch(
self.user_profile_url, {'password': new_password}, format='json',
self.user_profile_url,
{'password': new_password},
format='json',
)
self.client.credentials()
response = self.client.post(
Expand All @@ -122,5 +142,6 @@ def test_auth_sign_in_new_password_succeeds(self):
format='json',
)
self.assertEqual(
response.status_code, rest_framework.status.HTTP_200_OK,
response.status_code,
rest_framework.status.HTTP_200_OK,
)
28 changes: 20 additions & 8 deletions promo_code/user/tests/user/validations/test_profile_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ def setUp(self):
'other': {'age': 48, 'country': 'gb'},
}
response = self.client.post(
self.signup_url, signup_data, format='json',
self.signup_url,
signup_data,
format='json',
)
token = response.data.get('access')
self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + token)

def test_update_profile_empty_name_and_surname(self):
payload = {'name': '', 'surname': ''}
response = self.client.patch(
self.user_profile_url, payload, format='json',
self.user_profile_url,
payload,
format='json',
)
self.assertEqual(
response.status_code, rest_framework.status.HTTP_400_BAD_REQUEST,
response.status_code,
rest_framework.status.HTTP_400_BAD_REQUEST,
)

@parameterized.parameterized.expand(
Expand All @@ -39,10 +44,13 @@ def test_update_profile_empty_name_and_surname(self):
def test_update_profile_invalid_avatar_url(self, name, url):
payload = {'avatar_url': url}
response = self.client.patch(
self.user_profile_url, payload, format='json',
self.user_profile_url,
payload,
format='json',
)
self.assertEqual(
response.status_code, rest_framework.status.HTTP_400_BAD_REQUEST,
response.status_code,
rest_framework.status.HTTP_400_BAD_REQUEST,
)

@parameterized.parameterized.expand(
Expand All @@ -61,16 +69,20 @@ def test_update_profile_invalid_avatar_url(self, name, url):
def test_update_profile_weak_password(self, name, pwd):
payload = {'password': pwd}
response = self.client.patch(
self.user_profile_url, payload, format='json',
self.user_profile_url,
payload,
format='json',
)
self.assertEqual(
response.status_code, rest_framework.status.HTTP_400_BAD_REQUEST,
response.status_code,
rest_framework.status.HTTP_400_BAD_REQUEST,
)

def test_get_profile(self):
response = self.client.get(self.user_profile_url, format='json')
self.assertEqual(
response.status_code, rest_framework.status.HTTP_200_OK,
response.status_code,
rest_framework.status.HTTP_200_OK,
)
expected = {
'name': 'Jack',
Expand Down