Skip to content

Commit

Permalink
Merge branch 'ansible:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
chr-stian authored Oct 23, 2023
2 parents 3dff112 + 014f75b commit 716332a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 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 or '', 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
Expand Up @@ -6,7 +6,6 @@
from unittest.mock import MagicMock, patch, ANY
from insights_analytics_collector import register
import insights_analytics_collector.package
import galaxy_ng.app.metrics_collection.common_data
from galaxy_ng.app.metrics_collection.automation_analytics.collector import Collector
from galaxy_ng.app.metrics_collection.automation_analytics.package import Package
from django.test import TestCase, override_settings
Expand Down Expand Up @@ -56,15 +55,19 @@ def csv_exception(since, **kwargs):
class TestAutomationAnalyticsCollector(TestCase):
def setUp(self):
super().setUp()
self.api_status = MagicMock()

self.api_status_patch = patch('galaxy_ng.app.metrics_collection.common_data.api_status')
self.api_status = self.api_status_patch.start()
self.api_status.return_value = {}
galaxy_ng.app.metrics_collection.common_data.api_status = self.api_status

self.logger = MagicMock()
self.log = MagicMock("log")
self.logger.log = self.log
self.logger.exception = MagicMock("exception")

def tearDown(self):
self.api_status_patch.stop()

def test_no_config_gather(self):
"""Config is missing, no data are collected"""
collector = Collector(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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")
mocked_api_status = MagicMock(name="api_status")
json_response.return_value = mocked_api_status
mock_response.json = json_response

response = galaxy_ng.app.metrics_collection.common_data.api_status()

self.assertEqual(response, mocked_api_status)

mock_request.assert_called_with("GET",
'https://example.com/api-test/xxx/pulp/api/v3/status/')
json_response.assert_called_once()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.core.management import call_command
from django.test import TestCase
import os
import galaxy_ng.app.metrics_collection.common_data

s3_details = {
"aws_access_key_id": "blah",
Expand All @@ -15,9 +14,12 @@
class TestMetricsCollectionLightspeedCommand(TestCase):
def setUp(self):
super().setUp()
self.api_status = MagicMock()
self.api_status_patch = patch('galaxy_ng.app.metrics_collection.common_data.api_status')
self.api_status = self.api_status_patch.start()
self.api_status.return_value = {}
galaxy_ng.app.metrics_collection.common_data.api_status = self.api_status

def tearDown(self):
self.api_status_patch.stop()

def test_command_output(self):
call_command("metrics-collection-lightspeed")
Expand Down
1 change: 1 addition & 0 deletions profiles/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM localhost/oci_env/pulp:base
RUN echo "fastestmirror=1" >> /etc/dnf/dnf.conf

COPY . /opt/galaxy_ng/
WORKDIR /opt/galaxy_ng/
Expand Down

0 comments on commit 716332a

Please sign in to comment.