|
|
|
|
@ -7,9 +7,11 @@ from django.urls import reverse |
|
|
|
|
from rest_framework import status |
|
|
|
|
from rest_framework.generics import get_object_or_404 |
|
|
|
|
|
|
|
|
|
from factories.users import USER_PASSWORD |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db |
|
|
|
|
@mock.patch('django.core.mail.send_mail') |
|
|
|
|
@mock.patch('django.core.mail.EmailMessage.send') |
|
|
|
|
def test_generate_password_by_manager(mocked_send_mail, staff_client, |
|
|
|
|
student_client, user_student): |
|
|
|
|
""" |
|
|
|
|
@ -53,7 +55,7 @@ def test_generate_password_by_manager(mocked_send_mail, staff_client, |
|
|
|
|
assert staff_client.post( |
|
|
|
|
reverse('users:management-password'), |
|
|
|
|
data=wrong_email, |
|
|
|
|
status=status.HTTP_400_BAD_REQUEST |
|
|
|
|
status=status.HTTP_404_NOT_FOUND |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -70,5 +72,53 @@ def test_generate_password_by_manager_for_not_active_student(staff_client, |
|
|
|
|
assert staff_client.post( |
|
|
|
|
reverse('users:management-password'), |
|
|
|
|
data=data, |
|
|
|
|
status=status.HTTP_400_BAD_REQUEST |
|
|
|
|
status=status.HTTP_201_CREATED |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db |
|
|
|
|
def test_login_user(api_client, user_student): |
|
|
|
|
""" |
|
|
|
|
Test login user |
|
|
|
|
""" |
|
|
|
|
data = { |
|
|
|
|
'email': user_student.email, |
|
|
|
|
'password': USER_PASSWORD |
|
|
|
|
} |
|
|
|
|
assert api_client.post( |
|
|
|
|
reverse('users:login'), |
|
|
|
|
data=data, |
|
|
|
|
status=status.HTTP_200_OK |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db |
|
|
|
|
def test_login_user_wrong_password(api_client, user_student): |
|
|
|
|
""" |
|
|
|
|
Test login user with wrong password |
|
|
|
|
""" |
|
|
|
|
data = { |
|
|
|
|
'email': user_student.email, |
|
|
|
|
'password': USER_PASSWORD + '1' |
|
|
|
|
} |
|
|
|
|
assert api_client.post( |
|
|
|
|
reverse('users:login'), |
|
|
|
|
data=data, |
|
|
|
|
status=status.HTTP_403_FORBIDDEN |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db |
|
|
|
|
def test_login_user_wrong_user(api_client, user_student): |
|
|
|
|
""" |
|
|
|
|
Test login user with wrong password |
|
|
|
|
""" |
|
|
|
|
data = { |
|
|
|
|
'email': user_student.email + '1', |
|
|
|
|
'password': USER_PASSWORD |
|
|
|
|
} |
|
|
|
|
assert api_client.post( |
|
|
|
|
reverse('users:login'), |
|
|
|
|
data=data, |
|
|
|
|
status=status.HTTP_404_NOT_FOUND |
|
|
|
|
) |
|
|
|
|
|