|
|
@ -1,5 +1,6 @@ |
|
|
|
from unittest.mock import patch |
|
|
|
|
|
|
|
from fastapi.testclient import TestClient |
|
|
|
from pytest_mock import MockerFixture |
|
|
|
from sqlmodel import Session |
|
|
|
|
|
|
|
from app import crud |
|
|
@ -31,14 +32,11 @@ def test_get_users_normal_user_me( |
|
|
|
|
|
|
|
|
|
|
|
def test_create_user_new_email( |
|
|
|
client: TestClient, |
|
|
|
superuser_token_headers: dict[str, str], |
|
|
|
db: Session, |
|
|
|
mocker: MockerFixture, |
|
|
|
client: TestClient, superuser_token_headers: dict[str, str], db: Session |
|
|
|
) -> None: |
|
|
|
mocker.patch("app.utils.send_email") |
|
|
|
mocker.patch("app.core.config.settings.SMTP_HOST", "smtp.example.com") |
|
|
|
mocker.patch("app.core.config.settings.SMTP_USER", "admin@example.com") |
|
|
|
with patch("app.utils.send_email", return_value=None), patch( |
|
|
|
"app.core.config.settings.SMTP_HOST", "smtp.example.com" |
|
|
|
), patch("app.core.config.settings.SMTP_USER", "admin@example.com"): |
|
|
|
username = random_email() |
|
|
|
password = random_lower_string() |
|
|
|
data = {"email": username, "password": password} |
|
|
@ -265,8 +263,8 @@ def test_update_password_me_same_password_error( |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def test_create_user_open(client: TestClient, mocker: MockerFixture) -> None: |
|
|
|
mocker.patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True) |
|
|
|
def test_create_user_open(client: TestClient) -> None: |
|
|
|
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True): |
|
|
|
username = random_email() |
|
|
|
password = random_lower_string() |
|
|
|
full_name = random_lower_string() |
|
|
@ -281,10 +279,8 @@ def test_create_user_open(client: TestClient, mocker: MockerFixture) -> None: |
|
|
|
assert created_user["full_name"] == full_name |
|
|
|
|
|
|
|
|
|
|
|
def test_create_user_open_forbidden_error( |
|
|
|
client: TestClient, mocker: MockerFixture |
|
|
|
) -> None: |
|
|
|
mocker.patch("app.core.config.settings.USERS_OPEN_REGISTRATION", False) |
|
|
|
def test_create_user_open_forbidden_error(client: TestClient) -> None: |
|
|
|
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", False): |
|
|
|
username = random_email() |
|
|
|
password = random_lower_string() |
|
|
|
full_name = random_lower_string() |
|
|
@ -294,13 +290,13 @@ def test_create_user_open_forbidden_error( |
|
|
|
json=data, |
|
|
|
) |
|
|
|
assert r.status_code == 403 |
|
|
|
assert r.json()["detail"] == "Open user registration is forbidden on this server" |
|
|
|
assert ( |
|
|
|
r.json()["detail"] == "Open user registration is forbidden on this server" |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def test_create_user_open_already_exists_error( |
|
|
|
client: TestClient, mocker: MockerFixture |
|
|
|
) -> None: |
|
|
|
mocker.patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True) |
|
|
|
def test_create_user_open_already_exists_error(client: TestClient) -> None: |
|
|
|
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True): |
|
|
|
password = random_lower_string() |
|
|
|
full_name = random_lower_string() |
|
|
|
data = { |
|
|
@ -313,7 +309,10 @@ def test_create_user_open_already_exists_error( |
|
|
|
json=data, |
|
|
|
) |
|
|
|
assert r.status_code == 400 |
|
|
|
assert r.json()["detail"] == "The user with this email already exists in the system" |
|
|
|
assert ( |
|
|
|
r.json()["detail"] |
|
|
|
== "The user with this email already exists in the system" |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def test_update_user( |
|
|
|