Skip to content

Commit

Permalink
TST: add missing tests for code cov
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-mudaraddi committed Oct 13, 2023
1 parent 1b5e011 commit 357d8e2
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/lib/openstack_query/runners/test_server_runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from unittest.mock import MagicMock, call, patch

import openstack.exceptions
import pytest

from openstack_query.runners.server_runner import ServerRunner
Expand Down Expand Up @@ -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
):
Expand Down Expand Up @@ -146,7 +162,30 @@ def test_parse_meta_params_with_invalid_project_identifier(
mock_project_identifiers = ["project_id3"]
mock_openstack_connection.identity.find_project.side_effect = [ResourceNotFound()]
with pytest.raises(ParseQueryError):
instance._parse_meta_params(mock_openstack_connection, mock_project_identifiers)
instance._parse_meta_params(
mock_openstack_connection,
from_projects=mock_project_identifiers,
as_admin=True,
)


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,
from_projects=mock_project_identifiers,
as_admin=True,
)


def test_run_query_project_meta_arg_preset_duplication(
Expand Down

0 comments on commit 357d8e2

Please sign in to comment.