Skip to content

Commit

Permalink
Adds test for openapi json
Browse files Browse the repository at this point in the history
  • Loading branch information
amandasavluchinske committed Jun 19, 2024
1 parent 47068ce commit e0ce5b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
"""
Use this manage.py for generate the OpenAPI schema. NOT for examples.
Use this manage.py to generate the OpenAPI schema. NOT for examples.
For tests, use pytest directly.
"""
import os
Expand Down
17 changes: 15 additions & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from model_bakery import baker

from django_ai_assistant import package_name, version
from django_ai_assistant.exceptions import AIAssistantNotDefinedError, AIUserNotAllowedError
from django_ai_assistant.helpers import use_cases
from django_ai_assistant.helpers.assistants import AIAssistant, register_assistant
Expand Down Expand Up @@ -48,6 +49,18 @@ def authenticated_client(client):
return client


# OPENAPI JSON View


@pytest.mark.django_db()
def test_generates_json_with_correct_version(authenticated_client):
response = authenticated_client.get("/openapi.json")

assert response.status_code == HTTPStatus.OK
assert response.json()["info"]["version"] == version
assert response.json()["info"]["title"] == package_name


# Assistant Views


Expand Down Expand Up @@ -131,7 +144,7 @@ def test_gets_specific_thread(authenticated_client):
)

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


def test_does_not_list_threads_if_unauthorized():
Expand All @@ -151,7 +164,7 @@ def test_create_thread(authenticated_client):
thread = Thread.objects.first()

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


def test_cannot_create_thread_if_unauthorized():
Expand Down

0 comments on commit e0ce5b1

Please sign in to comment.