Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gecBurton committed Oct 10, 2024
1 parent 2ac2147 commit c5659f9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion django_app/redbox_app/redbox_core/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ async def receive(self, text_data=None, bytes_data=None):

if session_id := data.get("sessionId"):
session = await Chat.objects.aget(id=session_id)
logger.info("updating: chat_backend=%s -> ai_settings=%s", session.chat_backend, chat_backend)
session.chat_backend = chat_backend
session.temperature = temperature
await session.asave()
Expand Down
8 changes: 6 additions & 2 deletions django_app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ def _collect_static():
call_command("collectstatic", "--no-input")


@pytest.mark.django_db()
@pytest.fixture(autouse=True)
def default_ai_settings():
def default_ai_settings(db): # noqa: ARG001
gpt_4o, _ = ChatLLMBackend.objects.get_or_create(name="gpt-4o", provider="azure_openai", is_default=True)
ai_settings, _ = AISettings.objects.get_or_create(label="default", chat_backend=gpt_4o)
return ai_settings
Expand Down Expand Up @@ -105,6 +104,11 @@ def alice(create_user):
)


@pytest.fixture()
def chat_with_alice(alice):
return Chat.objects.create(name="a chat", user=alice)


@pytest.fixture()
def bob(create_user):
return create_user("bob@example.com", "2000-01-01")
Expand Down
13 changes: 5 additions & 8 deletions django_app/tests/test_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,25 +420,22 @@ async def test_chat_consumer_with_explicit_no_document_selected_error(
@pytest.mark.django_db()
@pytest.mark.asyncio()
async def test_chat_consumer_get_ai_settings(
alice: User, mocked_connect_with_explicit_no_document_selected_error: Connect
chat_with_alice: Chat, mocked_connect_with_explicit_no_document_selected_error: Connect
):
with patch(
"redbox_app.redbox_core.consumers.ChatConsumer.redbox.graph",
new=mocked_connect_with_explicit_no_document_selected_error,
):
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = alice
communicator.scope["user"] = chat_with_alice.user
connected, _ = await communicator.connect()
assert connected

chat = Chat(name="a chat", user=alice)

await chat.asave()

ai_settings = await ChatConsumer.get_ai_settings(chat)
ai_settings = await ChatConsumer.get_ai_settings(chat_with_alice)

assert ai_settings.chat_map_question_prompt == CHAT_MAP_QUESTION_PROMPT
assert ai_settings.chat_backend.name == chat.chat_backend_id
assert ai_settings.chat_backend.name == chat_with_alice.chat_backend.name
assert ai_settings.chat_backend.provider == chat_with_alice.chat_backend.provider
assert not hasattr(ai_settings, "label")

# Close
Expand Down

0 comments on commit c5659f9

Please sign in to comment.