File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # pytest.ini tells Pytest how to use Django:
2+ [pytest]
3+ DJANGO_SETTINGS_MODULE = taskflow_api.settings
4+ python_files = tests.py test_*.py *_tests.py
5+ # adopts Speeds up tests by reusing the test DB & Measures coverage
6+ addopts = --reuse-db --cov =. --cov-report =term-missing
Original file line number Diff line number Diff line change 124124
125125CELERY_ACCEPT_CONTENT = ["json" ]
126126CELERY_TASK_SERIALIZER = "json"
127+
128+
129+ SWAGGER_USE_COMPAT_RENDERERS = False
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import pytest
2+ from rest_framework .test import APIClient
3+ from django .urls import reverse
4+ from datetime import date
5+
6+ @pytest .mark .django_db
7+ def test_create_task_api ():
8+ client = APIClient ()
9+ url = reverse ("task-list" ) # Adjust if you use a different route name
10+ response = client .post (url , {
11+ "title" : "API Task" ,
12+ "due_date" : date .today (),
13+ }, format = "json" )
14+ assert response .status_code == 201
15+ assert response .data ["title" ] == "API Task"
Original file line number Diff line number Diff line change 1+ import pytest
2+ from tasks .models import Task
3+ from tasks .tasks import log_task_action
4+ from datetime import date
5+ import os
6+
7+ @pytest .mark .django_db
8+ def test_log_task_action (tmp_path , settings ):
9+ # Ensure log directory exists
10+ os .makedirs ("logs" , exist_ok = True )
11+ task = Task .objects .create (title = "CeleryTest" , due_date = date .today ())
12+ log_task_action (task .id , "created" )
13+
14+ # Check the log file for correct entry
15+ with open ("logs/task_activity.log" ) as f :
16+ log_lines = f .readlines ()
17+ assert any ("CeleryTest" in line for line in log_lines )
Original file line number Diff line number Diff line change 1+ import pytest
2+ from tasks .models import Task
3+ from datetime import date
4+
5+ # @pytest.mark.django_db allows DB access in your test.
6+ @pytest .mark .django_db
7+ def test_task_creation ():
8+ task = Task .objects .create (title = "Testing" , due_date = date .today ())
9+ assert task .id is not None
10+ assert task .title == "Testing"
You can’t perform that action at this time.
0 commit comments