diff --git a/app/tasks/tasks.py b/app/tasks/tasks.py index 95a4f62..b27e9e0 100644 --- a/app/tasks/tasks.py +++ b/app/tasks/tasks.py @@ -6,6 +6,7 @@ from pathlib import Path from PIL import Image from pydantic import EmailStr + from app.config import settings from app.tasks.celery import celery from app.tasks.email_templates import create_registration_confirmation_template, \ @@ -22,9 +23,11 @@ def generate_confirmation_code(length=6): def send_registration_confirmation_email( username: str, email_to: EmailStr, + MODE: str ): confirmation_code = generate_confirmation_code() - + if MODE == 'TEST': + return confirmation_code msg_content = create_registration_confirmation_template( username=username, email_to=email_to, confirmation_code=confirmation_code ) @@ -40,7 +43,10 @@ def send_registration_confirmation_email( def send_password_change_email( username: str, email_to: EmailStr, + MODE: str ): + if MODE == 'TEST': + return True msg_content = create_password_change_confirmation_template( username=username, email_to=email_to ) @@ -56,9 +62,11 @@ def send_password_change_email( def send_password_recover_email( username: str, email_to: EmailStr, + MODE: str ): confirmation_code = generate_confirmation_code() - + if MODE == 'TEST': + return confirmation_code msg_content = create_password_recover_template( username=username, email_to=email_to, confirmation_code=confirmation_code ) diff --git a/app/tests/integration_tests/chat_api_test.py b/app/tests/integration_tests/chat_api_test.py index ddaf67f..15eeaf0 100644 --- a/app/tests/integration_tests/chat_api_test.py +++ b/app/tests/integration_tests/chat_api_test.py @@ -1,3 +1,16 @@ import pytest from httpx import AsyncClient + +async def test_get_chats(ac: AsyncClient): + await ac.post("/users/login", json={ + "email_or_username": 'urec', + "password": '12311231' + }) + response = await ac.get('/chat') + assert response.status_code == 200 + print(response.json()) + assert len(response.json()) == 2 + + + diff --git a/app/tests/mock_x_chats.json b/app/tests/mock_x_chats.json index 7ec2b0a..1101771 100644 --- a/app/tests/mock_x_chats.json +++ b/app/tests/mock_x_chats.json @@ -6,5 +6,13 @@ { "user_id": 3, "chat_id": 2 + }, + { + "user_id": 1, + "chat_id": 1 + }, + { + "user_id": 3, + "chat_id": 1 } ] \ No newline at end of file diff --git a/app/users/router.py b/app/users/router.py index f39f3ad..e79bb42 100644 --- a/app/users/router.py +++ b/app/users/router.py @@ -1,6 +1,7 @@ from fastapi import APIRouter, Response, Depends, status from fastapi.responses import RedirectResponse +from app.config import settings from app.exceptions import UsernameAlreadyInUseException, \ IncorrectPasswordException, PasswordsМismatchException, WrongCodeException, UserNotFoundException, \ SomethingWentWrongException @@ -44,7 +45,9 @@ async def register_user(response: Response, user_data: SUserRegister): date_of_birth=user_data.date_of_birth, ) - result = send_registration_confirmation_email.delay(username=user_data.username, email_to=user_data.email) + result = send_registration_confirmation_email.delay( + username=user_data.username, email_to=user_data.email, MODE=settings.MODE + ) result = result.get() if await UserCodesDAO.set_user_codes( @@ -116,7 +119,7 @@ async def change_password(new_password: SUserPassword, current_user: Users = Dep raise PasswordsМismatchException hashed_password = get_password_hash(new_password.new_password) await UserDAO.change_data(current_user.id, hashed_password=hashed_password) - send_password_change_email.delay(current_user.username, current_user.email) + send_password_change_email.delay(current_user.username, current_user.email, MODE=settings.MODE) @router.patch("/send_recovery_email", status_code=status.HTTP_200_OK, response_model=SRecoverEmailSent) @@ -124,7 +127,7 @@ async def send_recovery_email(email: SUserPasswordRecover): existing_user = await UserDAO.find_one_or_none(email=email.email) if not existing_user: raise UserNotFoundException - result = send_password_recover_email.delay(existing_user.username, existing_user.email) + result = send_password_recover_email.delay(existing_user.username, existing_user.email, MODE=settings.MODE) result = result.get() if await UserCodesDAO.set_user_codes( @@ -153,5 +156,5 @@ async def password_recovery(passwords: SUserPasswordChange): user = await UserDAO.find_one_or_none(username=username, id=passwords.user_id) if not user: raise UserNotFoundException - send_password_change_email.delay(user.username, user.email) + send_password_change_email.delay(user.username, user.email, MODE=settings.MODE) return {"username": username}