Delete testing user afer unit test session
This commit is contained in:
parent
6c7a561fef
commit
71517bb8b2
|
@ -2,6 +2,7 @@ from datetime import datetime
|
|||
|
||||
from fastapi import HTTPException
|
||||
from passlib.context import CryptContext
|
||||
from sqlalchemy.inspection import inspect
|
||||
|
||||
from app.schemas import *
|
||||
from constants import SHA1_SALT
|
||||
|
@ -31,11 +32,12 @@ def insert_data(model, data, db):
|
|||
return item
|
||||
|
||||
|
||||
# FIXME db.id has to be replaced with the table's UID
|
||||
def delete_data(model, data, db):
|
||||
item = instantiate_model(model=model, data=data)
|
||||
result = db.query(item).filter(item.email == data.email).delete()
|
||||
return result
|
||||
table = eval(model)
|
||||
primary_key_tuple = inspect(table).primary_key
|
||||
primary_key = primary_key_tuple[0]
|
||||
db.query(table).filter(primary_key == data).delete()
|
||||
db.commit()
|
||||
|
||||
|
||||
def fetch_user_by_key(data, db):
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
from pytest import fixture
|
||||
|
||||
from database.crud import delete_data
|
||||
from tests import TestingSessionLocal
|
||||
|
||||
|
||||
@fixture(scope="session")
|
||||
def get_test_db():
|
||||
try:
|
||||
db = TestingSessionLocal()
|
||||
yield db
|
||||
finally:
|
||||
delete_data(model="Users", data=2222, db=db)
|
||||
db.close()
|
|
@ -1,18 +1,6 @@
|
|||
from datetime import datetime
|
||||
|
||||
from pytest import fixture
|
||||
|
||||
from database.models import *
|
||||
from tests import TestingSessionLocal
|
||||
|
||||
|
||||
@fixture
|
||||
def get_test_db():
|
||||
try:
|
||||
db = TestingSessionLocal()
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_users(get_test_db):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from secrets import token_hex
|
||||
|
||||
from pytest import main
|
||||
|
||||
from app.schemas import *
|
||||
from database.models import *
|
||||
from tests import client
|
||||
from tests.queries_test import get_test_db
|
||||
|
||||
|
||||
def test_registration():
|
||||
|
@ -55,8 +55,8 @@ def test_forgot_password():
|
|||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_reset_password():
|
||||
main(["-k" "test_otp_verification"])
|
||||
def test_reset_password(get_test_db):
|
||||
test_otp_verification(get_test_db)
|
||||
data = {"email": "oyvey@hotmail.com", "password": "vivashviva"}
|
||||
response = client.post("/reset_password", json=data)
|
||||
assert response.status_code == 200
|
||||
|
|
Loading…
Reference in New Issue