File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818async def create_admin (session : AsyncSession ):
1919 ADMIN_USER = os .getenv ("ADMIN_USER" )
2020 ADMIN_PASSWORD = os .getenv ("ADMIN_PASSWORD" )
21+ ADMIN_EMAIL = os .getenv ("ADMIN_EMAIL" )
2122 password = ADMIN_PASSWORD
2223 hashed_password = auth .hash_password (password )
2324 community = DBCommunity (
2425 username = ADMIN_USER ,
25- email = "ADMIN_USER@mail.com" ,
26+ email = ADMIN_EMAIL ,
2627 password = hashed_password ,
2728 role = "admin" ,
2829 )
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ services:
1717 - ENCRYPTION_KEY=r0-QKv5qACJNFRqy2cNZCsfZ_zVvehlC-v8zDJb--EI=
1818 - ADMIN_USER=admin
1919 - ADMIN_PASSWORD=admin
20+ - ADMIN_EMAIL = ADMIN_USER@mail.com
2021 - ALGORITHM=HS256
2122 - ACCESS_TOKEN_EXPIRE_MINUTES=20
2223 restart : unless-stopped
Original file line number Diff line number Diff line change 1+ import os
12from collections .abc import AsyncGenerator
23
34import pytest
2223# Usamos engine e AsyncSessionLocal apenas para os testes.
2324# Isso garante que os testes são isolados e usam o banco de dados em memória.
2425TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:"
26+ os .environ ["ADMIN_USER" ] = "ADMIN_USER"
27+ os .environ ["ADMIN_PASSWORD" ] = "ADMIN_PASSWORD"
28+ os .environ ["ADMIN_EMAIL" ] = "ADMIN_EMAIL"
29+
2530
2631test_engine = create_async_engine (TEST_DATABASE_URL , echo = False , future = True )
2732
Original file line number Diff line number Diff line change 1+ import pytest
2+ from sqlmodel import select
3+ from sqlmodel .ext .asyncio .session import AsyncSession
4+
5+ from app .routers .admin .routes import create_admin
6+ from app .services .auth import verify_password
7+ from app .services .database .models import Community
8+ from app .services .encryption import decrypt_email
9+
10+ # Dados de teste
11+ TEST_USERNAME = "test_user_crypto"
12+ TEST_EMAIL = "crypto@test.com"
13+ TEST_PASSWORD = "@SafePassword123"
14+ import os
15+
16+
17+ @pytest .mark .asyncio
18+ async def test_insert_admin (session : AsyncSession ):
19+ ADMIN_USER = os .getenv ("ADMIN_USER" )
20+ ADMIN_EMAIL = os .getenv ("ADMIN_EMAIL" )
21+ ADMIN_PASSWORD = os .getenv ("ADMIN_PASSWORD" )
22+
23+ community = Community (
24+ username = ADMIN_USER ,
25+ )
26+
27+ await create_admin (session )
28+ statement = select (Community ).where (community .username == ADMIN_USER )
29+ result = await session .exec (statement )
30+ found = result .first ()
31+
32+ assert found is not None
33+ assert found .username == ADMIN_USER
34+ assert decrypt_email (found .email ) == ADMIN_EMAIL
35+ assert verify_password (ADMIN_PASSWORD , found .password )
You can’t perform that action at this time.
0 commit comments