From df723f05fd5932a826ed3dc64f71efb099c60260 Mon Sep 17 00:00:00 2001 From: amandasavluchinske Date: Mon, 17 Jun 2024 18:06:19 +0100 Subject: [PATCH 01/11] Adds tests for list threads and also a helper to create threads --- tests/helpers.py | 19 +++++++++++++++++++ tests/test_views.py | 24 +++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/helpers.py diff --git a/tests/helpers.py b/tests/helpers.py new file mode 100644 index 0000000..57d2099 --- /dev/null +++ b/tests/helpers.py @@ -0,0 +1,19 @@ +from django.contrib.auth.models import User + +from django_ai_assistant.models import Message, Thread + + +def create_thread( + name: str | None = None, user: User | None = None, message: str | None = None +) -> Thread: + name = name or "Test Thread" + user = user or User.objects.create_user(username="test_user") + message = message or "Test Message" + + thread = Thread.objects.create(name=name, created_by=user) + + Message.objects.create(message={"content": message}, thread=thread) + + thread.refresh_from_db() + + return thread diff --git a/tests/test_views.py b/tests/test_views.py index 00e72e2..9396bda 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,5 +1,6 @@ from http import HTTPStatus +from django.contrib.auth.models import User from django.test import Client, TestCase import pytest @@ -7,6 +8,7 @@ from django_ai_assistant.exceptions import AIAssistantNotDefinedError from django_ai_assistant.helpers.assistants import AIAssistant, register_assistant from django_ai_assistant.tools import BaseModel, Field, method_tool +from tests.helpers import create_thread # Set up @@ -73,4 +75,24 @@ def test_does_not_return_assistant_if_unauthorized(self): # Threads Views -# Up next + +class ThreadsListViewsTests(TestCase): + def setUp(self): + super().setUp() + self.user = User.objects.create_user(username="testuser", password="password") + self.client = Client() + self.client.login(username="testuser", password="password") + + def test_list_threads_without_results(self): + response = self.client.get("/threads/") + + assert response.status_code == HTTPStatus.OK + assert response.json() == [] + + def test_list_threads_with_results(self): + thread = create_thread(user=self.user) + + response = self.client.get("/threads/") + + assert response.status_code == HTTPStatus.OK + assert response.json()[0].get("id") == thread.id From 7e65ccd33f36fc958fc9b79c6ce975a9a5ce0e67 Mon Sep 17 00:00:00 2001 From: amandasavluchinske Date: Mon, 17 Jun 2024 18:19:35 +0100 Subject: [PATCH 02/11] Adds baker --- poetry.lock | 23 +++++++++++++++++++++-- pyproject.toml | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 8c30480..aef4010 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "aiohttp" @@ -1259,6 +1259,24 @@ files = [ [package.dependencies] traitlets = "*" +[[package]] +name = "model-bakery" +version = "1.18.1" +description = "Smart object creation facility for Django." +optional = false +python-versions = ">=3.8" +files = [ + {file = "model_bakery-1.18.1-py3-none-any.whl", hash = "sha256:49d672d41e8c377854d42e50df61ff5ee56b91a3b2ff24372344c05c29166eb2"}, + {file = "model_bakery-1.18.1.tar.gz", hash = "sha256:8cc2b7b0879a2fc400808225a4c1f830b322b181007577b588f4d4aac5d4cb4b"}, +] + +[package.dependencies] +django = ">=4.2" + +[package.extras] +docs = ["myst-parser", "sphinx", "sphinx-rtd-theme"] +test = ["black", "coverage", "mypy", "pillow", "pytest", "pytest-django", "ruff"] + [[package]] name = "multidict" version = "6.0.5" @@ -1869,6 +1887,7 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -2705,4 +2724,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.12,<3.13" -content-hash = "ccd01a998eb526dd7a4b6b4a401f34462d16a6bf5eb703c10b5b0a7175e74ef7" +content-hash = "2bc5e1b1fe25c2765af0cd3a3b22a560ad9db2f8694771dd10ffab07669673f0" diff --git a/pyproject.toml b/pyproject.toml index 32485db..9425735 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ ipython = "^8.24.0" pytest-asyncio = "^0.23.7" pytest-recording = "^0.13.1" coveralls = "^4.0.1" +model-bakery = "^1.18.1" [tool.poetry.group.example.dependencies] django-webpack-loader = "^3.1.0" From 4e6824886715a869ddb560614bae68bbbbef9c31 Mon Sep 17 00:00:00 2001 From: amandasavluchinske Date: Mon, 17 Jun 2024 18:58:25 +0100 Subject: [PATCH 03/11] Updates threads tests to use pytest standards --- tests/test_views.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/tests/test_views.py b/tests/test_views.py index 4402049..6746e8b 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -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 @@ -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 From b06a23fe231ae31b80cb2fdb8afa2f2e3ab882ed Mon Sep 17 00:00:00 2001 From: amandasavluchinske Date: Mon, 17 Jun 2024 19:00:46 +0100 Subject: [PATCH 04/11] Removes helpers file --- tests/helpers.py | 19 ------------------- tests/test_views.py | 14 +++++++------- 2 files changed, 7 insertions(+), 26 deletions(-) delete mode 100644 tests/helpers.py diff --git a/tests/helpers.py b/tests/helpers.py deleted file mode 100644 index 57d2099..0000000 --- a/tests/helpers.py +++ /dev/null @@ -1,19 +0,0 @@ -from django.contrib.auth.models import User - -from django_ai_assistant.models import Message, Thread - - -def create_thread( - name: str | None = None, user: User | None = None, message: str | None = None -) -> Thread: - name = name or "Test Thread" - user = user or User.objects.create_user(username="test_user") - message = message or "Test Message" - - thread = Thread.objects.create(name=name, created_by=user) - - Message.objects.create(message={"content": message}, thread=thread) - - thread.refresh_from_db() - - return thread diff --git a/tests/test_views.py b/tests/test_views.py index 6746e8b..c855a95 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -40,6 +40,13 @@ def fetch_forecast_temperature(self, location: str, dt_str: str) -> str: return "35 degrees Celsius" +@pytest.fixture +def authenticated_client(client): + User.objects.create_user(username="testuser", password="password") + client.login(username="testuser", password="password") + return client + + # Assistant Views @@ -75,13 +82,6 @@ def test_does_not_return_assistant_if_unauthorized(): # Threads Views -@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/") From 8721e1dd62729fcd3c785eb31108081c6c4b314d Mon Sep 17 00:00:00 2001 From: amandasavluchinske Date: Mon, 17 Jun 2024 20:08:08 +0100 Subject: [PATCH 05/11] Adds tests for threads --- tests/test_views.py | 98 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/tests/test_views.py b/tests/test_views.py index c855a95..7a58763 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,3 +1,4 @@ +import json from http import HTTPStatus from django.contrib.auth.models import User @@ -81,6 +82,8 @@ def test_does_not_return_assistant_if_unauthorized(): # Threads Views +# GET + @pytest.mark.django_db(transaction=True) def test_list_threads_without_results(authenticated_client): @@ -98,3 +101,98 @@ def test_list_threads_with_results(authenticated_client): assert response.status_code == HTTPStatus.OK assert response.json()[0].get("id") == thread.id + + +@pytest.mark.django_db(transaction=True) +def test_does_not_list_other_users_threads(authenticated_client): + baker.make(Thread) + response = authenticated_client.get("/threads/") + + assert response.status_code == HTTPStatus.OK + assert response.json() == [] + + +def test_does_not_list_threads_if_unauthorized(): + # TODO: Implement this test once permissions are in place + pass + + +# POST + + +@pytest.mark.django_db(transaction=True) +def test_create_thread(authenticated_client): + response = authenticated_client.post( + "/threads/", data=json.dumps({}), content_type="application/json" + ) + + thread = Thread.objects.first() + + assert response.status_code == HTTPStatus.OK + assert response.json().get("id") == thread.id + + +def test_cannot_create_thread_if_unauthorized(): + # TODO: Implement this test once permissions are in place + pass + + +# PATCH + + +@pytest.mark.django_db(transaction=True) +def test_update_thread(authenticated_client): + thread = baker.make(Thread, created_by=User.objects.first()) + response = authenticated_client.patch( + f"/threads/{thread.id}/", + data=json.dumps({"name": "New name"}), + content_type="application/json", + ) + + assert response.status_code == HTTPStatus.OK + + +@pytest.mark.django_db(transaction=True) +def test_cannot_update_other_users_threads(authenticated_client): + thread = baker.make(Thread) + response = authenticated_client.patch( + f"/threads/{thread.id}/", + data=json.dumps({"name": "New name"}), + content_type="application/json", + ) + + assert response.status_code == HTTPStatus.FORBIDDEN + + +def test_cannot_update_thread_if_unauthorized(): + # TODO: Implement this test once permissions are in place + pass + + +# DELETE + + +@pytest.mark.django_db(transaction=True) +def test_delete_thread(authenticated_client): + thread = baker.make(Thread, created_by=User.objects.first()) + response = authenticated_client.delete(f"/threads/{thread.id}/") + + assert response.status_code == HTTPStatus.NO_CONTENT + + +@pytest.mark.django_db(transaction=True) +def test_cannot_delete_other_users_threads(authenticated_client): + thread = baker.make(Thread) + response = authenticated_client.delete(f"/threads/{thread.id}/") + + assert response.status_code == HTTPStatus.FORBIDDEN + + +def test_cannot_delete_thread_if_unauthorized(): + # TODO: Implement this test once permissions are in place + pass + + +# Threads Messages Views (will need VCR) + +# TBD From 3e2584006b920bf3b1a77cbbc4384d08396e7f47 Mon Sep 17 00:00:00 2001 From: amandasavluchinske Date: Tue, 18 Jun 2024 15:19:28 +0100 Subject: [PATCH 06/11] Removes useless json.dumps --- tests/test_views.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/test_views.py b/tests/test_views.py index 7a58763..5879341 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,4 +1,3 @@ -import json from http import HTTPStatus from django.contrib.auth.models import User @@ -122,9 +121,7 @@ def test_does_not_list_threads_if_unauthorized(): @pytest.mark.django_db(transaction=True) def test_create_thread(authenticated_client): - response = authenticated_client.post( - "/threads/", data=json.dumps({}), content_type="application/json" - ) + response = authenticated_client.post("/threads/", data={}, content_type="application/json") thread = Thread.objects.first() @@ -145,7 +142,7 @@ def test_update_thread(authenticated_client): thread = baker.make(Thread, created_by=User.objects.first()) response = authenticated_client.patch( f"/threads/{thread.id}/", - data=json.dumps({"name": "New name"}), + data={"name": "New name"}, content_type="application/json", ) @@ -157,7 +154,7 @@ def test_cannot_update_other_users_threads(authenticated_client): thread = baker.make(Thread) response = authenticated_client.patch( f"/threads/{thread.id}/", - data=json.dumps({"name": "New name"}), + data={"name": "New name"}, content_type="application/json", ) From edfe7d090670442a2dad1c220344ce69e97c73b2 Mon Sep 17 00:00:00 2001 From: amandasavluchinske Date: Tue, 18 Jun 2024 15:29:38 +0100 Subject: [PATCH 07/11] Favors reverse as opposed to hardcoded URLs --- tests/test_views.py | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/test_views.py b/tests/test_views.py index 5879341..d7ac3f8 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,6 +1,7 @@ from http import HTTPStatus from django.contrib.auth.models import User +from django.urls import reverse import pytest from model_bakery import baker @@ -51,7 +52,7 @@ def authenticated_client(client): def test_list_assistants_with_results(client): - response = client.get("/assistants/") + response = client.get(reverse("django_ai_assistant:assistants_list")) assert response.status_code == HTTPStatus.OK assert response.json() == [{"id": "temperature_assistant", "name": "Temperature Assistant"}] @@ -63,7 +64,11 @@ def test_does_not_list_assistants_if_unauthorized(): def test_get_assistant_that_exists(client): - response = client.get("/assistants/temperature_assistant/") + response = client.get( + reverse( + "django_ai_assistant:assistant_detail", kwargs={"assistant_id": "temperature_assistant"} + ) + ) assert response.status_code == HTTPStatus.OK assert response.json() == {"id": "temperature_assistant", "name": "Temperature Assistant"} @@ -71,7 +76,11 @@ def test_get_assistant_that_exists(client): def test_get_assistant_that_does_not_exist(client): with pytest.raises(AIAssistantNotDefinedError): - client.get("/assistants/fake_assistant/") + client.get( + reverse( + "django_ai_assistant:assistant_detail", kwargs={"assistant_id": "fake_assistant"} + ) + ) def test_does_not_return_assistant_if_unauthorized(): @@ -86,7 +95,7 @@ def test_does_not_return_assistant_if_unauthorized(): @pytest.mark.django_db(transaction=True) def test_list_threads_without_results(authenticated_client): - response = authenticated_client.get("/threads/") + response = authenticated_client.get(reverse("django_ai_assistant:threads_list_create")) assert response.status_code == HTTPStatus.OK assert response.json() == [] @@ -96,7 +105,7 @@ def test_list_threads_without_results(authenticated_client): def test_list_threads_with_results(authenticated_client): user = User.objects.first() thread = baker.make(Thread, created_by=user) - response = authenticated_client.get("/threads/") + response = authenticated_client.get(reverse("django_ai_assistant:threads_list_create")) assert response.status_code == HTTPStatus.OK assert response.json()[0].get("id") == thread.id @@ -105,7 +114,7 @@ def test_list_threads_with_results(authenticated_client): @pytest.mark.django_db(transaction=True) def test_does_not_list_other_users_threads(authenticated_client): baker.make(Thread) - response = authenticated_client.get("/threads/") + response = authenticated_client.get(reverse("django_ai_assistant:threads_list_create")) assert response.status_code == HTTPStatus.OK assert response.json() == [] @@ -121,7 +130,9 @@ def test_does_not_list_threads_if_unauthorized(): @pytest.mark.django_db(transaction=True) def test_create_thread(authenticated_client): - response = authenticated_client.post("/threads/", data={}, content_type="application/json") + response = authenticated_client.post( + reverse("django_ai_assistant:threads_list_create"), data={}, content_type="application/json" + ) thread = Thread.objects.first() @@ -141,7 +152,7 @@ def test_cannot_create_thread_if_unauthorized(): def test_update_thread(authenticated_client): thread = baker.make(Thread, created_by=User.objects.first()) response = authenticated_client.patch( - f"/threads/{thread.id}/", + reverse("django_ai_assistant:thread_detail_update_delete", kwargs={"thread_id": thread.id}), data={"name": "New name"}, content_type="application/json", ) @@ -153,7 +164,7 @@ def test_update_thread(authenticated_client): def test_cannot_update_other_users_threads(authenticated_client): thread = baker.make(Thread) response = authenticated_client.patch( - f"/threads/{thread.id}/", + reverse("django_ai_assistant:thread_detail_update_delete", kwargs={"thread_id": thread.id}), data={"name": "New name"}, content_type="application/json", ) @@ -172,7 +183,9 @@ def test_cannot_update_thread_if_unauthorized(): @pytest.mark.django_db(transaction=True) def test_delete_thread(authenticated_client): thread = baker.make(Thread, created_by=User.objects.first()) - response = authenticated_client.delete(f"/threads/{thread.id}/") + response = authenticated_client.delete( + reverse("django_ai_assistant:thread_detail_update_delete", kwargs={"thread_id": thread.id}) + ) assert response.status_code == HTTPStatus.NO_CONTENT @@ -180,7 +193,9 @@ def test_delete_thread(authenticated_client): @pytest.mark.django_db(transaction=True) def test_cannot_delete_other_users_threads(authenticated_client): thread = baker.make(Thread) - response = authenticated_client.delete(f"/threads/{thread.id}/") + response = authenticated_client.delete( + reverse("django_ai_assistant:thread_detail_update_delete", kwargs={"thread_id": thread.id}) + ) assert response.status_code == HTTPStatus.FORBIDDEN From 1fdee9266d06777602c78c5707b2b0afcb6ed4cf Mon Sep 17 00:00:00 2001 From: amandasavluchinske Date: Tue, 18 Jun 2024 15:33:41 +0100 Subject: [PATCH 08/11] Adds test for getting a specific thread and improves list thread test --- tests/test_views.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_views.py b/tests/test_views.py index d7ac3f8..60a667e 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -104,11 +104,12 @@ def test_list_threads_without_results(authenticated_client): @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) + baker.make(Thread, created_by=user) + baker.make(Thread, created_by=user) response = authenticated_client.get(reverse("django_ai_assistant:threads_list_create")) assert response.status_code == HTTPStatus.OK - assert response.json()[0].get("id") == thread.id + assert len(response.json()) == 2 @pytest.mark.django_db(transaction=True) @@ -120,6 +121,17 @@ def test_does_not_list_other_users_threads(authenticated_client): assert response.json() == [] +@pytest.mark.django_db(transaction=True) +def test_gets_specific_thread(authenticated_client): + thread = baker.make(Thread, created_by=User.objects.first()) + response = authenticated_client.get( + reverse("django_ai_assistant:thread_detail_update_delete", kwargs={"thread_id": thread.id}) + ) + + assert response.status_code == HTTPStatus.OK + assert response.json().get("id") == thread.id + + def test_does_not_list_threads_if_unauthorized(): # TODO: Implement this test once permissions are in place pass From 2d2e0a1f03a99bb9f54d0c9fcac888f7b30d18a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Juvenal?= Date: Tue, 18 Jun 2024 18:10:12 -0300 Subject: [PATCH 09/11] Update tests/test_views.py Co-authored-by: Pamella Bezerra --- tests/test_views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_views.py b/tests/test_views.py index 60a667e..c2c4498 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -104,8 +104,7 @@ def test_list_threads_without_results(authenticated_client): @pytest.mark.django_db(transaction=True) def test_list_threads_with_results(authenticated_client): user = User.objects.first() - baker.make(Thread, created_by=user) - baker.make(Thread, created_by=user) + baker.make(Thread, created_by=user, _quantity=2) response = authenticated_client.get(reverse("django_ai_assistant:threads_list_create")) assert response.status_code == HTTPStatus.OK From 0bc09ff4d8cf5c442d39e6f2fe505b5f39a7a1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Juvenal?= Date: Tue, 18 Jun 2024 18:12:30 -0300 Subject: [PATCH 10/11] Drop unused description field --- tests/test_views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_views.py b/tests/test_views.py index c2c4498..aff1798 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -19,7 +19,6 @@ class TemperatureAssistant(AIAssistant): id = "temperature_assistant" # noqa: A003 name = "Temperature Assistant" - description = "A temperature assistant that provides temperature information." instructions = "You are a temperature bot." model = "gpt-4o" From eb43ab55bb9e28aa9d1bde7707cbf29c0091c559 Mon Sep 17 00:00:00 2001 From: amandasavluchinske Date: Wed, 19 Jun 2024 13:29:10 +0100 Subject: [PATCH 11/11] Adds additional assertions to update and delete tests --- tests/test_views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_views.py b/tests/test_views.py index aff1798..701739e 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -168,6 +168,7 @@ def test_update_thread(authenticated_client): ) assert response.status_code == HTTPStatus.OK + assert Thread.objects.filter(id=thread.id).first().name == "New name" @pytest.mark.django_db(transaction=True) @@ -180,6 +181,7 @@ def test_cannot_update_other_users_threads(authenticated_client): ) assert response.status_code == HTTPStatus.FORBIDDEN + assert Thread.objects.filter(id=thread.id).first().name != "New name" def test_cannot_update_thread_if_unauthorized(): @@ -198,6 +200,7 @@ def test_delete_thread(authenticated_client): ) assert response.status_code == HTTPStatus.NO_CONTENT + assert not Thread.objects.filter(id=thread.id).exists() @pytest.mark.django_db(transaction=True) @@ -208,6 +211,7 @@ def test_cannot_delete_other_users_threads(authenticated_client): ) assert response.status_code == HTTPStatus.FORBIDDEN + assert Thread.objects.filter(id=thread.id).exists() def test_cannot_delete_thread_if_unauthorized():