kenken999's picture
sd
185f702
raw
history blame
984 Bytes
import pytest
from app.crud import CRUD
from app.models import User
@pytest.fixture
def crud():
return CRUD('postgresql://user:password@localhost/dbname')
def test_create_user(crud):
user = crud.create_user('Jane Doe', 'janedoe@example.com')
assert user.name == 'Jane Doe'
assert user.email == 'janedoe@example.com'
def test_read_user(crud):
user = crud.create_user('Jane Doe', 'janedoe@example.com')
read_user = crud.read_user(user.id)
assert read_user.name == 'Jane Doe'
assert read_user.email == 'janedoe@example.com'
def test_update_user(crud):
user = crud.create_user('Jane Doe', 'janedoe@example.com')
updated_user = crud.update_user(user.id, 'Jane Doe Updated', 'janedoeupdated@example.com')
assert updated_user.name == 'Jane Doe Updated'
assert updated_user.email == 'janedoeupdated@example.com'
def test_delete_user(crud):
user = crud.create_user('Jane Doe', 'janedoe@example.com')
assert crud.delete_user(user.id)