1
- import unittest
2
-
3
1
from django .urls .base import reverse
4
2
from django .test .utils import override_settings
5
3
6
4
from rest_framework .test import APIClient
5
+ from unittest .mock import patch
7
6
8
7
from pulp_ansible .app .models import (
9
8
AnsibleDistribution ,
17
16
from .base import BaseTestCase
18
17
19
18
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
+
20
31
def _create_repo (name , ** kwargs ):
21
32
repo = AnsibleRepository .objects .create (name = name , ** kwargs )
22
33
AnsibleDistribution .objects .create (
@@ -80,11 +91,14 @@ def setUp(self):
80
91
}
81
92
)
82
93
83
- @unittest .skip ("FIXME - broken by dab 2024.12.13" )
84
94
def test_unauthenticated_access_to_collections (self ):
85
95
response = self .client .get (self .collections_detail_url )
86
96
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 )):
88
102
response = self .client .get (self .collections_detail_url )
89
103
self .assertEqual (response .data ['name' ], self .collection .name )
90
104
self .assertEqual (response .data ['namespace' ], self .collection .namespace .name )
@@ -93,10 +107,13 @@ def test_unauthenticated_access_to_collections(self):
93
107
response .data ['highest_version' ]['version' ], '1.1.2'
94
108
)
95
109
96
- @unittest .skip ("FIXME - broken by dab 2024.12.13" )
97
110
def test_unauthenticated_access_to_namespace (self ):
98
111
response = self .client .get (self .ns_detail_url )
99
112
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 )):
101
118
response = self .client .get (self .ns_detail_url )
102
119
self .assertEqual (response .data ['name' ], self .namespace .name )
0 commit comments