diff --git a/tests/lib/openstack_query/runners/test_server_runner.py b/tests/lib/openstack_query/runners/test_server_runner.py index dad2346d5..4eba364a4 100644 --- a/tests/lib/openstack_query/runners/test_server_runner.py +++ b/tests/lib/openstack_query/runners/test_server_runner.py @@ -1,4 +1,6 @@ from unittest.mock import MagicMock, call, patch + +import openstack.exceptions import pytest from openstack_query.runners.server_runner import ServerRunner @@ -49,6 +51,20 @@ def test_parse_meta_params_with_from_projects_no_admin( ) +def test_parse_meta_params_with_no_admin(instance, mock_openstack_connection): + """ + Tests _parse_meta_params method works expectedly - with no as_admin given + method should return meta params with projects set to a singleton list containing + only the current scoped project id + """ + res = instance._parse_meta_params( + mock_openstack_connection, + as_admin=False, + ) + assert not set(res.keys()).difference({"projects"}) + assert res["projects"] == [mock_openstack_connection.current_project_id] + + def test_parse_meta_params_with_all_projects_no_admin( instance, mock_openstack_connection ): @@ -149,6 +165,21 @@ def test_parse_meta_params_with_invalid_project_identifier( instance._parse_meta_params(mock_openstack_connection, mock_project_identifiers) +def test_parse_meta_params_with_invalid_permissions( + instance, mock_openstack_connection +): + """ + Tests _parse_meta_parms method works expectedly - with invalid admin creds + method should raise ParseQueryError when find_project fails with ForbiddenException + """ + mock_project_identifiers = ["project_id3"] + mock_openstack_connection.identity.find_project.side_effect = [ + openstack.exceptions.ForbiddenException() + ] + with pytest.raises(ParseQueryError): + instance._parse_meta_params(mock_openstack_connection, mock_project_identifiers) + + def test_run_query_project_meta_arg_preset_duplication( instance, mock_openstack_connection ):