Skip to content

Commit

Permalink
chore: add improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
luisfelipec95 committed Feb 28, 2025
1 parent d7dbe30 commit b7e1c98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Test suite for Aggregated Data Collector API.
"""
from unittest.mock import patch, MagicMock
from unittest.mock import patch
from django.test import TestCase
from eox_core.api.data.aggregated_collector.utils import execute_query


class UtilsTests(TestCase):
"""
Test suite for utility functions used in the Aggregated Data Collector API.
"""
@patch("eox_core.api.data.aggregated_collector.utils.connection.cursor")
def test_execute_query_success(self, mock_cursor):
"""
Expand Down
16 changes: 14 additions & 2 deletions eox_core/api/data/aggregated_collector/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from django.urls import reverse
from rest_framework.test import APIClient
from rest_framework import status
from eox_core.api.data.aggregated_collector.utils import execute_query
from eox_core.api.data.aggregated_collector.tasks import generate_report
from eox_core.api.data.aggregated_collector.v1.views import AggregatedCollectorView


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

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

mock_post.assert_called_once()

@patch("eox_core.api.data.aggregated_collector.v1.views.generate_report.delay")
def test_aggregated_collector_view(self, mock_task):
"""
Test AggregatedCollectorView to ensure it correctly triggers the report generation task.
"""
response = self.client.post(self.url, HTTP_AUTHORIZATION=f"Bearer {settings.EOX_CORE_AGGREGATED_COLLECTOR_AUTH_TOKEN}")

self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)

mock_task.assert_called_once()

0 comments on commit b7e1c98

Please sign in to comment.