Merge "Fix system-scope test"

This commit is contained in:
Zuul 2024-12-18 09:46:30 +00:00 committed by Gerrit Code Review
commit b460315fb7
2 changed files with 42 additions and 8 deletions

View File

@ -255,6 +255,30 @@ def generate_test_data(service_providers=False, endpoint='localhost'):
body=domain_token_dict
)
system_token_dict = {
'token': {
'methods': ['password'],
'expires_at': expiration,
'system': {
'all': True,
},
'user': {
'id': user_dict['id'],
'name': user_dict['name'],
'domain': {
'id': domain_dict['id'],
'name': domain_dict['name']
}
},
'roles': [role_dict],
'catalog': [keystone_service, nova_service]
}
}
test_data.system_scoped_access_info = access.create(
resp=auth_response,
body=system_token_dict
)
unscoped_token_dict = {
'token': {
'methods': ['password'],

View File

@ -1390,12 +1390,18 @@ class OpenStackAuthTests(test.TestCase):
next=None):
projects = []
user = self.data.user
scoped = self.data.unscoped_access_info
form_data = self.get_form_data(user)
mock_get_access.return_value = self.data.unscoped_access_info
mock_get_access_token.return_value = scoped
mock_get_access.side_effect = [
self.data.unscoped_access_info,
]
mock_get_access_token.side_effect = [
# satisfy call to plugin.get_domain_scoped_auth
self.data.domain_scoped_access_info,
# satisfy call to switch_system_scope
self.data.system_scoped_access_info,
]
mock_project_list.return_value = projects
url = reverse('login')
@ -1406,6 +1412,11 @@ class OpenStackAuthTests(test.TestCase):
response = self.client.post(url, form_data)
self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
mock_project_list.assert_called_once_with(
IsA(session.Session),
IsA(v3_auth.Password),
self.data.unscoped_access_info)
self.assertFalse(self.client.session['token'].system_scoped)
url = reverse('switch_system_scope')
@ -1421,14 +1432,13 @@ class OpenStackAuthTests(test.TestCase):
else:
self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
self.assertNotEqual(False, self.client.session['token'].system_scoped)
self.assertTrue(self.client.session['token'].system_scoped)
mock_get_access.assert_called_once_with(IsA(session.Session))
mock_get_access_token.assert_called_with(IsA(session.Session))
mock_project_list.assert_called_once_with(
IsA(session.Session),
IsA(v3_auth.Password),
self.data.unscoped_access_info)
def test_switch_system_scope_with_next(self):
self.test_switch_system_scope(next='/next_url')
class OpenStackAuthTestsPublicURL(OpenStackAuthTests):