parent
6ca8139a68
commit
b92e6d0435
11 changed files with 177 additions and 6 deletions
@ -0,0 +1,28 @@ |
||||
import pytest |
||||
from tests.client import BetterAPIClient |
||||
|
||||
pytest_plugins = [ |
||||
'tests.fixtures.users', |
||||
] |
||||
|
||||
@pytest.fixture |
||||
def api_client(): |
||||
"""Anonymous client for REST API.""" |
||||
client = BetterAPIClient() |
||||
return client |
||||
|
||||
|
||||
@pytest.fixture |
||||
def staff_client(user_staff): |
||||
"""Authorized as staff client for REST API.""" |
||||
client = BetterAPIClient() |
||||
client.force_authenticate(user=user_staff) |
||||
return client |
||||
|
||||
|
||||
@pytest.fixture |
||||
def student_client(user_student): |
||||
"""Authorized as staff client for REST API.""" |
||||
client = BetterAPIClient() |
||||
client.force_authenticate(user=user_student) |
||||
return client |
||||
@ -0,0 +1,42 @@ |
||||
import mock |
||||
import pytest |
||||
|
||||
from django.contrib.auth import get_user_model |
||||
from django.urls import reverse |
||||
|
||||
from rest_framework import status |
||||
from rest_framework.generics import get_object_or_404 |
||||
|
||||
|
||||
@pytest.mark.django_db |
||||
@mock.patch('django.core.mail.send_mail') |
||||
def test_generate_password_by_manager(mocked_send_mail, staff_client, |
||||
student_client, user_student): |
||||
""" |
||||
Test generate new password from admin area by manager |
||||
""" |
||||
assert staff_client.get( |
||||
reverse('users:management-password'), |
||||
status=status.HTTP_405_METHOD_NOT_ALLOWED |
||||
) |
||||
assert student_client.get( |
||||
reverse('users:management-password'), |
||||
status=status.HTTP_403_FORBIDDEN |
||||
) |
||||
data = { |
||||
'email': user_student.email, |
||||
} |
||||
assert staff_client.post( |
||||
reverse('users:management-password'), |
||||
data=data, |
||||
status=status.HTTP_201_CREATED |
||||
) |
||||
test_user = get_object_or_404(get_user_model(), email=user_student.email) |
||||
assert not test_user.check_password('test') |
||||
assert mocked_send_mail.call_count == 1 |
||||
assert student_client.post( |
||||
reverse('users:management-password'), |
||||
data=data, |
||||
status=status.HTTP_403_FORBIDDEN |
||||
) |
||||
|
||||
Loading…
Reference in new issue