From 2255a1eb3947221e0e348a3121d7e5587dfde7be Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Tue, 17 Oct 2023 11:06:41 +0200 Subject: [PATCH] Metrics Collection: Added GALAXY_API_PATH_PREFIX to API call Jira AA-1892 No-Issue Signed-off-by: Martin Slemr --- .../app/metrics_collection/common_data.py | 6 ++++-- .../automation_analytics/test_data.py | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 galaxy_ng/tests/unit/app/management/commands/analytics/automation_analytics/test_data.py diff --git a/galaxy_ng/app/metrics_collection/common_data.py b/galaxy_ng/app/metrics_collection/common_data.py index 291f08ba7c..600795f027 100644 --- a/galaxy_ng/app/metrics_collection/common_data.py +++ b/galaxy_ng/app/metrics_collection/common_data.py @@ -1,3 +1,4 @@ +import os import requests import logging from urllib.parse import urljoin @@ -10,9 +11,10 @@ def api_status(): - status_path = '/pulp/api/v3/status/' + status_path = 'pulp/api/v3/status/' try: - url = urljoin(settings.ANSIBLE_API_HOSTNAME, status_path) + path = os.path.join(settings.GALAXY_API_PATH_PREFIX, status_path) + url = urljoin(settings.ANSIBLE_API_HOSTNAME, path) response = requests.request("GET", url) if response.status_code == 200: return response.json() diff --git a/galaxy_ng/tests/unit/app/management/commands/analytics/automation_analytics/test_data.py b/galaxy_ng/tests/unit/app/management/commands/analytics/automation_analytics/test_data.py new file mode 100644 index 0000000000..cf6bacebb4 --- /dev/null +++ b/galaxy_ng/tests/unit/app/management/commands/analytics/automation_analytics/test_data.py @@ -0,0 +1,21 @@ +import galaxy_ng.app.metrics_collection.common_data +from django.test import TestCase, override_settings +from unittest.mock import MagicMock, patch + + +class TestAutomationAnalyticsData(TestCase): + @override_settings(ANSIBLE_API_HOSTNAME='https://example.com') + @override_settings(GALAXY_API_PATH_PREFIX='/api-test/xxx') + @patch('galaxy_ng.app.metrics_collection.common_data.requests.request') + def test_api_status_request(self, mock_request): + mock_response = MagicMock(name="mock_response") + mock_response.status_code = 200 + mock_request.return_value = mock_response + + json_response = MagicMock(name="json") + mock_response.json = json_response + + galaxy_ng.app.metrics_collection.common_data.api_status() + + mock_request.assert_called_with("GET", 'https://example.com/api-test/xxx/pulp/api/v3/status/') + json_response.assert_called_once()