|
| 1 | +""" |
| 2 | +Tests for the tasks page and task detail page. |
| 3 | +""" |
| 4 | + |
| 5 | +from django.urls import reverse |
| 6 | + |
| 7 | +from .base import CeleryPanelTestCase |
| 8 | + |
| 9 | + |
| 10 | +class TestTasksPage(CeleryPanelTestCase): |
| 11 | + """Test cases for the tasks list page.""" |
| 12 | + |
| 13 | + def test_tasks_page_loads(self): |
| 14 | + """Test that the tasks page loads successfully.""" |
| 15 | + response = self.client.get(reverse("dj_celery_panel:tasks")) |
| 16 | + |
| 17 | + self.assertEqual(response.status_code, 200) |
| 18 | + self.assertContains(response, "Task Execution History") |
| 19 | + |
| 20 | + def test_tasks_page_shows_search_bar(self): |
| 21 | + """Test that the tasks page has a search bar.""" |
| 22 | + response = self.client.get(reverse("dj_celery_panel:tasks")) |
| 23 | + |
| 24 | + self.assertEqual(response.status_code, 200) |
| 25 | + self.assertContains(response, 'name="search"') |
| 26 | + |
| 27 | + def test_tasks_page_with_search_query(self): |
| 28 | + """Test that the tasks page accepts search queries.""" |
| 29 | + response = self.client.get(reverse("dj_celery_panel:tasks"), {"search": "test_task"}) |
| 30 | + |
| 31 | + self.assertEqual(response.status_code, 200) |
| 32 | + self.assertContains(response, 'value="test_task"') |
| 33 | + |
| 34 | + def test_tasks_page_pagination(self): |
| 35 | + """Test that the tasks page handles pagination.""" |
| 36 | + response = self.client.get(reverse("dj_celery_panel:tasks"), {"page": "1"}) |
| 37 | + |
| 38 | + self.assertEqual(response.status_code, 200) |
| 39 | + |
| 40 | + def test_tasks_page_invalid_page_number(self): |
| 41 | + """Test that the tasks page handles invalid page numbers gracefully.""" |
| 42 | + response = self.client.get(reverse("dj_celery_panel:tasks"), {"page": "invalid"}) |
| 43 | + |
| 44 | + # Should default to page 1 |
| 45 | + self.assertEqual(response.status_code, 200) |
| 46 | + |
| 47 | + def test_tasks_requires_authentication(self): |
| 48 | + """Test that unauthenticated users cannot access the tasks page.""" |
| 49 | + from django.test import Client |
| 50 | + |
| 51 | + client = Client() |
| 52 | + response = client.get(reverse("dj_celery_panel:tasks")) |
| 53 | + |
| 54 | + # Should redirect to login |
| 55 | + self.assertEqual(response.status_code, 302) |
| 56 | + |
| 57 | + |
| 58 | +class TestTaskDetailPage(CeleryPanelTestCase): |
| 59 | + """Test cases for the task detail page.""" |
| 60 | + |
| 61 | + def test_task_detail_page_loads_with_valid_task_id(self): |
| 62 | + """Test that the task detail page loads with a task ID.""" |
| 63 | + # Using a dummy task ID - the page should load even if task doesn't exist |
| 64 | + response = self.client.get( |
| 65 | + reverse("dj_celery_panel:task_detail", kwargs={"task_id": "test-task-id"}) |
| 66 | + ) |
| 67 | + |
| 68 | + self.assertEqual(response.status_code, 200) |
| 69 | + |
| 70 | + def test_task_detail_shows_not_found_for_invalid_task(self): |
| 71 | + """Test that the task detail page shows error for invalid task.""" |
| 72 | + response = self.client.get( |
| 73 | + reverse("dj_celery_panel:task_detail", kwargs={"task_id": "nonexistent-task"}) |
| 74 | + ) |
| 75 | + |
| 76 | + self.assertEqual(response.status_code, 200) |
| 77 | + # Should show some indication that task wasn't found |
| 78 | + # Either in messages or in the page content |
| 79 | + |
| 80 | + def test_task_detail_requires_authentication(self): |
| 81 | + """Test that unauthenticated users cannot access task detail.""" |
| 82 | + from django.test import Client |
| 83 | + |
| 84 | + client = Client() |
| 85 | + response = client.get( |
| 86 | + reverse("dj_celery_panel:task_detail", kwargs={"task_id": "test-task-id"}) |
| 87 | + ) |
| 88 | + |
| 89 | + # Should redirect to login |
| 90 | + self.assertEqual(response.status_code, 302) |
0 commit comments