Skip to content

Commit

Permalink
fix(tests) Clean up test logic
Browse files Browse the repository at this point in the history
  • Loading branch information
VVoruganti committed Sep 14, 2024
1 parent 25b01de commit 589ad33
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "honcho"
version = "0.0.11"
version = "0.0.12"
description = "Honcho Server"
authors = [
{name = "Plastic Labs", email = "[email protected]"},
Expand All @@ -26,8 +26,8 @@ dependencies = [
"mirascope>=0.18.0",
"openai>=1.43.0",
]
[project.optional-dependencies]
test = [
[tool.uv]
dev-dependencies = [
"pytest>=8.2.2",
"sqlalchemy-utils>=0.41.2",
"pytest-asyncio>=0.23.7",
Expand Down
16 changes: 10 additions & 6 deletions src/routers/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ async def enqueue(payload: dict):
session_id=payload["session_id"],
)
# Check if metadata has a "deriver" key
deriver_disabled = session.h_metadata.get("deriver_disabled")
if deriver_disabled is not None and deriver_disabled is not False:
print("=====================")
print(f"Deriver is not enabled on session {payload['session_id']}")
print("=====================")
# If deriver is not enabled, do not enqueue
if session is not None:
deriver_disabled = session.h_metadata.get("deriver_disabled")
if deriver_disabled is not None and deriver_disabled is not False:
print("=====================")
print(f"Deriver is not enabled on session {payload['session_id']}")
print("=====================")
# If deriver is not enabled, do not enqueue
return
else:
# Session doesn't exist return
return
try:
processed_payload = {
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ async def override_get_db():
async def sample_data(db_session):
"""Helper function to create test data"""
# Create test app
test_app = models.App(name=str(uuid.uuid4()), metadata={})
test_app = models.App(name=str(uuid.uuid4()))
db_session.add(test_app)
await db_session.flush()

# Create test user
test_user = models.User(name=str(uuid.uuid4()), app_id=test_app.id, metadata={})
test_user = models.User(name=str(uuid.uuid4()), app_id=test_app.id)
db_session.add(test_user)
await db_session.flush()

Expand Down
10 changes: 5 additions & 5 deletions tests/routes/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
async def test_create_message(client, db_session, sample_data):
test_app, test_user = sample_data
# Create a test session
test_session = models.Session(user_id=test_user.id, metadata={})
test_session = models.Session(user_id=test_user.id)
db_session.add(test_session)
await db_session.commit()

Expand All @@ -31,11 +31,11 @@ async def test_create_message(client, db_session, sample_data):
async def test_get_messages(client, db_session, sample_data):
test_app, test_user = sample_data
# Create a test session and message
test_session = models.Session(user_id=test_user.id, metadata={})
test_session = models.Session(user_id=test_user.id)
db_session.add(test_session)
await db_session.commit()
test_message = models.Message(
session_id=test_session.id, content="Test message", is_user=True, metadata={}
session_id=test_session.id, content="Test message", is_user=True
)
db_session.add(test_message)
await db_session.commit()
Expand All @@ -56,11 +56,11 @@ async def test_get_messages(client, db_session, sample_data):
async def test_update_message(client, db_session, sample_data):
test_app, test_user = sample_data
# Create a test session and message
test_session = models.Session(user_id=test_user.id, metadata={})
test_session = models.Session(user_id=test_user.id)
db_session.add(test_session)
await db_session.commit()
test_message = models.Message(
session_id=test_session.id, content="Test message", is_user=True, metadata={}
session_id=test_session.id, content="Test message", is_user=True
)
db_session.add(test_message)
await db_session.commit()
Expand Down
12 changes: 6 additions & 6 deletions tests/routes/test_metamessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
async def test_create_metamessage(client, db_session, sample_data):
test_app, test_user = sample_data
# Create a test session
test_session = models.Session(user_id=test_user.id, metadata={})
test_session = models.Session(user_id=test_user.id)
db_session.add(test_session)
await db_session.commit()
test_message = models.Message(
session_id=test_session.id, content="Test message", is_user=True, metadata={}
session_id=test_session.id, content="Test message", is_user=True
)
db_session.add(test_message)
await db_session.commit()
Expand All @@ -37,11 +37,11 @@ async def test_create_metamessage(client, db_session, sample_data):
async def test_get_metamessage(client, db_session, sample_data):
test_app, test_user = sample_data
# Create a test session
test_session = models.Session(user_id=test_user.id, metadata={})
test_session = models.Session(user_id=test_user.id)
db_session.add(test_session)
await db_session.commit()
test_message = models.Message(
session_id=test_session.id, content="Test message", is_user=True, metadata={}
session_id=test_session.id, content="Test message", is_user=True
)
db_session.add(test_message)
await db_session.commit()
Expand Down Expand Up @@ -69,11 +69,11 @@ async def test_get_metamessage(client, db_session, sample_data):
async def test_update_metamessage(client, db_session, sample_data):
test_app, test_user = sample_data
# Create a test session
test_session = models.Session(user_id=test_user.id, metadata={})
test_session = models.Session(user_id=test_user.id)
db_session.add(test_session)
await db_session.commit()
test_message = models.Message(
session_id=test_session.id, content="Test message", is_user=True, metadata={}
session_id=test_session.id, content="Test message", is_user=True
)
db_session.add(test_message)
await db_session.commit()
Expand Down
20 changes: 12 additions & 8 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 589ad33

Please sign in to comment.