Skip to content

Commit

Permalink
user test part2
Browse files Browse the repository at this point in the history
  • Loading branch information
ZUS666 committed Nov 10, 2023
1 parent d32ac95 commit 36b0b2f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
46 changes: 44 additions & 2 deletions tests/api/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework import status


@pytest.mark.django_db(transaction=True)
@pytest.mark.django_db
class TestUserRegistration:
"""
Тесты регистрации пользователя.
Expand Down Expand Up @@ -94,10 +94,13 @@ def test_valid_data_signup(self, unauthed_client, django_user_model):
assert first_user.is_active is True


@pytest.mark.django_db(transaction=True)
@pytest.mark.django_db
class TestUserActions:
url_change_password = '/api/v1/users/change_password/'
url_me = '/api/v1/users/me/'
url_reset_password_code = '/api/v1/users/reset_password_confirmation_code/'
url_resend_password_code = '/api/v1/users/resend_confirmation_code/'
url_reset_password = '/api/v1/users/reset_password/'

def test_user_change_password(
self,
Expand Down Expand Up @@ -229,3 +232,42 @@ def test_users_patch_me(
f'{self.url_me} {response.status_code}'
f'{response.json()[key]} != {value}'
)

def test_reset_password(self, unauthed_client, full_data_user):
data = {'email': full_data_user.email}
response = unauthed_client.post(
self.url_reset_password_code, data=data
)
assert response.status_code == status.HTTP_200_OK, (
f'{self.url_reset_password_code} {response.status_code}'
f'with exists user.email'
)
code = cache.get(full_data_user.id)
valid_data = {
'email': full_data_user.email,
'confirmation_code': code,
'password': 'string!!!',
're_password': 'string!!!'
}
invalid_data_fields = (
('email', 'invalid@fake.com', status.HTTP_400_BAD_REQUEST),
('confirmation_code', '123321', status.HTTP_400_BAD_REQUEST),
('password', 'string!!!!', status.HTTP_400_BAD_REQUEST),
)
for field, value, status_code in invalid_data_fields:
invalid_data = valid_data.copy()
invalid_data[field] = value
response = unauthed_client.post(
self.url_reset_password, data=invalid_data
)
assert response.status_code == status_code, (
f'{self.url_reset_password} {response.status_code}'
f'{field}:{value} expected {status_code}'
)
response = unauthed_client.post(
self.url_reset_password, data=valid_data
)
assert response.status_code == status.HTTP_200_OK, (
f'{self.url_reset_password} {response.status_code} '
f'with valid data {valid_data}'
)
1 change: 1 addition & 0 deletions tests/fixtures/fixture_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def full_data_user(django_user_model):
phone='+79220011223',
birth_date=datetime.date(2000, 2, 2),
occupation='string',
is_active=True,
)


Expand Down

0 comments on commit 36b0b2f

Please sign in to comment.