Skip to content

Commit 2b266b0

Browse files
authored
Fix more unit tests by direct mocking of settings. (#2404)
Fix more unit test by direct mocking of settings. No-Issue Signed-off-by: James Tanner <tanner.jc@gmail.com>
1 parent 4ef1111 commit 2b266b0

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

galaxy_ng/tests/unit/api/test_view_only_access.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import unittest
2-
31
from django.urls.base import reverse
42
from django.test.utils import override_settings
53

64
from rest_framework.test import APIClient
5+
from unittest.mock import patch
76

87
from pulp_ansible.app.models import (
98
AnsibleDistribution,
@@ -17,6 +16,18 @@
1716
from .base import BaseTestCase
1817

1918

19+
class MockSettings:
20+
"""A dictionary like shim that serves as a dynaconf provided settings mock."""
21+
def __init__(self, kwargs):
22+
self.kwargs = kwargs
23+
# every setting should be evaluatable as a property ...
24+
for k, v in self.kwargs.items():
25+
setattr(self, k, v)
26+
27+
def get(self, key, default=None):
28+
return self.kwargs.get(key, default)
29+
30+
2031
def _create_repo(name, **kwargs):
2132
repo = AnsibleRepository.objects.create(name=name, **kwargs)
2233
AnsibleDistribution.objects.create(
@@ -80,11 +91,14 @@ def setUp(self):
8091
}
8192
)
8293

83-
@unittest.skip("FIXME - broken by dab 2024.12.13")
8494
def test_unauthenticated_access_to_collections(self):
8595
response = self.client.get(self.collections_detail_url)
8696
self.assertEqual(response.data['errors'][0]['status'], '401')
87-
with self.settings(GALAXY_ENABLE_UNAUTHENTICATED_COLLECTION_ACCESS=True):
97+
kwargs = {
98+
'GALAXY_DEPLOYMENT_MODE': 'standalone',
99+
'GALAXY_ENABLE_UNAUTHENTICATED_COLLECTION_ACCESS': True
100+
}
101+
with patch('galaxy_ng.app.access_control.access_policy.settings', MockSettings(kwargs)):
88102
response = self.client.get(self.collections_detail_url)
89103
self.assertEqual(response.data['name'], self.collection.name)
90104
self.assertEqual(response.data['namespace'], self.collection.namespace.name)
@@ -93,10 +107,13 @@ def test_unauthenticated_access_to_collections(self):
93107
response.data['highest_version']['version'], '1.1.2'
94108
)
95109

96-
@unittest.skip("FIXME - broken by dab 2024.12.13")
97110
def test_unauthenticated_access_to_namespace(self):
98111
response = self.client.get(self.ns_detail_url)
99112
self.assertEqual(response.data['errors'][0]['status'], '401')
100-
with self.settings(GALAXY_ENABLE_UNAUTHENTICATED_COLLECTION_ACCESS=True):
113+
kwargs = {
114+
'GALAXY_DEPLOYMENT_MODE': 'standalone',
115+
'GALAXY_ENABLE_UNAUTHENTICATED_COLLECTION_ACCESS': True
116+
}
117+
with patch('galaxy_ng.app.access_control.access_policy.settings', MockSettings(kwargs)):
101118
response = self.client.get(self.ns_detail_url)
102119
self.assertEqual(response.data['name'], self.namespace.name)

0 commit comments

Comments
 (0)