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 18, 2023
1 parent b10dd99 commit 9d903f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
10 changes: 8 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,14 @@


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 or '', status_path)
url = urljoin(settings.ANSIBLE_API_HOSTNAME, path)
text = (f"{settings.ANSIBLE_API_HOSTNAME} | "
f"{settings.GALAXY_API_PATH_PREFIX} | {status_path} | url: {url}")
logger.error(text)
print(text)
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,31 @@
import galaxy_ng.app.metrics_collection.common_data
from django.test import TestCase, override_settings
from unittest.mock import MagicMock, patch
from django.conf import settings
from urllib.parse import urljoin
import os


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

path = os.path.join(settings.GALAXY_API_PATH_PREFIX or '', 'pulp/api/v3/status/')
url = urljoin(settings.ANSIBLE_API_HOSTNAME, path)
assert path == '/api-test/xxx/pulp/api/v3/status/'
assert url == 'https://example.com/api-test/xxx/pulp/api/v3/status/'

galaxy_ng.app.metrics_collection.common_data.api_status()

json_response.assert_called_once()
# 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 9d903f2

Please sign in to comment.