Сделал тест на получение доступных чатов
This commit is contained in:
parent
02400f952b
commit
3c6c0df1ca
4 changed files with 38 additions and 6 deletions
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,5 +6,13 @@
|
|||
{
|
||||
"user_id": 3,
|
||||
"chat_id": 2
|
||||
},
|
||||
{
|
||||
"user_id": 1,
|
||||
"chat_id": 1
|
||||
},
|
||||
{
|
||||
"user_id": 3,
|
||||
"chat_id": 1
|
||||
}
|
||||
]
|
|
@ -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}
|
||||
|
|
Loading…
Add table
Reference in a new issue