Skip to content

Commit

Permalink
Updates threads tests to use pytest standards
Browse files Browse the repository at this point in the history
  • Loading branch information
amandasavluchinske committed Jun 17, 2024
1 parent 95fe7ee commit 4e68248
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from http import HTTPStatus

from django.contrib.auth.models import User

import pytest
from model_bakery import baker

from django_ai_assistant.exceptions import AIAssistantNotDefinedError
from django_ai_assistant.helpers.assistants import AIAssistant, register_assistant
from django_ai_assistant.langchain.tools import BaseModel, Field, method_tool
from django_ai_assistant.models import Thread


# Set up
Expand Down Expand Up @@ -71,16 +75,26 @@ def test_does_not_return_assistant_if_unauthorized():
# Threads Views


# @pytest.mark.django_db(transaction=True)
# def test_list_threads_without_results(client):
# response = client.get("/threads/")
@pytest.fixture
def authenticated_client(client):
User.objects.create_user(username="testuser", password="password")
client.login(username="testuser", password="password")
return client


@pytest.mark.django_db(transaction=True)
def test_list_threads_without_results(authenticated_client):
response = authenticated_client.get("/threads/")

assert response.status_code == HTTPStatus.OK
assert response.json() == []

# assert response.status_code == HTTPStatus.OK
# assert response.json() == []

# @pytest.mark.django_db(transaction=True)
# def test_list_threads_with_results(client):
# response = client.get("/threads/")
@pytest.mark.django_db(transaction=True)
def test_list_threads_with_results(authenticated_client):
user = User.objects.first()
thread = baker.make(Thread, created_by=user)
response = authenticated_client.get("/threads/")

# assert response.status_code == HTTPStatus.OK
# assert response.json()[0].get("id") == thread.id
assert response.status_code == HTTPStatus.OK
assert response.json()[0].get("id") == thread.id

0 comments on commit 4e68248

Please sign in to comment.