Skip to content

Commit

Permalink
Metrics Collection: Added GALAXY_API_PATH_PREFIX to API call
Browse files Browse the repository at this point in the history
Jira AA-1892

No-Issue

Signed-off-by: Martin Slemr <[email protected]>
  • Loading branch information
slemrmartin committed Oct 17, 2023
1 parent b10dd99 commit 2255a1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions galaxy_ng/app/metrics_collection/common_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import requests
import logging
from urllib.parse import urljoin
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 2255a1e

Please sign in to comment.