Skip to content

Commit b7e1c98

Browse files
committed
chore: add improvements
1 parent d7dbe30 commit b7e1c98

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

eox_core/api/data/aggregated_collector/v1/tests/test_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"""
22
Test suite for Aggregated Data Collector API.
33
"""
4-
from unittest.mock import patch, MagicMock
4+
from unittest.mock import patch
55
from django.test import TestCase
66
from eox_core.api.data.aggregated_collector.utils import execute_query
77

88

99
class UtilsTests(TestCase):
10+
"""
11+
Test suite for utility functions used in the Aggregated Data Collector API.
12+
"""
1013
@patch("eox_core.api.data.aggregated_collector.utils.connection.cursor")
1114
def test_execute_query_success(self, mock_cursor):
1215
"""

eox_core/api/data/aggregated_collector/v1/tests/test_views.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
from django.urls import reverse
88
from rest_framework.test import APIClient
99
from rest_framework import status
10+
from eox_core.api.data.aggregated_collector.utils import execute_query
1011
from eox_core.api.data.aggregated_collector.tasks import generate_report
1112
from eox_core.api.data.aggregated_collector.v1.views import AggregatedCollectorView
1213

13-
1414
class AggregatedCollectorViewTests(TestCase):
1515
def setUp(self):
1616
self.client = APIClient()
17+
self.url = reverse("eox-data-api-collector-v1:aggregated_collector")
1718
settings.AGGREGATED_DATA_COLLECTOR_API_ENABLED = True
1819
settings.EOX_CORE_AGGREGATED_COLLECTOR_TARGET_URL = "http://mock-api.com"
1920
settings.EOX_CORE_AGGREGATED_COLLECTOR_TARGET_TOKEN_URL = "http://mock-token.com"
@@ -27,6 +28,17 @@ def test_generate_report(self, mock_post, mock_execute):
2728
"""
2829
mock_execute.return_value = [{"id": 1, "data": "sample"}]
2930

30-
generate_report("http://mock-api.com", "http://mock-token.com", "localhost")
31+
generate_report(self, "http://mock-api.com", "http://mock-token.com", "localhost")
3132

3233
mock_post.assert_called_once()
34+
35+
@patch("eox_core.api.data.aggregated_collector.v1.views.generate_report.delay")
36+
def test_aggregated_collector_view(self, mock_task):
37+
"""
38+
Test AggregatedCollectorView to ensure it correctly triggers the report generation task.
39+
"""
40+
response = self.client.post(self.url, HTTP_AUTHORIZATION=f"Bearer {settings.EOX_CORE_AGGREGATED_COLLECTOR_AUTH_TOKEN}")
41+
42+
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
43+
44+
mock_task.assert_called_once()

0 commit comments

Comments
 (0)