Skip to content

Commit

Permalink
Fir tests and docs
Browse files Browse the repository at this point in the history
Fix broken import in test
Change naming to be consistant
Update links in docs
  • Loading branch information
gmatthews20 committed Dec 12, 2024
1 parent 1f01b04 commit 1062dc8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docs/DEVELOPER_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ There are currently 4 API submodules:

4. Openstack Query API - A python library developed by the Cloud Team to make querying Openstack easier.
- This is in active development, and we're aiming to move this out of this pack to be a standalone library.
- See [Openstack Query README.md](../lib/openstack_query/README.md)
- See [Openstack Query README.md](https://github.com/stfc/openstack-query-library/blob/main/README.md)


There are also several folders which contain shared components used by multiple API submodules.
Expand Down Expand Up @@ -140,6 +140,6 @@ We've implemented a python package to allow querying for OpenStack resources.
This is built on top of the standard openstacksdk library and implements more query features, and allows running
more complex queries.

See the Query Library [README.md](../lib/openstack_query/README.md)
See the Query Library [README.md](https://github.com/stfc/openstack-query-library/blob/main/README.md)

This will soon be extracted out into a separate repo soon.
1 change: 0 additions & 1 deletion lib/workflows/list_all_openstack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import List, Optional
from enums.query.sort_order import SortOrder
import openstackquery

# pylint:disable=too-many-arguments
Expand Down
2 changes: 1 addition & 1 deletion lib/workflows/send_shutoff_vm_email.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Optional, Union

from email_api.emailer import Emailer
from openstack_query import ServerQuery, UserQuery
from openstackquery import ServerQuery, UserQuery

from enums.cloud_domains import CloudDomains

Expand Down
11 changes: 5 additions & 6 deletions tests/lib/workflows/test_list_all_openstack.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
from unittest.mock import patch, NonCallableMock, MagicMock
import pytest

from enums.query.sort_order import SortOrder
from workflows.list_all_openstack import list_all_openstack


@patch("workflows.list_all_openstack.openstackquery")
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_list_all_openstack_minimal(mock_openstack_query, output_type):
def test_list_all_openstack_minimal(mock_openstackquery, output_type):
"""
Runs list_all_openstack only providing required values
"""

mock_query = MagicMock()
mock_cloud_account = NonCallableMock()

mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query

res = list_all_openstack(
cloud_account=mock_cloud_account,
Expand All @@ -43,12 +42,12 @@ def test_list_all_openstack_minimal(mock_openstack_query, output_type):
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_list_all_openstack_all(mock_openstack_query, output_type):
def test_list_all_openstack_all(mock_openstackquery, output_type):
"""
Runs list_all_openstack only providing all values
"""
mock_query = MagicMock()
mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query

params = {
"cloud_account": NonCallableMock(),
Expand All @@ -65,7 +64,7 @@ def test_list_all_openstack_all(mock_openstack_query, output_type):

mock_query.select.assert_called_once_with(*params["properties_to_select"])
mock_query.sort_by.assert_called_once_with(
*[(p, SortOrder.DESC) for p in params["sort_by"]]
*[(p, "desc") for p in params["sort_by"]]
)
mock_query.group_by.assert_called_once_with(params["group_by"])
mock_query.run.assert_called_once_with(
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/workflows/test_search_by_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_search_by_datetime_minimal(mock_openstack_query, output_type):
def test_search_by_datetime_minimal(mock_openstackquery, output_type):
"""
Runs search_by_datetime only providing required values
"""

mock_query = MagicMock()
mock_cloud_account = NonCallableMock()

mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query
params = {
"cloud_account": mock_cloud_account,
"query_type": "MockQuery",
Expand Down Expand Up @@ -70,15 +70,15 @@ def test_search_by_datetime_errors_when_args_all_zero():
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_search_by_datetime_all(mock_openstack_query, mock_to_webhook, output_type):
def test_search_by_datetime_all(mock_openstackquery, mock_to_webhook, output_type):
"""
Runs search_by_datetime providing all available params
"""

mock_query = MagicMock()
mock_cloud_account = NonCallableMock()

mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query
params = {
"cloud_account": mock_cloud_account,
"query_type": "MockQuery",
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/workflows/test_search_by_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_search_by_expression_minimal(mock_openstack_query, output_type):
def test_search_by_expression_minimal(mock_openstackquery, output_type):
"""
Runs search_by_expression only providing required values
"""

mock_query = MagicMock()
mock_cloud_account = NonCallableMock()

mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query
params = {
"cloud_account": mock_cloud_account,
"query_type": "MockQuery",
Expand Down Expand Up @@ -51,15 +51,15 @@ def test_search_by_expression_minimal(mock_openstack_query, output_type):
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_search_by_expression_all(mock_openstack_query, mock_to_webhook, output_type):
def test_search_by_expression_all(mock_openstackquery, mock_to_webhook, output_type):
"""
Runs search_by_expression providing all available params
"""

mock_query = MagicMock()
mock_cloud_account = NonCallableMock()

mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query
params = {
"cloud_account": mock_cloud_account,
"query_type": "MockQuery",
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/workflows/test_search_by_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_search_by_property_minimal(mock_openstack_query, output_type):
def test_search_by_property_minimal(mock_openstackquery, output_type):
"""
Runs search_by_property only providing required values
"""

mock_query = MagicMock()
mock_cloud_account = NonCallableMock()

mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query
params = {
"cloud_account": mock_cloud_account,
"query_type": "MockQuery",
Expand Down Expand Up @@ -66,15 +66,15 @@ def test_search_by_property_errors_when_no_values_given():
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_search_by_property_all(mock_openstack_query, mock_to_webhook, output_type):
def test_search_by_property_all(mock_openstackquery, mock_to_webhook, output_type):
"""
Runs search_by_property providing all values
"""

mock_query = MagicMock()
mock_cloud_account = NonCallableMock()

mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query
params = {
"cloud_account": mock_cloud_account,
"query_type": "MockQuery",
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/workflows/test_search_by_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_search_by_regex_minimal(mock_openstack_query, output_type):
def test_search_by_regex_minimal(mock_openstackquery, output_type):
"""
Runs search_by_regex only providing required values
"""

mock_query = MagicMock()
mock_cloud_account = NonCallableMock()

mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query
params = {
"cloud_account": mock_cloud_account,
"query_type": "MockQuery",
Expand Down Expand Up @@ -50,15 +50,15 @@ def test_search_by_regex_minimal(mock_openstack_query, output_type):
@pytest.mark.parametrize(
"output_type", ["to_html", "to_string", "to_objects", "to_props"]
)
def test_search_by_regex_all(mock_openstack_query, mock_to_webhook, output_type):
def test_search_by_regex_all(mock_openstackquery, mock_to_webhook, output_type):
"""
Runs search_by_regex providing all values
"""

mock_query = MagicMock()
mock_cloud_account = NonCallableMock()

mock_openstack_query.MockQuery.return_value = mock_query
mock_openstackquery.MockQuery.return_value = mock_query
params = {
"cloud_account": mock_cloud_account,
"query_type": "MockQuery",
Expand Down

0 comments on commit 1062dc8

Please sign in to comment.