test: add unit tests for routes (#4249)
This commit is contained in:
parent
a88fd9bbb0
commit
fadb20115d
23 changed files with 623 additions and 272 deletions
|
|
@ -384,6 +384,44 @@ async def logged_in_headers(client, active_user):
|
|||
return {"Authorization": f"Bearer {a_token}"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def active_super_user(client): # noqa: ARG001
|
||||
db_manager = get_db_service()
|
||||
with db_manager.with_session() as session:
|
||||
user = User(
|
||||
username="activeuser",
|
||||
password=get_password_hash("testpassword"),
|
||||
is_active=True,
|
||||
is_superuser=True,
|
||||
)
|
||||
if active_user := session.exec(select(User).where(User.username == user.username)).first():
|
||||
user = active_user
|
||||
else:
|
||||
session.add(user)
|
||||
session.commit()
|
||||
session.refresh(user)
|
||||
user = UserRead.model_validate(user, from_attributes=True)
|
||||
yield user
|
||||
# Clean up
|
||||
# Now cleanup transactions, vertex_build
|
||||
with db_manager.with_session() as session:
|
||||
user = session.get(User, user.id)
|
||||
_delete_transactions_and_vertex_builds(session, user)
|
||||
session.delete(user)
|
||||
|
||||
session.commit()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def logged_in_headers_super_user(client, active_super_user):
|
||||
login_data = {"username": active_super_user.username, "password": "testpassword"}
|
||||
response = await client.post("api/v1/login", data=login_data)
|
||||
assert response.status_code == 200
|
||||
tokens = response.json()
|
||||
a_token = tokens["access_token"]
|
||||
return {"Authorization": f"Bearer {a_token}"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def flow(
|
||||
client, # noqa: ARG001
|
||||
|
|
@ -484,7 +522,7 @@ async def added_webhook_test(client, json_webhook_test, logged_in_headers):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
async def flow_component(client: TestClient, logged_in_headers):
|
||||
async def flow_component(client: AsyncClient, logged_in_headers):
|
||||
chat_input = ChatInput()
|
||||
graph = Graph(start=chat_input, end=chat_input)
|
||||
graph_dict = graph.dump(name="Chat Input Component")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue