e60489715a
Client endpoint - GET & POST implemented
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import pytest
|
|
from sqlmodel import SQLModel, Session, create_engine
|
|
|
|
from app.core.config import settings
|
|
from app.api.deps import SessionDep
|
|
from app.schemas.schemas import ClientCreate
|
|
from app.api.clients.endpoints import create_client
|
|
from fastapi import HTTPException
|
|
|
|
|
|
# Fixture for a temporary in-memory database session
|
|
@pytest.fixture
|
|
def session():
|
|
engine = create_engine(str(settings.database_uri), echo=False)
|
|
SQLModel.metadata.create_all(engine)
|
|
with Session(engine) as session:
|
|
yield session
|
|
|
|
|
|
def test_create_client_success(session: SessionDep):
|
|
client_data = ClientCreate(tin_number=781410046, names="Lin", phone_number="0781410046")
|
|
client = create_client(client_data, session)
|
|
|
|
assert client.id is not None
|
|
assert client.names == "Lin"
|
|
assert client.tin_number == 781410046
|
|
assert client.phone_number == "0781410046"
|
|
|
|
|
|
def test_create_client_duplicate_name(session):
|
|
client_data = ClientCreate(tin_number=781410045, names="John Doe", phone_number="0781410045")
|
|
|
|
# Try to create another client with the same name
|
|
with pytest.raises(HTTPException) as exc_info:
|
|
create_client(client_data, session)
|
|
assert exc_info.value.status_code == 400
|
|
assert "already exists" in exc_info.value.detail
|