diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.yml new file mode 100644 index 0000000..d73d940 --- /dev/null +++ b/.github/workflows/build_package.yml @@ -0,0 +1,91 @@ +name: build and release openstackquery package + +on: + workflow_dispatch: + inputs: + version: + description: 'Version to release' + required: true + changelog: + description: 'Release changelog description' + required: false + +jobs: + release: + runs-on: ubuntu-latest + + if: github.ref == 'refs/heads/main' + + strategy: + matrix: + python-version: ['3.8', '3.x'] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Update version in setup.py + run: | + sed -i "s/version=.*,/version='${{ github.event.inputs.version }}',/" setup.py + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel build + + - name: Build package + run: python -m build + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: dist-${{ matrix.python-version }} + path: dist/ + + publish: + needs: release + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v3 + with: + path: dist + + - name: Generate Changelog + id: changelog + run: | + if [ -z "${{ github.event.inputs.changelog }}" ]; then + echo "changelog=Release version ${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT + else + echo "changelog=${{ github.event.inputs.changelog }}" >> $GITHUB_OUTPUT + fi + + - name: Create Git Tag + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git add version.txt + git commit -m "Bump version to ${{ github.event.inputs.version }}" + git tag v${{ github.event.inputs.version }} + git push origin main + git push origin v${{ github.event.inputs.version }} + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: v${{ github.event.inputs.version }} + body: ${{ steps.changelog.outputs.changelog }} + files: | + dist/**/*.whl + dist/**/*.tar.gz + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 4c2bc13..651980c 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.x"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -17,7 +17,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pylint pip install -r requirements.txt - name: Analysing the code with pylint diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index f12af18..e4a3383 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -19,16 +19,11 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Run Tests - run: cd $GITHUB_WORKSPACE && ./run_tests.sh - - - name: Run pytest with codecov + - name: Install dependencies run: | - pip install -r requirements.txt - pytest tests/enums tests/lib --cov=lib --cov=tests/enums --cov=tests/lib --cov-report xml:coverage.xml + python -m pip install --upgrade pip + pip install -r requirements.txt - - name: Submit Coverage - uses: codecov/codecov-action@v4 - with: - fail_ci_if_error: true - token: ${{secrets.CODECOV_TOKEN}} + - name: run tests using pytest + run: | + cd $GITHUB_WORKSPACE && pytest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c3b3e1f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..190f1be --- /dev/null +++ b/.pylintrc @@ -0,0 +1,14 @@ +[FORMAT] +# Black will enforce 88 chars on Python code +# this will enforce 120 chars on docs / comments +max-line-length=120 + +# Disable various warnings: +# C0114: Missing module string - we don't need module strings for the small repo +# C0115: Missing class doc string - a lot of the actions are self explanatory +# W0511: TODOs they're well....to do later +# R0801: Similar lines - Imports and method signatures will flag this, such as forwarding action args +# C0116: Missing method docstring - Adds too much noise +# R0913: Too many arguments - same as above + +disable=C0114,C0115,E0401,W0511,R0801,C0116,R0913 diff --git a/README.md b/README.md index 1af707e..3bef34b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ -### Note: This is under active development -### TODO: The Query Library needs to be moved out of StackStorm and into a standalone repo - # Quick Links User-related Docs: @@ -59,3 +56,6 @@ It will address the following issues: ### 5. Easy to use syntax - sql-like syntax makes it easy to use + + +# Installation diff --git a/openstack_query/__init__.py b/openstackquery/__init__.py similarity index 93% rename from openstack_query/__init__.py rename to openstackquery/__init__.py index 1df255f..55e7261 100644 --- a/openstack_query/__init__.py +++ b/openstackquery/__init__.py @@ -1,6 +1,6 @@ import sys import logging -from .api.query_objects import ( +from openstackquery.api.query_objects import ( ServerQuery, UserQuery, FlavorQuery, diff --git a/openstack_query/aliases.py b/openstackquery/aliases.py similarity index 96% rename from openstack_query/aliases.py rename to openstackquery/aliases.py index 364c54d..d5e8b4d 100644 --- a/openstack_query/aliases.py +++ b/openstackquery/aliases.py @@ -1,9 +1,10 @@ from typing import List, Callable, Any, Dict, Union -from enums.props.prop_enum import PropEnum -from enums.query_presets import QueryPresets - from openstack.identity.v3.project import Project +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.enums.query_presets import QueryPresets + + PropValue = Union[str, bool, int, None] # A type alias for a single openstack resource - i.e Server, Hypervisor etc diff --git a/openstack_query/api/__init__.py b/openstackquery/api/__init__.py similarity index 100% rename from openstack_query/api/__init__.py rename to openstackquery/api/__init__.py diff --git a/openstack_query/api/query_api.py b/openstackquery/api/query_api.py similarity index 92% rename from openstack_query/api/query_api.py rename to openstackquery/api/query_api.py index 72741c2..d4513e9 100644 --- a/openstack_query/api/query_api.py +++ b/openstackquery/api/query_api.py @@ -1,13 +1,16 @@ import logging from copy import deepcopy +from typing import TYPE_CHECKING from typing import Union, List, Optional, Dict, Tuple -from aliases import OpenstackResourceObj, PropValue -from enums.props.prop_enum import PropEnum -from enums.sort_order import SortOrder -from enums.query_presets import QueryPresets -from exceptions.parse_query_error import ParseQueryError -from structs.query_components import QueryComponents +from openstackquery.aliases import OpenstackResourceObj, PropValue +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.enums.sort_order import SortOrder +from openstackquery.enums.query_presets import QueryPresets +from openstackquery.exceptions.parse_query_error import ParseQueryError + +if TYPE_CHECKING: + from openstackquery.structs.query_components import QueryComponents logger = logging.getLogger(__name__) @@ -17,9 +20,9 @@ class QueryAPI: Interface for Query Classes. This class exposes all public methods for query api. """ - def __init__(self, query_components: QueryComponents): + def __init__(self, query_components: "QueryComponents"): self.builder = query_components.builder - self.executer = query_components.executer + self.executor = query_components.executor self.parser = query_components.parser self.output = query_components.output self.chainer = query_components.chainer @@ -123,11 +126,11 @@ def run( filters = ( self.builder.client_side_filters + self.builder.server_filter_fallback ) - self.executer.run_with_subset( + self.executor.run_with_subset( subset=from_subset, client_side_filters=filters ) else: - self.executer.run_with_openstacksdk( + self.executor.run_with_openstacksdk( cloud_account=cloud_account, client_side_filters=self.builder.client_side_filters, server_side_filters=self.builder.server_side_filters, @@ -136,12 +139,12 @@ def run( link_prop, forwarded_vals = self.chainer.forwarded_info if forwarded_vals: - self.executer.apply_forwarded_results( + self.executor.apply_forwarded_results( link_prop, deepcopy(forwarded_vals), ) - self.results_container = self.executer.results_container + self.results_container = self.executor.results_container return self def to_objects( @@ -152,7 +155,7 @@ def to_objects( This is either returned as a list if no groups are specified, or as a dict if they grouping was requested :param groups: a list of group keys to limit output by """ - if self.executer.has_forwarded_results: + if self.executor.has_forwarded_results: logger.warning( "This Query has properties from previous queries. Running to_objects WILL IGNORE THIS " "Use to_props() instead if you want to include these properties" diff --git a/openstack_query/api/query_objects.py b/openstackquery/api/query_objects.py similarity index 69% rename from openstack_query/api/query_objects.py rename to openstackquery/api/query_objects.py index f0b5a02..d522b9c 100644 --- a/openstack_query/api/query_objects.py +++ b/openstackquery/api/query_objects.py @@ -1,16 +1,16 @@ from typing import TYPE_CHECKING from typing import Type -from mappings.flavor_mapping import FlavorMapping -from mappings.hypervisor_mapping import HypervisorMapping -from mappings.image_mapping import ImageMapping -from mappings.mapping_interface import MappingInterface -from mappings.project_mapping import ProjectMapping -from mappings.server_mapping import ServerMapping -from mappings.user_mapping import UserMapping +from openstackquery.mappings.flavor_mapping import FlavorMapping +from openstackquery.mappings.hypervisor_mapping import HypervisorMapping +from openstackquery.mappings.image_mapping import ImageMapping +from openstackquery.mappings.mapping_interface import MappingInterface +from openstackquery.mappings.project_mapping import ProjectMapping +from openstackquery.mappings.server_mapping import ServerMapping +from openstackquery.mappings.user_mapping import UserMapping if TYPE_CHECKING: - from api.query_api import QueryAPI + from openstackquery.api.query_api import QueryAPI def get_common(query_mapping: Type[MappingInterface]) -> "QueryAPI": @@ -20,8 +20,8 @@ def get_common(query_mapping: Type[MappingInterface]) -> "QueryAPI": :param query_mapping: a mapping class that defines property, runner and handler mappings """ # pylint: disable=import-outside-toplevel - from api.query_api import QueryAPI - from query_factory import QueryFactory + from openstackquery.api.query_api import QueryAPI + from openstackquery.query_factory import QueryFactory return QueryAPI(QueryFactory.build_query_deps(query_mapping)) diff --git a/openstack_query/enums/__init__.py b/openstackquery/enums/__init__.py similarity index 100% rename from openstack_query/enums/__init__.py rename to openstackquery/enums/__init__.py diff --git a/openstack_query/enums/enum_with_aliases.py b/openstackquery/enums/enum_with_aliases.py similarity index 94% rename from openstack_query/enums/enum_with_aliases.py rename to openstackquery/enums/enum_with_aliases.py index cc84fae..6dd87dc 100644 --- a/openstack_query/enums/enum_with_aliases.py +++ b/openstackquery/enums/enum_with_aliases.py @@ -2,7 +2,7 @@ from enum import Enum from typing import Dict -from exceptions.parse_query_error import ParseQueryError +from openstackquery.exceptions.parse_query_error import ParseQueryError class EnumWithAliases(Enum): diff --git a/openstack_query/enums/props/__init__.py b/openstackquery/enums/props/__init__.py similarity index 100% rename from openstack_query/enums/props/__init__.py rename to openstackquery/enums/props/__init__.py diff --git a/openstack_query/enums/props/flavor_properties.py b/openstackquery/enums/props/flavor_properties.py similarity index 94% rename from openstack_query/enums/props/flavor_properties.py rename to openstackquery/enums/props/flavor_properties.py index e1ccdcd..03d08c0 100644 --- a/openstack_query/enums/props/flavor_properties.py +++ b/openstackquery/enums/props/flavor_properties.py @@ -1,6 +1,8 @@ from enum import auto -from enums.props.prop_enum import PropEnum -from exceptions.query_property_mapping_error import QueryPropertyMappingError +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) class FlavorProperties(PropEnum): diff --git a/openstack_query/enums/props/hypervisor_properties.py b/openstackquery/enums/props/hypervisor_properties.py similarity index 96% rename from openstack_query/enums/props/hypervisor_properties.py rename to openstackquery/enums/props/hypervisor_properties.py index 3f9ad5c..452f4c2 100644 --- a/openstack_query/enums/props/hypervisor_properties.py +++ b/openstackquery/enums/props/hypervisor_properties.py @@ -1,8 +1,10 @@ from enum import auto from typing import Dict, Optional -from enums.props.prop_enum import PropEnum, PropFunc -from exceptions.query_property_mapping_error import QueryPropertyMappingError +from openstackquery.enums.props.prop_enum import PropEnum, PropFunc +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) class HypervisorProperties(PropEnum): diff --git a/openstack_query/enums/props/image_properties.py b/openstackquery/enums/props/image_properties.py similarity index 94% rename from openstack_query/enums/props/image_properties.py rename to openstackquery/enums/props/image_properties.py index 012c582..350e687 100644 --- a/openstack_query/enums/props/image_properties.py +++ b/openstackquery/enums/props/image_properties.py @@ -1,6 +1,8 @@ from enum import auto -from enums.props.prop_enum import PropEnum -from exceptions.query_property_mapping_error import QueryPropertyMappingError +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) class ImageProperties(PropEnum): diff --git a/openstack_query/enums/props/project_properties.py b/openstackquery/enums/props/project_properties.py similarity index 93% rename from openstack_query/enums/props/project_properties.py rename to openstackquery/enums/props/project_properties.py index 52ee0f1..4b83e05 100644 --- a/openstack_query/enums/props/project_properties.py +++ b/openstackquery/enums/props/project_properties.py @@ -1,6 +1,8 @@ from enum import auto -from enums.props.prop_enum import PropEnum -from exceptions.query_property_mapping_error import QueryPropertyMappingError +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) class ProjectProperties(PropEnum): diff --git a/openstack_query/enums/props/prop_enum.py b/openstackquery/enums/props/prop_enum.py similarity index 91% rename from openstack_query/enums/props/prop_enum.py rename to openstackquery/enums/props/prop_enum.py index 5729622..d7088db 100644 --- a/openstack_query/enums/props/prop_enum.py +++ b/openstackquery/enums/props/prop_enum.py @@ -1,7 +1,7 @@ from abc import abstractmethod from typing import Callable, Any, Optional -from enums.enum_with_aliases import EnumWithAliases +from openstackquery.enums.enum_with_aliases import EnumWithAliases PropFunc = Callable[[Any], Any] diff --git a/openstack_query/enums/props/server_properties.py b/openstackquery/enums/props/server_properties.py similarity index 95% rename from openstack_query/enums/props/server_properties.py rename to openstackquery/enums/props/server_properties.py index 67903b5..b45a610 100644 --- a/openstack_query/enums/props/server_properties.py +++ b/openstackquery/enums/props/server_properties.py @@ -1,6 +1,8 @@ from enum import auto -from enums.props.prop_enum import PropEnum -from exceptions.query_property_mapping_error import QueryPropertyMappingError +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) class ServerProperties(PropEnum): diff --git a/openstack_query/enums/props/user_properties.py b/openstackquery/enums/props/user_properties.py similarity index 93% rename from openstack_query/enums/props/user_properties.py rename to openstackquery/enums/props/user_properties.py index 6808036..579d9f6 100644 --- a/openstack_query/enums/props/user_properties.py +++ b/openstackquery/enums/props/user_properties.py @@ -1,6 +1,8 @@ from enum import auto -from enums.props.prop_enum import PropEnum -from exceptions.query_property_mapping_error import QueryPropertyMappingError +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) class UserProperties(PropEnum): diff --git a/openstack_query/enums/query_output_types.py b/openstackquery/enums/query_output_types.py similarity index 91% rename from openstack_query/enums/query_output_types.py rename to openstackquery/enums/query_output_types.py index 0dc4d40..498d920 100644 --- a/openstack_query/enums/query_output_types.py +++ b/openstackquery/enums/query_output_types.py @@ -1,5 +1,5 @@ from enum import Enum, auto -from exceptions.parse_query_error import ParseQueryError +from openstackquery.exceptions.parse_query_error import ParseQueryError # pylint: disable=too-few-public-methods diff --git a/openstack_query/enums/query_presets.py b/openstackquery/enums/query_presets.py similarity index 94% rename from openstack_query/enums/query_presets.py rename to openstackquery/enums/query_presets.py index 8a637ae..6ef986d 100644 --- a/openstack_query/enums/query_presets.py +++ b/openstackquery/enums/query_presets.py @@ -1,7 +1,7 @@ from typing import Union from enum import auto -from enums.enum_with_aliases import EnumWithAliases -from exceptions.parse_query_error import ParseQueryError +from openstackquery.enums.enum_with_aliases import EnumWithAliases +from openstackquery.exceptions.parse_query_error import ParseQueryError # pylint: disable=too-few-public-methods diff --git a/openstack_query/enums/query_types.py b/openstackquery/enums/query_types.py similarity index 68% rename from openstack_query/enums/query_types.py rename to openstackquery/enums/query_types.py index 1fafa61..b259296 100644 --- a/openstack_query/enums/query_types.py +++ b/openstackquery/enums/query_types.py @@ -1,13 +1,13 @@ from typing import Dict -from enums.enum_with_aliases import EnumWithAliases +from openstackquery.enums.enum_with_aliases import EnumWithAliases -from mappings.flavor_mapping import FlavorMapping -from mappings.image_mapping import ImageMapping -from mappings.project_mapping import ProjectMapping -from mappings.server_mapping import ServerMapping -from mappings.user_mapping import UserMapping -from mappings.hypervisor_mapping import HypervisorMapping +from openstackquery.mappings.flavor_mapping import FlavorMapping +from openstackquery.mappings.image_mapping import ImageMapping +from openstackquery.mappings.project_mapping import ProjectMapping +from openstackquery.mappings.server_mapping import ServerMapping +from openstackquery.mappings.user_mapping import UserMapping +from openstackquery.mappings.hypervisor_mapping import HypervisorMapping # pylint: disable=too-few-public-methods diff --git a/openstack_query/enums/sort_order.py b/openstackquery/enums/sort_order.py similarity index 86% rename from openstack_query/enums/sort_order.py rename to openstackquery/enums/sort_order.py index 83f736d..48c66c0 100644 --- a/openstack_query/enums/sort_order.py +++ b/openstackquery/enums/sort_order.py @@ -1,5 +1,5 @@ from typing import Dict -from enums.enum_with_aliases import EnumWithAliases +from openstackquery.enums.enum_with_aliases import EnumWithAliases # pylint: disable=too-few-public-methods diff --git a/openstack_query/exceptions/__init__.py b/openstackquery/exceptions/__init__.py similarity index 100% rename from openstack_query/exceptions/__init__.py rename to openstackquery/exceptions/__init__.py diff --git a/openstack_query/exceptions/enum_mapping_error.py b/openstackquery/exceptions/enum_mapping_error.py similarity index 100% rename from openstack_query/exceptions/enum_mapping_error.py rename to openstackquery/exceptions/enum_mapping_error.py diff --git a/openstack_query/exceptions/parse_query_error.py b/openstackquery/exceptions/parse_query_error.py similarity index 100% rename from openstack_query/exceptions/parse_query_error.py rename to openstackquery/exceptions/parse_query_error.py diff --git a/openstack_query/exceptions/query_chaining_error.py b/openstackquery/exceptions/query_chaining_error.py similarity index 100% rename from openstack_query/exceptions/query_chaining_error.py rename to openstackquery/exceptions/query_chaining_error.py diff --git a/openstack_query/exceptions/query_preset_mapping_error.py b/openstackquery/exceptions/query_preset_mapping_error.py similarity index 76% rename from openstack_query/exceptions/query_preset_mapping_error.py rename to openstackquery/exceptions/query_preset_mapping_error.py index c83a67f..3e06db5 100644 --- a/openstack_query/exceptions/query_preset_mapping_error.py +++ b/openstackquery/exceptions/query_preset_mapping_error.py @@ -1,4 +1,4 @@ -from exceptions.enum_mapping_error import EnumMappingError +from openstackquery.exceptions.enum_mapping_error import EnumMappingError # pylint:disable=too-few-public-methods diff --git a/openstack_query/exceptions/query_property_mapping_error.py b/openstackquery/exceptions/query_property_mapping_error.py similarity index 75% rename from openstack_query/exceptions/query_property_mapping_error.py rename to openstackquery/exceptions/query_property_mapping_error.py index 9a2129b..70a5b56 100644 --- a/openstack_query/exceptions/query_property_mapping_error.py +++ b/openstackquery/exceptions/query_property_mapping_error.py @@ -1,4 +1,4 @@ -from exceptions.enum_mapping_error import EnumMappingError +from openstackquery.exceptions.enum_mapping_error import EnumMappingError # pylint:disable=too-few-public-methods diff --git a/openstack_query/handlers/__init__.py b/openstackquery/handlers/__init__.py similarity index 100% rename from openstack_query/handlers/__init__.py rename to openstackquery/handlers/__init__.py diff --git a/openstack_query/handlers/client_side_handler.py b/openstackquery/handlers/client_side_handler.py similarity index 94% rename from openstack_query/handlers/client_side_handler.py rename to openstackquery/handlers/client_side_handler.py index eb2d414..f108386 100644 --- a/openstack_query/handlers/client_side_handler.py +++ b/openstackquery/handlers/client_side_handler.py @@ -1,11 +1,11 @@ import logging from typing import Optional, Tuple, List, Union -from exceptions.parse_query_error import ParseQueryError -from exceptions.query_preset_mapping_error import QueryPresetMappingError +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.exceptions.query_preset_mapping_error import QueryPresetMappingError -from handlers.handler_base import HandlerBase -from aliases import ( +from openstackquery.handlers.handler_base import HandlerBase +from openstackquery.aliases import ( FilterFunc, PresetPropMappings, ClientSideFilterFunc, @@ -15,8 +15,8 @@ PresetToFilterFunc, ) -from enums.query_presets import QueryPresets -from enums.props.prop_enum import PropEnum +from openstackquery.enums.query_presets import QueryPresets +from openstackquery.enums.props.prop_enum import PropEnum logger = logging.getLogger(__name__) diff --git a/openstack_query/handlers/client_side_handler_datetime.py b/openstackquery/handlers/client_side_handler_datetime.py similarity index 96% rename from openstack_query/handlers/client_side_handler_datetime.py rename to openstackquery/handlers/client_side_handler_datetime.py index 8225678..eadc046 100644 --- a/openstack_query/handlers/client_side_handler_datetime.py +++ b/openstackquery/handlers/client_side_handler_datetime.py @@ -1,12 +1,12 @@ from typing import Union from datetime import datetime -from enums.query_presets import QueryPresetsDateTime +from openstackquery.enums.query_presets import QueryPresetsDateTime -from aliases import PresetPropMappings +from openstackquery.aliases import PresetPropMappings -from time_utils import TimeUtils -from handlers.client_side_handler import ClientSideHandler +from openstackquery.time_utils import TimeUtils +from openstackquery.handlers.client_side_handler import ClientSideHandler # pylint: disable=too-many-arguments,too-few-public-methods diff --git a/openstack_query/handlers/client_side_handler_generic.py b/openstackquery/handlers/client_side_handler_generic.py similarity index 92% rename from openstack_query/handlers/client_side_handler_generic.py rename to openstackquery/handlers/client_side_handler_generic.py index 6330fc3..af31f34 100644 --- a/openstack_query/handlers/client_side_handler_generic.py +++ b/openstackquery/handlers/client_side_handler_generic.py @@ -1,8 +1,8 @@ from typing import Any, List -from aliases import PresetPropMappings, PropValue +from openstackquery.aliases import PresetPropMappings, PropValue -from enums.query_presets import QueryPresetsGeneric -from handlers.client_side_handler import ClientSideHandler +from openstackquery.enums.query_presets import QueryPresetsGeneric +from openstackquery.handlers.client_side_handler import ClientSideHandler # pylint: disable=too-few-public-methods diff --git a/openstack_query/handlers/client_side_handler_integer.py b/openstackquery/handlers/client_side_handler_integer.py similarity index 92% rename from openstack_query/handlers/client_side_handler_integer.py rename to openstackquery/handlers/client_side_handler_integer.py index ffb4923..04d46bd 100644 --- a/openstack_query/handlers/client_side_handler_integer.py +++ b/openstackquery/handlers/client_side_handler_integer.py @@ -1,8 +1,8 @@ from typing import Union -from aliases import PresetPropMappings +from openstackquery.aliases import PresetPropMappings -from enums.query_presets import QueryPresetsInteger -from handlers.client_side_handler import ClientSideHandler +from openstackquery.enums.query_presets import QueryPresetsInteger +from openstackquery.handlers.client_side_handler import ClientSideHandler # pylint: disable=too-few-public-methods diff --git a/openstack_query/handlers/client_side_handler_string.py b/openstackquery/handlers/client_side_handler_string.py similarity index 84% rename from openstack_query/handlers/client_side_handler_string.py rename to openstackquery/handlers/client_side_handler_string.py index 25114c4..fbd1b6e 100644 --- a/openstack_query/handlers/client_side_handler_string.py +++ b/openstackquery/handlers/client_side_handler_string.py @@ -1,10 +1,10 @@ import re from typing import Union -from aliases import PresetPropMappings +from openstackquery.aliases import PresetPropMappings -from enums.query_presets import QueryPresetsString -from handlers.client_side_handler import ClientSideHandler +from openstackquery.enums.query_presets import QueryPresetsString +from openstackquery.handlers.client_side_handler import ClientSideHandler # pylint: disable=too-few-public-methods diff --git a/openstack_query/handlers/handler_base.py b/openstackquery/handlers/handler_base.py similarity index 87% rename from openstack_query/handlers/handler_base.py rename to openstackquery/handlers/handler_base.py index 118b72d..fcc831b 100644 --- a/openstack_query/handlers/handler_base.py +++ b/openstackquery/handlers/handler_base.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod -from enums.query_presets import QueryPresets -from enums.props.prop_enum import PropEnum +from openstackquery.enums.query_presets import QueryPresets +from openstackquery.enums.props.prop_enum import PropEnum class HandlerBase(ABC): diff --git a/openstack_query/handlers/server_side_handler.py b/openstackquery/handlers/server_side_handler.py similarity index 91% rename from openstack_query/handlers/server_side_handler.py rename to openstackquery/handlers/server_side_handler.py index 771d76f..50e3fc6 100644 --- a/openstack_query/handlers/server_side_handler.py +++ b/openstackquery/handlers/server_side_handler.py @@ -1,17 +1,17 @@ import logging from typing import Optional, List -from enums.query_presets import QueryPresets -from enums.props.prop_enum import PropEnum +from openstackquery.enums.query_presets import QueryPresets +from openstackquery.enums.props.prop_enum import PropEnum -from aliases import ( +from openstackquery.aliases import ( FilterParams, ServerSideFilterMappings, ServerSideFilterFunc, ServerSideFilters, ) -from handlers.handler_base import HandlerBase -from exceptions.query_preset_mapping_error import QueryPresetMappingError +from openstackquery.handlers.handler_base import HandlerBase +from openstackquery.exceptions.query_preset_mapping_error import QueryPresetMappingError logger = logging.getLogger(__name__) diff --git a/openstack_query/mappings/__init__.py b/openstackquery/mappings/__init__.py similarity index 100% rename from openstack_query/mappings/__init__.py rename to openstackquery/mappings/__init__.py diff --git a/openstack_query/mappings/flavor_mapping.py b/openstackquery/mappings/flavor_mapping.py similarity index 85% rename from openstack_query/mappings/flavor_mapping.py rename to openstackquery/mappings/flavor_mapping.py index 1befc1e..32b6c55 100644 --- a/openstack_query/mappings/flavor_mapping.py +++ b/openstackquery/mappings/flavor_mapping.py @@ -1,26 +1,26 @@ from typing import Type -from structs.query_client_side_handlers import QueryClientSideHandlers +from openstackquery.structs.query_client_side_handlers import QueryClientSideHandlers -from enums.props.server_properties import ServerProperties -from enums.props.flavor_properties import FlavorProperties -from enums.query_presets import ( +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.props.flavor_properties import FlavorProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsInteger, QueryPresetsString, ) -from handlers.server_side_handler import ServerSideHandler -from handlers.client_side_handler_generic import ( +from openstackquery.handlers.server_side_handler import ServerSideHandler +from openstackquery.handlers.client_side_handler_generic import ( ClientSideHandlerGeneric, ) -from handlers.client_side_handler_integer import ( +from openstackquery.handlers.client_side_handler_integer import ( ClientSideHandlerInteger, ) -from handlers.client_side_handler_string import ClientSideHandlerString +from openstackquery.handlers.client_side_handler_string import ClientSideHandlerString -from mappings.mapping_interface import MappingInterface -from runners.flavor_runner import FlavorRunner +from openstackquery.mappings.mapping_interface import MappingInterface +from openstackquery.runners.flavor_runner import FlavorRunner class FlavorMapping(MappingInterface): diff --git a/openstack_query/mappings/hypervisor_mapping.py b/openstackquery/mappings/hypervisor_mapping.py similarity index 84% rename from openstack_query/mappings/hypervisor_mapping.py rename to openstackquery/mappings/hypervisor_mapping.py index b621eb7..b38a625 100644 --- a/openstack_query/mappings/hypervisor_mapping.py +++ b/openstackquery/mappings/hypervisor_mapping.py @@ -1,25 +1,25 @@ from typing import Type -from enums.props.hypervisor_properties import HypervisorProperties -from enums.props.server_properties import ServerProperties -from enums.query_presets import ( +from openstackquery.enums.props.hypervisor_properties import HypervisorProperties +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsString, QueryPresetsInteger, ) -from handlers.client_side_handler_generic import ( +from openstackquery.handlers.client_side_handler_generic import ( ClientSideHandlerGeneric, ) -from handlers.client_side_handler_integer import ( +from openstackquery.handlers.client_side_handler_integer import ( ClientSideHandlerInteger, ) -from handlers.client_side_handler_string import ClientSideHandlerString -from handlers.server_side_handler import ServerSideHandler -from mappings.mapping_interface import MappingInterface +from openstackquery.handlers.client_side_handler_string import ClientSideHandlerString +from openstackquery.handlers.server_side_handler import ServerSideHandler +from openstackquery.mappings.mapping_interface import MappingInterface -from runners.hypervisor_runner import HypervisorRunner -from runners.runner_wrapper import RunnerWrapper -from structs.query_client_side_handlers import QueryClientSideHandlers +from openstackquery.runners.hypervisor_runner import HypervisorRunner +from openstackquery.runners.runner_wrapper import RunnerWrapper +from openstackquery.structs.query_client_side_handlers import QueryClientSideHandlers class HypervisorMapping(MappingInterface): diff --git a/openstack_query/mappings/image_mapping.py b/openstackquery/mappings/image_mapping.py similarity index 89% rename from openstack_query/mappings/image_mapping.py rename to openstackquery/mappings/image_mapping.py index fe73ad4..1628a6d 100644 --- a/openstack_query/mappings/image_mapping.py +++ b/openstackquery/mappings/image_mapping.py @@ -1,29 +1,29 @@ from typing import Type -from enums.props.image_properties import ImageProperties -from enums.props.server_properties import ServerProperties -from enums.query_presets import ( +from openstackquery.enums.props.image_properties import ImageProperties +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsDateTime, QueryPresetsInteger, QueryPresetsString, ) -from handlers.client_side_handler_datetime import ( +from openstackquery.handlers.client_side_handler_datetime import ( ClientSideHandlerDateTime, ) -from handlers.client_side_handler_generic import ( +from openstackquery.handlers.client_side_handler_generic import ( ClientSideHandlerGeneric, ) -from handlers.client_side_handler_integer import ( +from openstackquery.handlers.client_side_handler_integer import ( ClientSideHandlerInteger, ) -from handlers.client_side_handler_string import ClientSideHandlerString -from handlers.server_side_handler import ServerSideHandler +from openstackquery.handlers.client_side_handler_string import ClientSideHandlerString +from openstackquery.handlers.server_side_handler import ServerSideHandler -from mappings.mapping_interface import MappingInterface -from runners.image_runner import ImageRunner -from time_utils import TimeUtils -from structs.query_client_side_handlers import QueryClientSideHandlers +from openstackquery.mappings.mapping_interface import MappingInterface +from openstackquery.runners.image_runner import ImageRunner +from openstackquery.time_utils import TimeUtils +from openstackquery.structs.query_client_side_handlers import QueryClientSideHandlers class ImageMapping(MappingInterface): diff --git a/openstack_query/mappings/mapping_interface.py b/openstackquery/mappings/mapping_interface.py similarity index 84% rename from openstack_query/mappings/mapping_interface.py rename to openstackquery/mappings/mapping_interface.py index abe2463..8289a35 100644 --- a/openstack_query/mappings/mapping_interface.py +++ b/openstackquery/mappings/mapping_interface.py @@ -1,9 +1,9 @@ from typing import Type from abc import ABC, abstractmethod -from enums.props.prop_enum import PropEnum -from structs.query_client_side_handlers import QueryClientSideHandlers -from runners.runner_wrapper import RunnerWrapper -from handlers.server_side_handler import ServerSideHandler +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.structs.query_client_side_handlers import QueryClientSideHandlers +from openstackquery.runners.runner_wrapper import RunnerWrapper +from openstackquery.handlers.server_side_handler import ServerSideHandler class MappingInterface(ABC): diff --git a/openstack_query/mappings/project_mapping.py b/openstackquery/mappings/project_mapping.py similarity index 88% rename from openstack_query/mappings/project_mapping.py rename to openstackquery/mappings/project_mapping.py index 0a1b335..cdaaa6b 100644 --- a/openstack_query/mappings/project_mapping.py +++ b/openstackquery/mappings/project_mapping.py @@ -1,22 +1,22 @@ from typing import Type -from structs.query_client_side_handlers import QueryClientSideHandlers +from openstackquery.structs.query_client_side_handlers import QueryClientSideHandlers -from enums.props.project_properties import ProjectProperties -from enums.query_presets import ( +from openstackquery.enums.props.project_properties import ProjectProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsString, ) -from enums.props.server_properties import ServerProperties +from openstackquery.enums.props.server_properties import ServerProperties -from handlers.server_side_handler import ServerSideHandler -from handlers.client_side_handler_generic import ( +from openstackquery.handlers.server_side_handler import ServerSideHandler +from openstackquery.handlers.client_side_handler_generic import ( ClientSideHandlerGeneric, ) -from handlers.client_side_handler_string import ClientSideHandlerString +from openstackquery.handlers.client_side_handler_string import ClientSideHandlerString -from mappings.mapping_interface import MappingInterface -from runners.project_runner import ProjectRunner +from openstackquery.mappings.mapping_interface import MappingInterface +from openstackquery.runners.project_runner import ProjectRunner class ProjectMapping(MappingInterface): diff --git a/openstack_query/mappings/server_mapping.py b/openstackquery/mappings/server_mapping.py similarity index 87% rename from openstack_query/mappings/server_mapping.py rename to openstackquery/mappings/server_mapping.py index fefc5af..3328cc4 100644 --- a/openstack_query/mappings/server_mapping.py +++ b/openstackquery/mappings/server_mapping.py @@ -1,33 +1,33 @@ from typing import Type -from structs.query_client_side_handlers import QueryClientSideHandlers +from openstackquery.structs.query_client_side_handlers import QueryClientSideHandlers -from enums.props.server_properties import ServerProperties -from enums.query_presets import ( +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsDateTime, QueryPresetsString, ) -from enums.props.user_properties import UserProperties -from enums.props.project_properties import ProjectProperties -from enums.props.flavor_properties import FlavorProperties -from enums.props.image_properties import ImageProperties -from enums.props.hypervisor_properties import HypervisorProperties +from openstackquery.enums.props.user_properties import UserProperties +from openstackquery.enums.props.project_properties import ProjectProperties +from openstackquery.enums.props.flavor_properties import FlavorProperties +from openstackquery.enums.props.image_properties import ImageProperties +from openstackquery.enums.props.hypervisor_properties import HypervisorProperties -from handlers.server_side_handler import ServerSideHandler +from openstackquery.handlers.server_side_handler import ServerSideHandler -from handlers.client_side_handler_generic import ( +from openstackquery.handlers.client_side_handler_generic import ( ClientSideHandlerGeneric, ) -from handlers.client_side_handler_string import ClientSideHandlerString -from handlers.client_side_handler_datetime import ( +from openstackquery.handlers.client_side_handler_string import ClientSideHandlerString +from openstackquery.handlers.client_side_handler_datetime import ( ClientSideHandlerDateTime, ) -from mappings.mapping_interface import MappingInterface -from runners.server_runner import ServerRunner +from openstackquery.mappings.mapping_interface import MappingInterface +from openstackquery.runners.server_runner import ServerRunner -from time_utils import TimeUtils +from openstackquery.time_utils import TimeUtils class ServerMapping(MappingInterface): diff --git a/openstack_query/mappings/user_mapping.py b/openstackquery/mappings/user_mapping.py similarity index 85% rename from openstack_query/mappings/user_mapping.py rename to openstackquery/mappings/user_mapping.py index 4113f9d..74627b6 100644 --- a/openstack_query/mappings/user_mapping.py +++ b/openstackquery/mappings/user_mapping.py @@ -1,24 +1,24 @@ from typing import Type -from structs.query_client_side_handlers import QueryClientSideHandlers +from openstackquery.structs.query_client_side_handlers import QueryClientSideHandlers -from enums.props.user_properties import UserProperties -from enums.query_presets import ( +from openstackquery.enums.props.user_properties import UserProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsString, ) -from enums.props.server_properties import ServerProperties +from openstackquery.enums.props.server_properties import ServerProperties -from handlers.server_side_handler import ServerSideHandler +from openstackquery.handlers.server_side_handler import ServerSideHandler -from handlers.client_side_handler_generic import ( +from openstackquery.handlers.client_side_handler_generic import ( ClientSideHandlerGeneric, ) -from handlers.client_side_handler_string import ClientSideHandlerString +from openstackquery.handlers.client_side_handler_string import ClientSideHandlerString -from mappings.mapping_interface import MappingInterface -from runners.user_runner import UserRunner +from openstackquery.mappings.mapping_interface import MappingInterface +from openstackquery.runners.user_runner import UserRunner class UserMapping(MappingInterface): diff --git a/openstack_query/openstack_connection.py b/openstackquery/openstack_connection.py similarity index 90% rename from openstack_query/openstack_connection.py rename to openstackquery/openstack_connection.py index 6c96268..a8a8d68 100644 --- a/openstack_query/openstack_connection.py +++ b/openstackquery/openstack_connection.py @@ -22,9 +22,7 @@ def __enter__(self) -> Connection: if not self._cloud_name: # If we don't provide a cloud name (or an empty one), Openstack will # default to env vars, which may be a security problem if they are incorrectly set - raise RuntimeError( - "A cloud name is required but was not provided." - ) + raise RuntimeError("A cloud name is required but was not provided.") self._connection = connect(cloud=self._cloud_name) return self._connection diff --git a/openstack_query/query_base.py b/openstackquery/query_base.py similarity index 85% rename from openstack_query/query_base.py rename to openstackquery/query_base.py index b7934e0..20240f5 100644 --- a/openstack_query/query_base.py +++ b/openstackquery/query_base.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod -from structs.query_client_side_handlers import QueryClientSideHandlers -from handlers.server_side_handler import ServerSideHandler +from openstackquery.structs.query_client_side_handlers import QueryClientSideHandlers +from openstackquery.handlers.server_side_handler import ServerSideHandler # pylint:disable=too-few-public-methods diff --git a/openstack_query/query_blocks/__init__.py b/openstackquery/query_blocks/__init__.py similarity index 100% rename from openstack_query/query_blocks/__init__.py rename to openstackquery/query_blocks/__init__.py diff --git a/openstack_query/query_blocks/query_builder.py b/openstackquery/query_blocks/query_builder.py similarity index 94% rename from openstack_query/query_blocks/query_builder.py rename to openstackquery/query_blocks/query_builder.py index d79755a..fa735ff 100644 --- a/openstack_query/query_blocks/query_builder.py +++ b/openstackquery/query_blocks/query_builder.py @@ -1,17 +1,19 @@ from typing import Optional, Dict, Any, List, Type, Union import logging -from handlers.client_side_handler import ClientSideHandler -from handlers.server_side_handler import ServerSideHandler +from openstackquery.handlers.client_side_handler import ClientSideHandler +from openstackquery.handlers.server_side_handler import ServerSideHandler -from enums.query_presets import QueryPresets -from enums.query_presets import get_preset_from_string -from enums.props.prop_enum import PropEnum +from openstackquery.enums.query_presets import QueryPresets +from openstackquery.enums.query_presets import get_preset_from_string +from openstackquery.enums.props.prop_enum import PropEnum -from exceptions.query_preset_mapping_error import QueryPresetMappingError -from exceptions.query_property_mapping_error import QueryPropertyMappingError +from openstackquery.exceptions.query_preset_mapping_error import QueryPresetMappingError +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) -from aliases import ( +from openstackquery.aliases import ( ClientSideFilterFunc, ClientSideFilters, ServerSideFilters, diff --git a/openstack_query/query_blocks/query_chainer.py b/openstackquery/query_blocks/query_chainer.py similarity index 91% rename from openstack_query/query_blocks/query_chainer.py rename to openstackquery/query_blocks/query_chainer.py index 59e1620..7d38a4f 100644 --- a/openstack_query/query_blocks/query_chainer.py +++ b/openstackquery/query_blocks/query_chainer.py @@ -1,10 +1,10 @@ from typing import Tuple, List, Optional, Union, Dict -from aliases import PropValue -from enums.props.prop_enum import PropEnum -from enums.query_presets import QueryPresetsGeneric -from enums.query_types import QueryTypes -from exceptions.query_chaining_error import QueryChainingError +from openstackquery.aliases import PropValue +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.enums.query_presets import QueryPresetsGeneric +from openstackquery.enums.query_types import QueryTypes +from openstackquery.exceptions.query_chaining_error import QueryChainingError class QueryChainer: @@ -81,10 +81,11 @@ def parse_then( this query (and previous chained queries) onto new query. """ - # prevents circular imports + # prevents circular imports - TODO fix this cyclic issue # pylint:disable=import-outside-toplevel - from query_factory import QueryFactory - from api.query_api import QueryAPI + # pylint:disable=cyclic-import + from openstackquery.query_factory import QueryFactory + from openstackquery.api.query_api import QueryAPI if isinstance(query_type, str): query_type = QueryTypes.from_string(query_type) diff --git a/openstack_query/query_blocks/query_executor.py b/openstackquery/query_blocks/query_executor.py similarity index 94% rename from openstack_query/query_blocks/query_executor.py rename to openstackquery/query_blocks/query_executor.py index 3b11163..7af9629 100644 --- a/openstack_query/query_blocks/query_executor.py +++ b/openstackquery/query_blocks/query_executor.py @@ -1,16 +1,14 @@ import logging import time from typing import Optional, Dict, List, Type - -from query_blocks.results_container import ResultsContainer -from runners.runner_wrapper import RunnerWrapper -from runners.runner_utils import RunnerUtils - from openstack_connection import OpenstackConnection -from enums.props.prop_enum import PropEnum +from openstackquery.query_blocks.results_container import ResultsContainer +from openstackquery.runners.runner_wrapper import RunnerWrapper +from openstackquery.runners.runner_utils import RunnerUtils -from aliases import ( +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.aliases import ( ServerSideFilters, ClientSideFilters, PropValue, diff --git a/openstack_query/query_blocks/query_grouper.py b/openstackquery/query_blocks/query_grouper.py similarity index 95% rename from openstack_query/query_blocks/query_grouper.py rename to openstackquery/query_blocks/query_grouper.py index 09720f5..fdc8dc6 100644 --- a/openstack_query/query_blocks/query_grouper.py +++ b/openstackquery/query_blocks/query_grouper.py @@ -1,10 +1,11 @@ from typing import List, Dict, Optional, Union import logging from collections import OrderedDict -from query_blocks.result import Result -from enums.props.prop_enum import PropEnum -from aliases import GroupMappings, GroupRanges, PropValue -from exceptions.parse_query_error import ParseQueryError + +from openstackquery.query_blocks.result import Result +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.aliases import GroupMappings, GroupRanges, PropValue +from openstackquery.exceptions.parse_query_error import ParseQueryError logger = logging.getLogger(__name__) diff --git a/openstack_query/query_blocks/query_output.py b/openstackquery/query_blocks/query_output.py similarity index 97% rename from openstack_query/query_blocks/query_output.py rename to openstackquery/query_blocks/query_output.py index 7a04d10..c56e67d 100644 --- a/openstack_query/query_blocks/query_output.py +++ b/openstackquery/query_blocks/query_output.py @@ -2,10 +2,11 @@ from typing import List, Dict, Union, Type, Set, Optional from pathlib import Path from tabulate import tabulate -from enums.props.prop_enum import PropEnum -from aliases import PropValue -from exceptions.parse_query_error import ParseQueryError -from query_blocks.results_container import ResultsContainer + +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.aliases import PropValue +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.query_blocks.results_container import ResultsContainer class QueryOutput: diff --git a/openstack_query/query_blocks/query_parser.py b/openstackquery/query_blocks/query_parser.py similarity index 87% rename from openstack_query/query_blocks/query_parser.py rename to openstackquery/query_blocks/query_parser.py index c8e4726..e1f92c9 100644 --- a/openstack_query/query_blocks/query_parser.py +++ b/openstackquery/query_blocks/query_parser.py @@ -1,14 +1,14 @@ from typing import List, Dict, Union, Type, Tuple, Optional import logging -from aliases import GroupRanges +from openstackquery.aliases import GroupRanges -from enums.sort_order import SortOrder -from enums.props.prop_enum import PropEnum +from openstackquery.enums.sort_order import SortOrder +from openstackquery.enums.props.prop_enum import PropEnum -from query_blocks.query_grouper import QueryGrouper -from query_blocks.query_sorter import QuerySorter -from query_blocks.result import Result +from openstackquery.query_blocks.query_grouper import QueryGrouper +from openstackquery.query_blocks.query_sorter import QuerySorter +from openstackquery.query_blocks.result import Result logger = logging.getLogger(__name__) diff --git a/openstack_query/query_blocks/query_sorter.py b/openstackquery/query_blocks/query_sorter.py similarity index 92% rename from openstack_query/query_blocks/query_sorter.py rename to openstackquery/query_blocks/query_sorter.py index abaafa9..401dc0f 100644 --- a/openstack_query/query_blocks/query_sorter.py +++ b/openstackquery/query_blocks/query_sorter.py @@ -1,11 +1,11 @@ from typing import List, Tuple, Union import logging -from query_blocks.result import Result +from openstackquery.query_blocks.result import Result -from enums.sort_order import SortOrder -from enums.props.prop_enum import PropEnum -from exceptions.parse_query_error import ParseQueryError +from openstackquery.enums.sort_order import SortOrder +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.exceptions.parse_query_error import ParseQueryError logger = logging.getLogger(__name__) diff --git a/openstack_query/query_blocks/result.py b/openstackquery/query_blocks/result.py similarity index 92% rename from openstack_query/query_blocks/result.py rename to openstackquery/query_blocks/result.py index 827adb6..82eeffe 100644 --- a/openstack_query/query_blocks/result.py +++ b/openstackquery/query_blocks/result.py @@ -1,6 +1,6 @@ from typing import Dict -from aliases import OpenstackResourceObj, PropValue -from enums.props.prop_enum import PropEnum +from openstackquery.aliases import OpenstackResourceObj, PropValue +from openstackquery.enums.props.prop_enum import PropEnum class Result: diff --git a/openstack_query/query_blocks/results_container.py b/openstackquery/query_blocks/results_container.py similarity index 96% rename from openstack_query/query_blocks/results_container.py rename to openstackquery/query_blocks/results_container.py index 1fe03c5..e935cdb 100644 --- a/openstack_query/query_blocks/results_container.py +++ b/openstackquery/query_blocks/results_container.py @@ -1,7 +1,7 @@ from typing import Union, List, Dict, Callable, Optional -from enums.props.prop_enum import PropEnum -from query_blocks.result import Result -from aliases import OpenstackResourceObj, PropValue +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.query_blocks.result import Result +from openstackquery.aliases import OpenstackResourceObj, PropValue class ResultsContainer: diff --git a/openstack_query/query_factory.py b/openstackquery/query_factory.py similarity index 66% rename from openstack_query/query_factory.py rename to openstackquery/query_factory.py index 1b91419..08ed6a9 100644 --- a/openstack_query/query_factory.py +++ b/openstackquery/query_factory.py @@ -1,12 +1,12 @@ from typing import Type -from mappings.mapping_interface import MappingInterface -from query_blocks.query_builder import QueryBuilder -from query_blocks.query_chainer import QueryChainer -from query_blocks.query_output import QueryOutput -from query_blocks.query_parser import QueryParser -from query_blocks.query_executor import QueryExecutor -from structs.query_components import QueryComponents +from openstackquery.mappings.mapping_interface import MappingInterface +from openstackquery.query_blocks.query_builder import QueryBuilder +from openstackquery.query_blocks.query_chainer import QueryChainer +from openstackquery.query_blocks.query_output import QueryOutput +from openstackquery.query_blocks.query_parser import QueryParser +from openstackquery.query_blocks.query_executor import QueryExecutor +from openstackquery.structs.query_components import QueryComponents # pylint:disable=too-few-public-methods @@ -32,10 +32,10 @@ def build_query_deps(mapping_cls: Type[MappingInterface]) -> QueryComponents: client_side_handlers=mapping_cls.get_client_side_handlers().to_list(), server_side_handler=mapping_cls.get_server_side_handler(), ) - executer = QueryExecutor( + executor = QueryExecutor( prop_enum_cls=prop_mapping, runner_cls=mapping_cls.get_runner_mapping() ) chainer = QueryChainer(chain_mappings=mapping_cls.get_chain_mappings()) - return QueryComponents(output, parser, builder, executer, chainer) + return QueryComponents(output, parser, builder, executor, chainer) diff --git a/openstack_query/runners/__init__.py b/openstackquery/runners/__init__.py similarity index 100% rename from openstack_query/runners/__init__.py rename to openstackquery/runners/__init__.py diff --git a/openstack_query/runners/flavor_runner.py b/openstackquery/runners/flavor_runner.py similarity index 88% rename from openstack_query/runners/flavor_runner.py rename to openstackquery/runners/flavor_runner.py index 390b249..df5eb66 100644 --- a/openstack_query/runners/flavor_runner.py +++ b/openstackquery/runners/flavor_runner.py @@ -2,11 +2,11 @@ import logging from openstack.compute.v2.flavor import Flavor -from openstack_connection import OpenstackConnection -from runners.runner_wrapper import RunnerWrapper -from runners.runner_utils import RunnerUtils +from openstackquery.openstack_connection import OpenstackConnection +from openstackquery.runners.runner_wrapper import RunnerWrapper +from openstackquery.runners.runner_utils import RunnerUtils -from aliases import ServerSideFilter +from openstackquery.aliases import ServerSideFilter logger = logging.getLogger(__name__) diff --git a/openstack_query/runners/hypervisor_runner.py b/openstackquery/runners/hypervisor_runner.py similarity index 87% rename from openstack_query/runners/hypervisor_runner.py rename to openstackquery/runners/hypervisor_runner.py index 1baeb59..8c7acdb 100644 --- a/openstack_query/runners/hypervisor_runner.py +++ b/openstackquery/runners/hypervisor_runner.py @@ -1,12 +1,12 @@ import logging from typing import Optional, List - -from aliases import ServerSideFilters, OpenstackResourceObj -from openstack_connection import OpenstackConnection -from runners.runner_utils import RunnerUtils -from runners.runner_wrapper import RunnerWrapper from openstack.compute.v2.hypervisor import Hypervisor +from openstackquery.aliases import ServerSideFilters, OpenstackResourceObj +from openstackquery.openstack_connection import OpenstackConnection +from openstackquery.runners.runner_utils import RunnerUtils +from openstackquery.runners.runner_wrapper import RunnerWrapper + logger = logging.getLogger(__name__) diff --git a/openstack_query/runners/image_runner.py b/openstackquery/runners/image_runner.py similarity index 91% rename from openstack_query/runners/image_runner.py rename to openstackquery/runners/image_runner.py index b34790c..3022f08 100644 --- a/openstack_query/runners/image_runner.py +++ b/openstackquery/runners/image_runner.py @@ -3,12 +3,12 @@ from openstack.compute.v2.image import Image -from openstack_connection import OpenstackConnection -from runners.runner_utils import RunnerUtils -from runners.runner_wrapper import RunnerWrapper +from openstackquery.openstack_connection import OpenstackConnection +from openstackquery.runners.runner_utils import RunnerUtils +from openstackquery.runners.runner_wrapper import RunnerWrapper -from exceptions.parse_query_error import ParseQueryError -from aliases import ServerSideFilter, ProjectIdentifier +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.aliases import ServerSideFilter, ProjectIdentifier logger = logging.getLogger(__name__) @@ -27,6 +27,7 @@ def parse_meta_params( from_projects: Optional[List[ProjectIdentifier]] = None, all_projects: bool = False, as_admin: bool = False, + **_, ) -> Dict: """ This method is a helper function that will parse a set of meta params specific to the resource and diff --git a/openstack_query/runners/project_runner.py b/openstackquery/runners/project_runner.py similarity index 89% rename from openstack_query/runners/project_runner.py rename to openstackquery/runners/project_runner.py index d5d397c..8ef6ebe 100644 --- a/openstack_query/runners/project_runner.py +++ b/openstackquery/runners/project_runner.py @@ -3,11 +3,11 @@ from openstack.identity.v3.project import Project -from openstack_connection import OpenstackConnection -from runners.runner_utils import RunnerUtils -from runners.runner_wrapper import RunnerWrapper +from openstackquery.openstack_connection import OpenstackConnection +from openstackquery.runners.runner_utils import RunnerUtils +from openstackquery.runners.runner_wrapper import RunnerWrapper -from aliases import ServerSideFilter +from openstackquery.aliases import ServerSideFilter logger = logging.getLogger(__name__) diff --git a/openstack_query/runners/runner_utils.py b/openstackquery/runners/runner_utils.py similarity index 97% rename from openstack_query/runners/runner_utils.py rename to openstackquery/runners/runner_utils.py index 6814d9d..b02ec6d 100644 --- a/openstack_query/runners/runner_utils.py +++ b/openstackquery/runners/runner_utils.py @@ -2,9 +2,9 @@ import logging from openstack.exceptions import ResourceNotFound, ForbiddenException -from exceptions.parse_query_error import ParseQueryError -from openstack_connection import OpenstackConnection -from aliases import ( +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.openstack_connection import OpenstackConnection +from openstackquery.aliases import ( ServerSideFilter, ClientSideFilters, ClientSideFilterFunc, diff --git a/openstack_query/runners/runner_wrapper.py b/openstackquery/runners/runner_wrapper.py similarity index 92% rename from openstack_query/runners/runner_wrapper.py rename to openstackquery/runners/runner_wrapper.py index 1b8a833..de87ab2 100644 --- a/openstack_query/runners/runner_wrapper.py +++ b/openstackquery/runners/runner_wrapper.py @@ -1,13 +1,13 @@ from abc import abstractmethod from typing import Optional, List, Dict -from aliases import ( +from openstackquery.aliases import ( PropFunc, ServerSideFilters, OpenstackResourceObj, ) -from openstack_connection import OpenstackConnection -from exceptions.parse_query_error import ParseQueryError +from openstackquery.openstack_connection import OpenstackConnection +from openstackquery.exceptions.parse_query_error import ParseQueryError class RunnerWrapper: diff --git a/openstack_query/runners/server_runner.py b/openstackquery/runners/server_runner.py similarity index 93% rename from openstack_query/runners/server_runner.py rename to openstackquery/runners/server_runner.py index 2f50a94..41685ff 100644 --- a/openstack_query/runners/server_runner.py +++ b/openstackquery/runners/server_runner.py @@ -3,12 +3,12 @@ from openstack.compute.v2.server import Server -from openstack_connection import OpenstackConnection -from runners.runner_utils import RunnerUtils -from runners.runner_wrapper import RunnerWrapper +from openstackquery.openstack_connection import OpenstackConnection +from openstackquery.runners.runner_utils import RunnerUtils +from openstackquery.runners.runner_wrapper import RunnerWrapper -from exceptions.parse_query_error import ParseQueryError -from aliases import ( +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.aliases import ( ProjectIdentifier, ServerSideFilter, ) @@ -30,6 +30,7 @@ def parse_meta_params( from_projects: Optional[List[ProjectIdentifier]] = None, all_projects: bool = False, as_admin: bool = False, + **_, ) -> Dict: """ This method is a helper function that will parse a set of query meta params related to openstack server queries. diff --git a/openstack_query/runners/user_runner.py b/openstackquery/runners/user_runner.py similarity index 90% rename from openstack_query/runners/user_runner.py rename to openstackquery/runners/user_runner.py index e654d00..135ab4c 100644 --- a/openstack_query/runners/user_runner.py +++ b/openstackquery/runners/user_runner.py @@ -2,11 +2,11 @@ from typing import Optional, Dict, List from openstack.identity.v3.user import User -from openstack_connection import OpenstackConnection -from runners.runner_utils import RunnerUtils -from runners.runner_wrapper import RunnerWrapper +from openstackquery.openstack_connection import OpenstackConnection +from openstackquery.runners.runner_utils import RunnerUtils +from openstackquery.runners.runner_wrapper import RunnerWrapper -from aliases import ServerSideFilter +from openstackquery.aliases import ServerSideFilter logger = logging.getLogger(__name__) @@ -20,7 +20,7 @@ class UserRunner(RunnerWrapper): RESOURCE_TYPE = User def parse_meta_params( - self, conn: OpenstackConnection, from_domain: str = "default" + self, conn: OpenstackConnection, from_domain: str = "default", **_ ) -> Dict: """ This method is a helper function that will parse a set of query meta params related to openstack user queries diff --git a/openstack_query/structs/__init__.py b/openstackquery/structs/__init__.py similarity index 100% rename from openstack_query/structs/__init__.py rename to openstackquery/structs/__init__.py diff --git a/openstack_query/structs/query_client_side_handlers.py b/openstackquery/structs/query_client_side_handlers.py similarity index 66% rename from openstack_query/structs/query_client_side_handlers.py rename to openstackquery/structs/query_client_side_handlers.py index 3895cec..3021b99 100644 --- a/openstack_query/structs/query_client_side_handlers.py +++ b/openstackquery/structs/query_client_side_handlers.py @@ -1,15 +1,15 @@ from typing import List, Optional from dataclasses import dataclass, fields -from handlers.client_side_handler import ClientSideHandler -from handlers.client_side_handler_generic import ( +from openstackquery.handlers.client_side_handler import ClientSideHandler +from openstackquery.handlers.client_side_handler_generic import ( ClientSideHandlerGeneric, ) -from handlers.client_side_handler_string import ClientSideHandlerString -from handlers.client_side_handler_datetime import ( +from openstackquery.handlers.client_side_handler_string import ClientSideHandlerString +from openstackquery.handlers.client_side_handler_datetime import ( ClientSideHandlerDateTime, ) -from handlers.client_side_handler_integer import ( +from openstackquery.handlers.client_side_handler_integer import ( ClientSideHandlerInteger, ) diff --git a/openstack_query/structs/query_components.py b/openstackquery/structs/query_components.py similarity index 66% rename from openstack_query/structs/query_components.py rename to openstackquery/structs/query_components.py index 50e4a73..eb7e8dd 100644 --- a/openstack_query/structs/query_components.py +++ b/openstackquery/structs/query_components.py @@ -1,10 +1,10 @@ from dataclasses import dataclass -from query_blocks.query_builder import QueryBuilder -from query_blocks.query_chainer import QueryChainer -from query_blocks.query_output import QueryOutput -from query_blocks.query_parser import QueryParser -from query_blocks.query_executor import QueryExecutor +from openstackquery.query_blocks.query_builder import QueryBuilder +from openstackquery.query_blocks.query_chainer import QueryChainer +from openstackquery.query_blocks.query_output import QueryOutput +from openstackquery.query_blocks.query_parser import QueryParser +from openstackquery.query_blocks.query_executor import QueryExecutor @dataclass @@ -15,7 +15,7 @@ class QueryComponents: - and handles the select(), to_string(), to_html(), etc commands :param parser: holds a configured QueryParser object which is used to handle sort_by/group_by commands :param builder: holds a configured QueryBuilder object which is used to handler where() commands - :param executer: holds a configured QueryExecute object which is used to execute the query + :param executor: holds a configured QueryExecute object which is used to execute the query - handles the run() command :param chainer: holds a configured QueryChainer object which is used to store query chain mappings """ @@ -23,5 +23,5 @@ class QueryComponents: output: QueryOutput parser: QueryParser builder: QueryBuilder - executer: QueryExecutor + executor: QueryExecutor chainer: QueryChainer diff --git a/openstack_query/structs/query_output_details.py b/openstackquery/structs/query_output_details.py similarity index 94% rename from openstack_query/structs/query_output_details.py rename to openstackquery/structs/query_output_details.py index b45bbf2..8f18525 100644 --- a/openstack_query/structs/query_output_details.py +++ b/openstackquery/structs/query_output_details.py @@ -1,8 +1,9 @@ from dataclasses import dataclass from typing import List, Dict, Optional, Tuple, Type -from enums.query_output_types import QueryOutputTypes -from enums.props.prop_enum import PropEnum -from aliases import PropValue + +from openstackquery.enums.query_output_types import QueryOutputTypes +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.aliases import PropValue @dataclass diff --git a/openstack_query/structs/query_preset_details.py b/openstackquery/structs/query_preset_details.py similarity index 73% rename from openstack_query/structs/query_preset_details.py rename to openstackquery/structs/query_preset_details.py index e3fbcc3..1caac22 100644 --- a/openstack_query/structs/query_preset_details.py +++ b/openstackquery/structs/query_preset_details.py @@ -1,8 +1,8 @@ from typing import Any, Dict from dataclasses import dataclass -from enums.props.prop_enum import PropEnum -from enums.query_presets import QueryPresets +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.enums.query_presets import QueryPresets @dataclass diff --git a/openstack_query/time_utils.py b/openstackquery/time_utils.py similarity index 100% rename from openstack_query/time_utils.py rename to openstackquery/time_utils.py diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..52778f4 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +pythonpath = openstackquery +testpaths = tests +python_files = *.py +python_functions = test_* diff --git a/setup.py b/setup.py index 5f4ebff..1922735 100644 --- a/setup.py +++ b/setup.py @@ -1 +1,19 @@ -# TODO - make package \ No newline at end of file +from setuptools import setup, find_packages + +DESCRIPTION = "python package for openstack query library" +LONG_DESCRIPTION = ( + """Python package for running complex queries on OpenStack Resources""" +) + +setup( + name="openstackquery", + version="0.1.0", + author="Anish Mudaraddi", + author_email="", + description=DESCRIPTION, + long_description=LONG_DESCRIPTION, + packages=find_packages(), + python_requires=">=3.8", + install_requires=[], + keywords=["python, openstack"], +) diff --git a/tests/api/test_query_api.py b/tests/api/test_query_api.py index 763db13..3885ff7 100644 --- a/tests/api/test_query_api.py +++ b/tests/api/test_query_api.py @@ -1,9 +1,9 @@ from unittest.mock import MagicMock, NonCallableMock, patch import pytest -from api.query_api import QueryAPI +from openstackquery.api.query_api import QueryAPI -from exceptions.parse_query_error import ParseQueryError +from openstackquery.exceptions.parse_query_error import ParseQueryError from tests.mocks.mocked_query_presets import MockQueryPresets from tests.mocks.mocked_props import MockProperties @@ -114,7 +114,7 @@ def test_run_invalid_params(instance): def test_run_from_subset(instance): """ Tests run method with from subset params - method should call executer.run_with_subset + method should call executor.run_with_subset """ mock_subset = NonCallableMock() @@ -126,19 +126,19 @@ def test_run_from_subset(instance): instance.chainer.forwarded_info = None, None res = instance.run(from_subset=mock_subset) - instance.executer.run_with_subset.assert_called_once_with( + instance.executor.run_with_subset.assert_called_once_with( subset=mock_subset, client_side_filters=[client_filter, fallback_filter] ) - instance.executer.apply_forwarded_results.assert_not_called() + instance.executor.apply_forwarded_results.assert_not_called() assert res == instance -@patch("api.query_api.deepcopy") +@patch("openstackquery.api.query_api.deepcopy") def test_run_from_subset_with_chained_values(mock_deepcopy, instance): """ Tests run method with from subset params and chained values - method should call executer.run_with_subset and then executer.apply_forwarded_results + method should call executor.run_with_subset and then executor.apply_forwarded_results """ mock_subset = NonCallableMock() @@ -154,11 +154,11 @@ def test_run_from_subset_with_chained_values(mock_deepcopy, instance): res = instance.run(from_subset=mock_subset) - instance.executer.run_with_subset.assert_called_once_with( + instance.executor.run_with_subset.assert_called_once_with( subset=mock_subset, client_side_filters=[client_filter, fallback_filter] ) - instance.executer.apply_forwarded_results.assert_called_once_with( + instance.executor.apply_forwarded_results.assert_called_once_with( mock_link_prop, mock_deepcopy.return_value ) mock_deepcopy.assert_called_once_with(mock_forwarded_vals) @@ -168,7 +168,7 @@ def test_run_from_subset_with_chained_values(mock_deepcopy, instance): def test_run_with_openstacksdk(instance): """ Tests run method with cloud_account param - method should call executer.run_with_openstacksdk + method should call executor.run_with_openstacksdk """ mock_cloud_account = NonCallableMock() mock_kwargs = {"arg1": "val1", "arg2": "val2"} @@ -176,21 +176,21 @@ def test_run_with_openstacksdk(instance): instance.chainer.forwarded_info = None, None res = instance.run(cloud_account=mock_cloud_account, **mock_kwargs) - instance.executer.run_with_openstacksdk.assert_called_once_with( + instance.executor.run_with_openstacksdk.assert_called_once_with( cloud_account=mock_cloud_account, client_side_filters=instance.builder.client_side_filters, server_side_filters=instance.builder.server_side_filters, **mock_kwargs ) - instance.executer.apply_forwarded_results.assert_not_called() + instance.executor.apply_forwarded_results.assert_not_called() assert res == instance -@patch("api.query_api.deepcopy") +@patch("openstackquery.api.query_api.deepcopy") def test_run_with_openstacksdk_with_chained_values(mock_deepcopy, instance): """ Tests run method with cloud_account param and chained values - method should call executer.run_with_openstacksdk and then executer.apply_forwarded_results + method should call executor.run_with_openstacksdk and then executor.apply_forwarded_results """ mock_cloud_account = NonCallableMock() mock_kwargs = {"arg1": "val1", "arg2": "val2"} @@ -200,13 +200,13 @@ def test_run_with_openstacksdk_with_chained_values(mock_deepcopy, instance): instance.chainer.forwarded_info = mock_link_prop, mock_forwarded_val res = instance.run(cloud_account=mock_cloud_account, **mock_kwargs) - instance.executer.run_with_openstacksdk.assert_called_once_with( + instance.executor.run_with_openstacksdk.assert_called_once_with( cloud_account=mock_cloud_account, client_side_filters=instance.builder.client_side_filters, server_side_filters=instance.builder.server_side_filters, **mock_kwargs ) - instance.executer.apply_forwarded_results.assert_called_once_with( + instance.executor.apply_forwarded_results.assert_called_once_with( mock_link_prop, mock_deepcopy.return_value ) mock_deepcopy.assert_called_once_with(mock_forwarded_val) @@ -254,7 +254,7 @@ def test_to_objects(instance): """ mock_flatten = NonCallableMock() - instance.executer.has_forwarded_results = False + instance.executor.has_forwarded_results = False res = instance.to_objects(mock_flatten) instance.results_container.parse_results.assert_called_once_with( @@ -274,7 +274,7 @@ def test_to_objects_with_forwarded_results(instance): """ mock_flatten = NonCallableMock() - instance.executer.has_forwarded_results = True + instance.executor.has_forwarded_results = True res = instance.to_objects(mock_flatten) instance.results_container.parse_results.assert_called_once_with( diff --git a/tests/api/test_query_objects.py b/tests/api/test_query_objects.py index 38123c1..812e29d 100644 --- a/tests/api/test_query_objects.py +++ b/tests/api/test_query_objects.py @@ -2,7 +2,7 @@ import pytest -from api.query_objects import ( +from openstackquery.api.query_objects import ( UserQuery, ServerQuery, FlavorQuery, @@ -13,8 +13,8 @@ ) -@patch("query_factory.QueryFactory") -@patch("api.query_api.QueryAPI") +@patch("openstackquery.query_factory.QueryFactory") +@patch("openstackquery.api.query_api.QueryAPI") def test_get_common(mock_query_api, mock_query_factory): """ tests that function _get_common works @@ -40,7 +40,7 @@ def _run_query_test_case(mock_query_func, expected_mapping): tests each given query_function calls get_common with expected mapping class """ - with patch("api.query_objects.get_common") as mock_get_common: + with patch("openstackquery.api.query_objects.get_common") as mock_get_common: res = mock_query_func() mock_get_common.assert_called_once_with(expected_mapping) assert res == mock_get_common.return_value @@ -53,9 +53,7 @@ def test_server_query(run_query_test_case): tests that function ServerQuery works should call get_common with ServerMapping """ - with patch( - "api.query_objects.ServerMapping" - ) as mock_server_mapping: + with patch("openstackquery.api.query_objects.ServerMapping") as mock_server_mapping: run_query_test_case(ServerQuery, mock_server_mapping) @@ -64,7 +62,7 @@ def test_user_query(run_query_test_case): tests that function UserQuery works should call get_common with UserMapping """ - with patch("api.query_objects.UserMapping") as mock_user_mapping: + with patch("openstackquery.api.query_objects.UserMapping") as mock_user_mapping: run_query_test_case(UserQuery, mock_user_mapping) @@ -73,9 +71,7 @@ def test_flavor_query(run_query_test_case): tests that function FlavorQuery works should call get_common with FlavorMapping """ - with patch( - "api.query_objects.FlavorMapping" - ) as mock_flavor_mapping: + with patch("openstackquery.api.query_objects.FlavorMapping") as mock_flavor_mapping: run_query_test_case(FlavorQuery, mock_flavor_mapping) @@ -85,7 +81,7 @@ def test_project_query(run_query_test_case): should call get_common with ProjectMapping """ with patch( - "api.query_objects.ProjectMapping" + "openstackquery.api.query_objects.ProjectMapping" ) as mock_project_mapping: run_query_test_case(ProjectQuery, mock_project_mapping) @@ -95,9 +91,7 @@ def test_image_query(run_query_test_case): tests that function ImageQuery works should call get_common with ImageMapping """ - with patch( - "api.query_objects.ImageMapping" - ) as mock_project_mapping: + with patch("openstackquery.api.query_objects.ImageMapping") as mock_project_mapping: run_query_test_case(ImageQuery, mock_project_mapping) @@ -107,6 +101,6 @@ def test_hypervisor_query(run_query_test_case): should call get_common with ProjectMapping """ with patch( - "api.query_objects.HypervisorMapping" + "openstackquery.api.query_objects.HypervisorMapping" ) as mock_project_mapping: run_query_test_case(HypervisorQuery, mock_project_mapping) diff --git a/tests/enums/__init__.py b/tests/enums/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/enums/props/__init__.py b/tests/enums/props/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/enums/props/test_flavor_properties.py b/tests/enums/props/test_flavor_properties.py new file mode 100644 index 0000000..ba0dc1b --- /dev/null +++ b/tests/enums/props/test_flavor_properties.py @@ -0,0 +1,145 @@ +from unittest.mock import patch +import pytest + +from openstackquery.enums.props.flavor_properties import FlavorProperties +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) + +from tests.mocks.mocked_props import MockProperties + + +@pytest.mark.parametrize("prop", list(FlavorProperties)) +def test_get_prop_mapping(prop): + """ + Tests that all flavor properties have a property function mapping + """ + FlavorProperties.get_prop_mapping(prop) + + +def test_get_prop_mapping_invalid(): + """ + Tests that get_prop_mapping returns Error if property not supported + """ + with pytest.raises(QueryPropertyMappingError): + FlavorProperties.get_prop_mapping(MockProperties.PROP_1) + + +@patch("openstackquery.enums.props.flavor_properties.FlavorProperties.get_prop_mapping") +def test_get_marker_prop_func(mock_get_prop_mapping): + """ + Tests that marker_prop_func returns get_prop_mapping called with FLAVOR_ID + """ + val = FlavorProperties.get_marker_prop_func() + mock_get_prop_mapping.assert_called_once_with(FlavorProperties.FLAVOR_ID) + assert val == mock_get_prop_mapping.return_value + + +@pytest.mark.parametrize( + "val", + [ + "flavor_description", + "Flavor_Description", + "FlAvOr_DeScRiPtIoN", + "description", + "desc", + ], +) +def test_flavor_description_serialization(val): + """ + Tests that variants of FLAVOR_DESCRIPTION can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_DESCRIPTION + + +@pytest.mark.parametrize( + "val", ["flavor_disk", "Flavor_Disk", "FlAvOr_DiSk", "disk", "disk_size"] +) +def test_flavor_disk_serialization(val): + """ + Tests that variants of FLAVOR_DISK can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_DISK + + +@pytest.mark.parametrize( + "val", + [ + "flavor_ephemeral", + "Flavor_Ephemeral", + "FlAvOr_EpHeMeRaL", + "ephemeral", + "ephemeral_disk", + "ephemeral_disk_size", + ], +) +def test_flavor_ephemeral_serialization(val): + """ + Tests that variants of FLAVOR_EPHEMERAL can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_EPHEMERAL + + +@pytest.mark.parametrize("val", ["flavor_id", "Flavor_ID", "FlAvOr_Id", "id", "uuid"]) +def test_flavor_id_serialization(val): + """ + Tests that variants of FLAVOR_ID can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_ID + + +@pytest.mark.parametrize( + "val", + ["flavor_is_disabled", "Flavor_Is_Disabled", "Flavor_Is_DiSaBlEd", "is_disabled"], +) +def test_flavor_is_disabled_serialization(val): + """ + Tests that variants of FLAVOR_IS_DISABLED can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_IS_DISABLED + + +@pytest.mark.parametrize( + "val", ["flavor_is_public", "Flavor_Is_Public", "FlAvOr_Is_PuBlIc", "is_public"] +) +def test_flavor_is_public_serialization(val): + """ + Tests that variants of FLAVOR_IS_PUBLIC can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_IS_PUBLIC + + +@pytest.mark.parametrize("val", ["flavor_name", "Flavor_Name", "FlAvOr_NaMe", "name"]) +def test_flavor_name_serialization(val): + """ + Tests that variants of FLAVOR_NAME can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_NAME + + +@pytest.mark.parametrize( + "val", ["flavor_ram", "Flavor_RAM", "FlAvOr_RaM", "ram", "ram_size"] +) +def test_flavor_ram_serialization(val): + """ + Tests that variants of FLAVOR_RAM can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_RAM + + +@pytest.mark.parametrize("val", ["flavor_swap", "Flavor_Swap", "FlAvOr_SwAp"]) +def test_flavor_swap_serialization(val): + """ + Tests that variants of FLAVOR_SWAP can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_SWAP + + +@pytest.mark.parametrize( + "val", ["flavor_vcpu", "Flavor_VCPU", "FlAvOr_VcPu", "vcpu", "vcpus"] +) +def test_flavor_vcpu_serialization(val): + """ + Tests that variants of FLAVOR_VCPU can be serialized + """ + assert FlavorProperties.from_string(val) is FlavorProperties.FLAVOR_VCPU diff --git a/tests/enums/props/test_hypervisor_properties.py b/tests/enums/props/test_hypervisor_properties.py new file mode 100644 index 0000000..2d11f5a --- /dev/null +++ b/tests/enums/props/test_hypervisor_properties.py @@ -0,0 +1,321 @@ +from unittest.mock import patch +import pytest + +from openstackquery.enums.props.hypervisor_properties import HypervisorProperties +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) + +from tests.mocks.mocked_props import MockProperties + + +@pytest.mark.parametrize("prop", list(HypervisorProperties)) +def test_get_prop_mapping(prop): + """ + Tests that all hypervisor properties have a property function mapping + """ + HypervisorProperties.get_prop_mapping(prop) + + +def test_get_prop_mapping_invalid(): + """ + Tests that get_prop_mapping returns Error if property not supported + """ + with pytest.raises(QueryPropertyMappingError): + HypervisorProperties.get_prop_mapping(MockProperties.PROP_1) + + +@patch( + "openstackquery.enums.props.hypervisor_properties.HypervisorProperties.get_prop_mapping" +) +def test_get_marker_prop_func(mock_get_prop_mapping): + """ + Tests that marker_prop_func returns get_prop_mapping called with HYPERVISOR_ID + """ + val = HypervisorProperties.get_marker_prop_func() + mock_get_prop_mapping.assert_called_once_with(HypervisorProperties.HYPERVISOR_ID) + assert val == mock_get_prop_mapping.return_value + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_current_workload", + "Hypervisor_Current_Workload", + "HyPeRvIsOr_CuRrEnT_wOrKlOaD", + "current_workload", + "workload", + ], +) +def test_hypervisor_current_workload_serialization(val): + """ + Tests that variants of HYPERVISOR_CURRENT_WORKLOAD can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_CURRENT_WORKLOAD + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_disk_free", + "Hypervisor_Disk_Free", + "HyPeRvIsOr_DiSk_FrEe", + "local_disk_free", + "free_disk_gb", + ], +) +def test_hypervisor_disk_free_serialization(val): + """ + Tests that variants of HYPERVISOR_DISK_FREE can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_DISK_FREE + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_disk_size", + "Hypervisor_Disk_Size", + "HyPeRvIsOr_DiSk_SiZe", + "local_disk_size", + "local_gb", + ], +) +def test_hypervisor_disk_size_serialization(val): + """ + Tests that variants of HYPERVISOR_DISK_SIZE can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_DISK_SIZE + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_disk_used", + "Hypervisor_Disk_Used", + "HyPeRvIsOr_DiSk_UsEd", + "local_disk_used", + "local_disk_used", + ], +) +def test_hypervisor_disk_used_serialization(val): + """ + Tests that variants of HYPERVISOR_DISK_USED can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_DISK_USED + ) + + +@pytest.mark.parametrize( + "val", + ["hypervisor_id", "Hypervisor_ID", "HyPeRvIsOr_Id", "id", "uuid", "host_id"], +) +def test_hypervisor_id_serialization(val): + """ + Tests that variants of HYPERVISOR_ID can be serialized + """ + assert HypervisorProperties.from_string(val) is HypervisorProperties.HYPERVISOR_ID + + +@pytest.mark.parametrize( + "val", + ["hypervisor_ip", "Hypervisor_IP", "HyPeRvIsOr_Ip", "ip", "host_ip"], +) +def test_hypervisor_ip_serialization(val): + """ + Tests that variants of HYPERVISOR_IP can be serialized + """ + assert HypervisorProperties.from_string(val) is HypervisorProperties.HYPERVISOR_IP + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_memory_free", + "Hypervisor_Memory_Free", + "HyPeRvIsOr_MeMoRy_FrEe", + "memory_free", + "free_ram_mb", + ], +) +def test_hypervisor_memory_free_serialization(val): + """ + Tests that variants of HYPERVISOR_MEMORY_FREE can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_MEMORY_FREE + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_memory_size", + "Hypervisor_Memory_Size", + "HyPeRvIsOr_MeMoRy_SiZe", + "memory_size", + "memory_mb", + ], +) +def test_hypervisor_memory_size_serialization(val): + """ + Tests that variants of HYPERVISOR_MEMORY_SIZE can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_MEMORY_SIZE + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_memory_used", + "Hypervisor_Memory_Used", + "HyPeRvIsOr_MeMoRy_UsEd", + "memory_used", + "memory_mb_used", + ], +) +def test_hypervisor_memory_used_serialization(val): + """ + Tests that variants of HYPERVISOR_MEMORY_USED can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_MEMORY_USED + ) + + +@pytest.mark.parametrize( + "val", + ["hypervisor_name", "Hypervisor_Name", "HyPeRvIsOr_NaMe", "name", "host_name"], +) +def test_hypervisor_name_serialization(val): + """ + Tests that variants of HYPERVISOR_NAME can be serialized + """ + assert HypervisorProperties.from_string(val) is HypervisorProperties.HYPERVISOR_NAME + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_server_count", + "Hypervisor_Server_Count", + "HyPeRvIsOr_SeRvEr_CoUnT", + "running_vms", + ], +) +def test_hypervisor_server_count_serialization(val): + """ + Tests that variants of HYPERVISOR_SERVER_COUNT can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_SERVER_COUNT + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_state", + "Hypervisor_State", + "HyPeRvIsOr_StAtE", + "state", + ], +) +def test_hypervisor_state_serialization(val): + """ + Tests that variants of HYPERVISOR_STATE can be serialized + """ + assert ( + HypervisorProperties.from_string(val) is HypervisorProperties.HYPERVISOR_STATE + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_status", + "Hypervisor_Status", + "HyPeRvIsOr_StAtuS", + "status", + ], +) +def test_hypervisor_status_serialization(val): + """ + Tests that variants of HYPERVISOR_STATUS can be serialized + """ + assert ( + HypervisorProperties.from_string(val) is HypervisorProperties.HYPERVISOR_STATUS + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_vcpus", + "Hypervisor_VCPUs", + "HyPeRvIsOr_VcPuS", + "vcpus", + ], +) +def test_hypervisor_vcpus_serialization(val): + """ + Tests that variants of HYPERVISOR_VCPUS can be serialized + """ + assert ( + HypervisorProperties.from_string(val) is HypervisorProperties.HYPERVISOR_VCPUS + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_vcpus_used", + "Hypervisor_VCPUs_Used", + "HyPeRvIsOr_VcPuS_uSeD", + "vcpus_used", + ], +) +def test_hypervisor_vcpus_used_serialization(val): + """ + Tests that variants of HYPERVISOR_VCPUS_USED can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_VCPUS_USED + ) + + +@pytest.mark.parametrize( + "val", + [ + "hypervisor_disabled_reason", + "Hypervisor_Disabled_Reason", + "HyPeRvIsOr_DiSaBlEd_ReAsOn", + "disabled_reason", + ], +) +def test_hypervisor_disabled_reason_serialization(val): + """ + Tests that variants of HYPERVISOR_DISABLED_REASON can be serialized + """ + assert ( + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_DISABLED_REASON + ) diff --git a/tests/enums/props/test_image_properties.py b/tests/enums/props/test_image_properties.py new file mode 100644 index 0000000..13171e5 --- /dev/null +++ b/tests/enums/props/test_image_properties.py @@ -0,0 +1,140 @@ +from unittest.mock import patch +import pytest + +from openstackquery.enums.props.image_properties import ImageProperties +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) + +from tests.mocks.mocked_props import MockProperties + + +@pytest.mark.parametrize("prop", list(ImageProperties)) +def test_get_prop_mapping(prop): + """ + Tests that all image properties have a property function mapping + """ + ImageProperties.get_prop_mapping(prop) + + +def test_get_prop_mapping_invalid(): + """ + Tests that get_prop_mapping returns Error if property not supported + """ + with pytest.raises(QueryPropertyMappingError): + ImageProperties.get_prop_mapping(MockProperties.PROP_1) + + +@patch("openstackquery.enums.props.image_properties.ImageProperties.get_prop_mapping") +def test_get_marker_prop_func(mock_get_prop_mapping): + """ + Tests that marker_prop_func returns get_prop_mapping called with IMAGE_ID + """ + val = ImageProperties.get_marker_prop_func() + mock_get_prop_mapping.assert_called_once_with(ImageProperties.IMAGE_ID) + assert val == mock_get_prop_mapping.return_value + + +@pytest.mark.parametrize( + "val", + ["image_creation_date", "Image_Creation_Date", "ImAgE_CrEaTiOn_DaTe", "created_at"], +) +def test_image_creation_date_serialization(val): + """ + Tests that variants of IMAGE_CREATION_DATE can be serialized + """ + assert ImageProperties.from_string(val) is ImageProperties.IMAGE_CREATION_DATE + + +@pytest.mark.parametrize( + "val", + [ + "image_creation_progress", + "Image_creation_Progress", + "ImAgE_CrEaTiOn_PrOgReSs", + "progress", + ], +) +def test_image_creation_progress_serialization(val): + """ + Tests that variants of IMAGE_CREATION_PROGRESS can be serialized + """ + assert ImageProperties.from_string(val) is ImageProperties.IMAGE_CREATION_PROGRESS + + +@pytest.mark.parametrize("val", ["image_id", "Image_Id", "ImAgE_Id", "id", "uuid"]) +def test_image_id_serialization(val): + """ + Tests that variants of IMAGE_ID can be serialized + """ + assert ImageProperties.from_string(val) is ImageProperties.IMAGE_ID + + +@pytest.mark.parametrize( + "val", + [ + "image_last_updated_date", + "Image_Last_Updated_Date", + "ImAgE_LaSt_UpDaTeD_DaTe", + "updated_at", + ], +) +def test_image_last_updated_date_serialization(val): + """ + Tests that variants of IMAGE_LAST_UPDATED_DATE can be serialized + """ + assert ImageProperties.from_string(val) is ImageProperties.IMAGE_LAST_UPDATED_DATE + + +@pytest.mark.parametrize( + "val", + ["image_minimum_ram", "Image_Minimum_RAM", "ImAgE_MiNiMuM_RaM", "min_ram", "ram"], +) +def test_image_minimum_ram_serialization(val): + """ + Tests that variants of IMAGE_MINIMUM_RAM can be serialized + """ + assert ImageProperties.from_string(val) is ImageProperties.IMAGE_MINIMUM_RAM + + +@pytest.mark.parametrize( + "val", + [ + "image_minimum_disk", + "Image_Minimum_Disk", + "ImAgE_MiNiMuM_DiSk", + "min_disk", + "disk", + ], +) +def test_image_minimum_disk_serialization(val): + """ + Tests that variants of IMAGE_MINIMUM_DISK can be serialized + """ + assert ImageProperties.from_string(val) is ImageProperties.IMAGE_MINIMUM_DISK + + +@pytest.mark.parametrize("val", ["image_name", "Image_Name", "ImAgE_NaMe", "name"]) +def test_image_name_serialization(val): + """ + Tests that variants of IMAGE_NAME can be serialized + """ + assert ImageProperties.from_string(val) is ImageProperties.IMAGE_NAME + + +@pytest.mark.parametrize("val", ["image_size", "Image_Size", "ImAgE_SiZe", "size"]) +def test_image_size_serialization(val): + """ + Tests that variants of IMAGE_SIZE can be serialized + """ + assert ImageProperties.from_string(val) is ImageProperties.IMAGE_SIZE + + +@pytest.mark.parametrize( + "val", ["image_status", "Image_Status", "ImAgE_StAtUs", "status"] +) +def test_image_status_serialization(val): + """ + Tests that variants of IMAGE_STATUS can be serialized + """ + assert ImageProperties.from_string(val) is ImageProperties.IMAGE_STATUS diff --git a/tests/enums/props/test_project_properties.py b/tests/enums/props/test_project_properties.py new file mode 100644 index 0000000..9b1566b --- /dev/null +++ b/tests/enums/props/test_project_properties.py @@ -0,0 +1,115 @@ +from unittest.mock import patch +import pytest + +from openstackquery.enums.props.project_properties import ProjectProperties +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) + +from tests.mocks.mocked_props import MockProperties + + +@pytest.mark.parametrize("prop", list(ProjectProperties)) +def test_get_prop_mapping(prop): + """ + Tests that all project properties have a property function mapping + """ + ProjectProperties.get_prop_mapping(prop) + + +def test_get_prop_mapping_invalid(): + """ + Tests that get_prop_mapping returns Error if property not supported + """ + with pytest.raises(QueryPropertyMappingError): + ProjectProperties.get_prop_mapping(MockProperties.PROP_1) + + +@patch( + "openstackquery.enums.props.project_properties.ProjectProperties.get_prop_mapping" +) +def test_get_marker_prop_func(mock_get_prop_mapping): + """ + Tests that marker_prop_func returns get_prop_mapping called with FLAVOR_ID + """ + val = ProjectProperties.get_marker_prop_func() + mock_get_prop_mapping.assert_called_once_with(ProjectProperties.PROJECT_ID) + assert val == mock_get_prop_mapping.return_value + + +@pytest.mark.parametrize( + "val", + [ + "project_description", + "Project_Description", + "PrOjEcT_DeScRiPtIoN", + "description", + "desc", + ], +) +def test_project_description_serialization(val): + """ + Tests that variants of PROJECT_DESCRIPTION can be serialized + """ + assert ProjectProperties.from_string(val) is ProjectProperties.PROJECT_DESCRIPTION + + +@pytest.mark.parametrize( + "val", ["project_domain_id", "Project_Domain_Id", "PrOjEcT_DoMaIn_Id", "domain_id"] +) +def test_project_domain_id_serialization(val): + """ + Tests that variants of PROJECT_DOMAIN_ID can be serialized + """ + assert ProjectProperties.from_string(val) is ProjectProperties.PROJECT_DOMAIN_ID + + +@pytest.mark.parametrize( + "val", ["project_id", "Project_Id", "PrOjEcT_Id", "id", "uuid"] +) +def test_project_id_serialization(val): + """ + Tests that variants of PROJECT_ID can be serialized + """ + assert ProjectProperties.from_string(val) is ProjectProperties.PROJECT_ID + + +@pytest.mark.parametrize( + "val", ["project_is_domain", "Project_Is_Domain", "PrOjEcT_Is_DoMaIn", "is_domain"] +) +def test_project_is_domain_serialization(val): + """ + Tests that variants of PROJECT_IS_DOMAIN can be serialized + """ + assert ProjectProperties.from_string(val) is ProjectProperties.PROJECT_IS_DOMAIN + + +@pytest.mark.parametrize( + "val", + ["project_is_enabled", "Project_Is_Enabled", "PrOjEcT_Is_EnAbLeD", "is_enabled"], +) +def test_project_is_enabled_serialization(val): + """ + Tests that variants of PROJECT_IS_ENABLED can be serialized + """ + assert ProjectProperties.from_string(val) is ProjectProperties.PROJECT_IS_ENABLED + + +@pytest.mark.parametrize( + "val", ["project_name", "Project_Name", "PrOjEcT_NaMe", "name"] +) +def test_project_name_serialization(val): + """ + Tests that variants of PROJECT_NAME can be serialized + """ + assert ProjectProperties.from_string(val) is ProjectProperties.PROJECT_NAME + + +@pytest.mark.parametrize( + "val", ["project_parent_id", "Project_Parent_Id", "PrOjEcT_PaReNt_Id", "parent_id"] +) +def test_project_parent_id_serialization(val): + """ + Tests that variants of PROJECT_NAME can be serialized + """ + assert ProjectProperties.from_string(val) is ProjectProperties.PROJECT_PARENT_ID diff --git a/tests/enums/props/test_server_properties.py b/tests/enums/props/test_server_properties.py new file mode 100644 index 0000000..9847a39 --- /dev/null +++ b/tests/enums/props/test_server_properties.py @@ -0,0 +1,203 @@ +from unittest.mock import patch +import pytest + +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) + +from tests.mocks.mocked_props import MockProperties + + +@pytest.mark.parametrize("prop", list(ServerProperties)) +def test_get_prop_mapping(prop): + """ + Tests that all server properties have a property function mapping + """ + ServerProperties.get_prop_mapping(prop) + + +def test_get_prop_mapping_invalid(): + """ + Tests that get_prop_mapping returns Error if property not supported + """ + with pytest.raises(QueryPropertyMappingError): + ServerProperties.get_prop_mapping(MockProperties.PROP_1) + + +@patch("openstackquery.enums.props.server_properties.ServerProperties.get_prop_mapping") +def test_get_marker_prop_func(mock_get_prop_mapping): + """ + Tests that marker_prop_func returns get_prop_mapping called with SERVER_ID + """ + val = ServerProperties.get_marker_prop_func() + mock_get_prop_mapping.assert_called_once_with(ServerProperties.SERVER_ID) + assert val == mock_get_prop_mapping.return_value + + +@pytest.mark.parametrize("val", ["flavor_id", "Flavor_ID", "FlAvOr_Id"]) +def test_flavor_id_serialization(val): + """ + Tests that variants of FLAVOR_ID can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.FLAVOR_ID + + +@pytest.mark.parametrize( + "val", ["hypervisor_id", "Hypervisor_ID", "HyPerVisor_ID", "host_id", "hv_id"] +) +def test_hypervisor_id_serialization(val): + """ + Tests that variants of HYPERVISOR_ID can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.HYPERVISOR_ID + + +@pytest.mark.parametrize("val", ["image_id", "Image_ID", "ImaGe_iD"]) +def test_image_id_serialization(val): + """ + Tests that variants of IMAGE_ID can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.IMAGE_ID + + +@pytest.mark.parametrize("val", ["project_id", "Project_Id", "PrOjEcT_Id"]) +def test_project_id_serialization(val): + """ + Tests that variants of PROJECT_ID can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.PROJECT_ID + + +@pytest.mark.parametrize( + "val", + [ + "server_creation_date", + "Server_Creation_Date", + "SeRvEr_CrEaTiOn_DAte", + "created_at", + ], +) +def test_server_creation_date_serialization(val): + """ + Tests that variants of SERVER_CREATION_DATE can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.SERVER_CREATION_DATE + + +@pytest.mark.parametrize( + "val", + ["server_description", "Server_Description", "SeRvEr_DeScrIpTion", "description"], +) +def test_server_description_serialization(val): + """ + Tests that variants of SERVER_DESCRIPTION can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.SERVER_DESCRIPTION + + +@pytest.mark.parametrize( + "val", ["server_id", "Server_Id", "SeRvEr_iD", "vm_id", "id", "uuid"] +) +def test_server_id_serialization(val): + """ + Tests that variants of SERVER_ID can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.SERVER_ID + + +@pytest.mark.parametrize( + "val", + [ + "server_last_updated_date", + "Server_Last_Updated_Date", + "SerVer_LasT_UpDatED_DaTe", + "updated_at", + ], +) +def test_server_last_updated_date_serialization(val): + """ + Tests that variants of SERVER_LAST_UPDATED_DATE can be serialized + """ + assert ( + ServerProperties.from_string(val) is ServerProperties.SERVER_LAST_UPDATED_DATE + ) + + +@pytest.mark.parametrize( + "val", ["server_name", "Server_NaMe", "Server_Name", "vm_name", "name"] +) +def test_server_name_serialization(val): + """ + Tests that variants of SERVER_NAME can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.SERVER_NAME + + +@pytest.mark.parametrize( + "val", ["server_status", "Server_Status", "SerVer_StAtUs", "status", "vm_status"] +) +def test_server_status_serialization(val): + """ + Tests that variants of SERVER_STATUS can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.SERVER_STATUS + + +@pytest.mark.parametrize("val", ["user_id", "User_Id", "UsEr_iD"]) +def test_user_id_serialization(val): + """ + Tests that variants of USER_ID can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.USER_ID + + +@pytest.mark.parametrize( + "val", ["addresses", "Addresses", "AdDreSSeS", "ips", "vm_ips", "server_ips"] +) +def test_addresses_serialization(val): + """ + Tests that variants of ADDRESSES can be serialized + """ + assert ServerProperties.from_string(val) is ServerProperties.ADDRESSES + + +def test_invalid_serialization(): + """ + Tests that error is raised when passes invalid string to all preset classes + """ + with pytest.raises(ParseQueryError): + ServerProperties.from_string("some-invalid-string") + + +def test_get_ips_with_valid_data(): + """ + Tests that get_ips works expectedly + should get comma-spaced ips for each network in addresses + """ + # Create a sample object with addresses + obj = { + "addresses": { + "network1": [{"addr": "192.168.1.1"}, {"addr": "192.168.1.2"}], + "network2": [{"addr": "10.0.0.1"}], + } + } + + # Call the get_ips method + result = ServerProperties.get_ips(obj) + + # Check if the result is as expected + expected_result = "192.168.1.1, 192.168.1.2, 10.0.0.1" + assert result == expected_result + + +def test_get_ips_with_empty_data(): + """ + Tests that get_pis works expectedly + should return empty string if addresses is empty + """ + # Test with an empty object + obj = {"addresses": {}} + result = ServerProperties.get_ips(obj) + assert result == "" diff --git a/tests/enums/props/test_user_properties.py b/tests/enums/props/test_user_properties.py new file mode 100644 index 0000000..d52fff6 --- /dev/null +++ b/tests/enums/props/test_user_properties.py @@ -0,0 +1,102 @@ +from unittest.mock import patch +import pytest + +from openstackquery.enums.props.user_properties import UserProperties +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) + +from tests.mocks.mocked_props import MockProperties + + +@pytest.mark.parametrize("prop", list(UserProperties)) +def test_get_prop_mapping(prop): + """ + Tests that all user properties have a property function mapping + """ + UserProperties.get_prop_mapping(prop) + + +def test_get_prop_mapping_invalid(): + """ + Tests that get_prop_mapping returns Error if property not supported + """ + with pytest.raises(QueryPropertyMappingError): + UserProperties.get_prop_mapping(MockProperties.PROP_1) + + +@patch("openstackquery.enums.props.user_properties.UserProperties.get_prop_mapping") +def test_get_marker_prop_func(mock_get_prop_mapping): + """ + Tests that marker_prop_func returns get_prop_mapping called with USER_ID + """ + val = UserProperties.get_marker_prop_func() + mock_get_prop_mapping.assert_called_once_with(UserProperties.USER_ID) + assert val == mock_get_prop_mapping.return_value + + +@pytest.mark.parametrize( + "val", ["user_domain_id", "User_Domain_ID", "UsEr_DoMaIn_iD", "domain_id"] +) +def test_user_domain_id_serialization(val): + """ + Tests that variants of USER_DOMAIN_ID can be serialized + """ + assert UserProperties.from_string(val) is UserProperties.USER_DOMAIN_ID + + +@pytest.mark.parametrize( + "val", + [ + "USER_EMAIL", + "User_Email", + "UsEr_EmAiL", + "email", + "email_addr", + "email_address", + "user_email_address", + ], +) +def test_user_email_serialization(val): + """ + Tests that variants of USER_EMAIL can be serialized + """ + assert UserProperties.from_string(val) is UserProperties.USER_EMAIL + + +@pytest.mark.parametrize( + "val", + ["USER_DESCRIPTION", "User_Description", "UsEr_DeScRiPtIoN", "description", "desc"], +) +def test_user_description_serialization(val): + """ + Tests that variants of USER_DESCRIPTION can be serialized + """ + assert UserProperties.from_string(val) is UserProperties.USER_DESCRIPTION + + +@pytest.mark.parametrize("val", ["USER_ID", "User_Id", "UsEr_Id", "id", "uuid"]) +def test_user_id_serialization(val): + """ + Tests that variants of USER_ID can be serialized + """ + assert UserProperties.from_string(val) is UserProperties.USER_ID + + +@pytest.mark.parametrize( + "val", ["USER_NAME", "User_Name", "UsEr_NaMe", "name", "username"] +) +def test_user_name_serialization(val): + """ + Tests that variants of USER_NAME can be serialized + """ + assert UserProperties.from_string(val) is UserProperties.USER_NAME + + +def test_invalid_serialization(): + """ + Tests that error is raised when passes invalid string to all preset classes + """ + with pytest.raises(ParseQueryError): + UserProperties.from_string("some-invalid-string") diff --git a/tests/enums/test_query_output_types.py b/tests/enums/test_query_output_types.py new file mode 100644 index 0000000..60ab3ee --- /dev/null +++ b/tests/enums/test_query_output_types.py @@ -0,0 +1,46 @@ +import pytest + +from openstackquery.enums.query_output_types import QueryOutputTypes +from openstackquery.exceptions.parse_query_error import ParseQueryError + + +@pytest.mark.parametrize("output_type", ["to_HTML", "To_HtMl", "to_html"]) +def test_to_html_serialization(output_type): + """ + Tests that variants of TO_HTML can be serialized + """ + assert QueryOutputTypes.from_string(output_type) is QueryOutputTypes.TO_HTML + + +@pytest.mark.parametrize( + "output_type", ["to_OBJECT_LIST", "To_ObJecT_LisT", "to_object_list"] +) +def test_to_object_list_serialization(output_type): + """ + Tests that variants of TO_OBJECT_LIST can be serialized + """ + assert QueryOutputTypes.from_string(output_type) is QueryOutputTypes.TO_OBJECT_LIST + + +@pytest.mark.parametrize("output_type", ["to_LIST", "To_LiSt", "to_list"]) +def test_to_list_serialization(output_type): + """ + Tests that variants of TO_LIST can be serialized + """ + assert QueryOutputTypes.from_string(output_type) is QueryOutputTypes.TO_LIST + + +@pytest.mark.parametrize("output_type", ["to_Str", "To_StR", "to_str"]) +def test_to_str_serialization(output_type): + """ + Tests that variants of TO_STR can be serialized + """ + assert QueryOutputTypes.from_string(output_type) is QueryOutputTypes.TO_STR + + +def test_invalid_serialization(): + """ + Tests that error is raised when passes invalid string + """ + with pytest.raises(ParseQueryError): + QueryOutputTypes.from_string("some-invalid-string") diff --git a/tests/enums/test_query_presets.py b/tests/enums/test_query_presets.py new file mode 100644 index 0000000..c6aedd0 --- /dev/null +++ b/tests/enums/test_query_presets.py @@ -0,0 +1,218 @@ +import pytest + +from openstackquery.enums.query_presets import ( + QueryPresetsGeneric, + QueryPresetsInteger, + QueryPresetsString, + QueryPresetsDateTime, + get_preset_from_string, +) +from openstackquery.exceptions.parse_query_error import ParseQueryError + + +@pytest.mark.parametrize( + "preset_string", ["equal_to", "Equal_To", "EqUaL_tO", "equal", "=="] +) +def test_equal_to_serialization(preset_string): + """ + Tests that variants of EQUAL_TO can be serialized + """ + assert ( + QueryPresetsGeneric.from_string(preset_string) is QueryPresetsGeneric.EQUAL_TO + ) + + +@pytest.mark.parametrize( + "preset_string", ["not_equal_to", "Not_Equal_To", "NoT_EqUaL_tO", "not_equal", "!="] +) +def test_not_equal_to_serialization(preset_string): + """ + Tests that variants of NOT_EQUAL_TO can be serialized + """ + assert ( + QueryPresetsGeneric.from_string(preset_string) + is QueryPresetsGeneric.NOT_EQUAL_TO + ) + + +@pytest.mark.parametrize( + "preset_string", ["greater_than", "Greater_Than", "GrEaTer_ThAn"] +) +def test_greater_than_serialization(preset_string): + """ + Tests that variants of GREATER_THAN can be serialized + """ + assert ( + QueryPresetsInteger.from_string(preset_string) + is QueryPresetsInteger.GREATER_THAN + ) + + +@pytest.mark.parametrize( + "preset_string", + [ + "greater_than_or_equal_to", + "Greater_Than_Or_Equal_To", + "GrEaTer_ThAn_Or_EqUaL_tO", + ], +) +def test_greater_than_or_equal_to_serialization(preset_string): + """ + Tests that variants of GREATER_THAN_OR_EQUAL_TO can be serialized + """ + assert ( + QueryPresetsInteger.from_string(preset_string) + is QueryPresetsInteger.GREATER_THAN_OR_EQUAL_TO + ) + + +@pytest.mark.parametrize("preset_string", ["less_than", "Less_Than", "LeSs_ThAn"]) +def test_less_than_serialization(preset_string): + """ + Tests that variants of LESS_THAN can be serialized + """ + assert ( + QueryPresetsInteger.from_string(preset_string) is QueryPresetsInteger.LESS_THAN + ) + + +@pytest.mark.parametrize( + "preset_string", + ["less_than_or_equal_to", "Less_Than_Or_Equal_To", "LeSs_ThAn_Or_EqUaL_tO"], +) +def test_less_than_or_equal_to_serialization(preset_string): + """ + Tests that variants of LESS_THAN_OR_EQUAL_TO can be serialized + """ + assert ( + QueryPresetsInteger.from_string(preset_string) + is QueryPresetsInteger.LESS_THAN_OR_EQUAL_TO + ) + + +@pytest.mark.parametrize("preset_string", ["older_than", "Older_Than", "OlDeR_ThAn"]) +def test_older_than_serialization(preset_string): + """ + Tests that variants of OLDER_THAN can be serialized + """ + assert ( + QueryPresetsDateTime.from_string(preset_string) + is QueryPresetsDateTime.OLDER_THAN + ) + + +@pytest.mark.parametrize( + "preset_string", + ["older_than_or_equal_to", "Older_Than_Or_Equal_To", "OlDeR_ThAn_Or_EqUaL_To"], +) +def test_older_than_or_equal_to_serialization(preset_string): + """ + Tests that variants of OLDER_THAN_OR_EQUAL_TO can be serialized + """ + assert ( + QueryPresetsDateTime.from_string(preset_string) + is QueryPresetsDateTime.OLDER_THAN_OR_EQUAL_TO + ) + + +@pytest.mark.parametrize( + "preset_string", ["younger_than", "Younger_Than", "YoUnGeR_ThAn"] +) +def test_younger_than_serialization(preset_string): + """ + Tests that variants of YOUNGER_THAN can be serialized + """ + assert ( + QueryPresetsDateTime.from_string(preset_string) + is QueryPresetsDateTime.YOUNGER_THAN + ) + + +@pytest.mark.parametrize( + "preset_string", + [ + "younger_than_or_equal_to", + "Younger_Than_Or_Equal_To", + "YoUngEr_ThAn_Or_EqUaL_To", + ], +) +def test_younger_than_or_equal_to_serialization(preset_string): + """ + Tests that variants of YOUNGER_THAN_OR_EQUAL_TO can be serialized + """ + assert ( + QueryPresetsDateTime.from_string(preset_string) + is QueryPresetsDateTime.YOUNGER_THAN_OR_EQUAL_TO + ) + + +@pytest.mark.parametrize("preset_string", ["any_in", "Any_In", "AnY_In", "in"]) +def test_any_in_serialization(preset_string): + """ + Tests that variants of ANY_IN can be serialized + """ + assert QueryPresetsGeneric.from_string(preset_string) is QueryPresetsGeneric.ANY_IN + + +@pytest.mark.parametrize( + "preset_string", ["not_any_in", "Not_Any_In", "NoT_AnY_In", "not_in"] +) +def test_not_any_in_serialization(preset_string): + """ + Tests that variants of NOT_ANY_IN can be serialized + """ + assert ( + QueryPresetsGeneric.from_string(preset_string) is QueryPresetsGeneric.NOT_ANY_IN + ) + + +@pytest.mark.parametrize( + "preset_string", + ["matches_regex", "Matches_Regex", "MaTcHeS_ReGeX", "regex", "match_regex"], +) +def test_matches_regex_serialization(preset_string): + """ + Tests that variants of MATCHES_REGEX can be serialized + """ + assert ( + QueryPresetsString.from_string(preset_string) + is QueryPresetsString.MATCHES_REGEX + ) + + +def test_invalid_serialization(): + """ + Tests that error is raised when passes invalid string to all preset classes + """ + for enum_cls in [ + QueryPresetsInteger, + QueryPresetsString, + QueryPresetsDateTime, + QueryPresetsGeneric, + ]: + with pytest.raises(ParseQueryError): + enum_cls.from_string("some-invalid-string") + + +@pytest.mark.parametrize( + "alias, expected_preset", + [ + ("equal_to", QueryPresetsGeneric.EQUAL_TO), + ("matches_regex", QueryPresetsString.MATCHES_REGEX), + ("older_than", QueryPresetsDateTime.OLDER_THAN), + ("greater_than", QueryPresetsInteger.GREATER_THAN), + ], +) +def test_get_preset_from_string_valid(alias, expected_preset): + """ + Tests that get_preset_from_string works for a valid preset alias from each preset type + """ + assert get_preset_from_string(alias) == expected_preset + + +def test_get_preset_from_string_invalid(): + """ + Tests that get_preset_from_string returns error if given an invalid alias + """ + with pytest.raises(ParseQueryError): + get_preset_from_string("invalid-alias") diff --git a/tests/enums/test_query_types.py b/tests/enums/test_query_types.py new file mode 100644 index 0000000..1789c5c --- /dev/null +++ b/tests/enums/test_query_types.py @@ -0,0 +1,114 @@ +import pytest + +from openstackquery.enums.query_types import QueryTypes +from openstackquery.exceptions.parse_query_error import ParseQueryError + + +@pytest.mark.parametrize( + "query_type", + [ + "Flavor_Query", + "FlAvOr_Query", + "flavor_query", + "flavor", + "flavors", + ], +) +def test_flavor_query_serialization(query_type): + """ + Tests that variants of FLAVOR_QUERY can be serialized + """ + assert QueryTypes.from_string(query_type) is QueryTypes.FLAVOR_QUERY + + +@pytest.mark.parametrize( + "query_type", + [ + "Server_Query", + "SeRvEr_QuErY", + "server_query", + "server", + "servers", + ], +) +def test_server_query_serialization(query_type): + """ + Tests that variants of SERVER_QUERY can be serialized + """ + assert QueryTypes.from_string(query_type) is QueryTypes.SERVER_QUERY + + +@pytest.mark.parametrize( + "query_type", + [ + "Project_Query", + "PrOjEcT_Query", + "project_query", + "project", + "projects", + ], +) +def test_project_query_serialization(query_type): + """ + Tests that variants of PROJECT_QUERY can be serialized + """ + assert QueryTypes.from_string(query_type) is QueryTypes.PROJECT_QUERY + + +@pytest.mark.parametrize( + "query_type", + [ + "User_Query", + "UsEr_QuEry", + "user_query", + "user", + "users", + ], +) +def test_user_query_serialization(query_type): + """ + Tests that variants of USER_QUERY can be serialized + """ + assert QueryTypes.from_string(query_type) is QueryTypes.USER_QUERY + + +@pytest.mark.parametrize( + "query_type", + [ + "Image_Query", + "ImAgE_QuEry", + "image_query", + "image", + "images", + ], +) +def test_image_query_serialization(query_type): + """ + Tests that variants of IMAGE_QUERY can be serialized + """ + assert QueryTypes.from_string(query_type) is QueryTypes.IMAGE_QUERY + + +@pytest.mark.parametrize( + "query_type", + [ + "Hypervisor_Query", + "HyPeRvIsOr_QuErY", + "hypervisor_query", + "hypervisor", + "hypervisors", + ], +) +def test_hypervisor_query_serialization(query_type): + """ + Tests that variants of HYPERVISOR_QUERY can be serialized + """ + assert QueryTypes.from_string(query_type) is QueryTypes.HYPERVISOR_QUERY + + +def test_invalid_serialization(): + """ + Tests that error is raised when passes invalid string + """ + with pytest.raises(ParseQueryError): + QueryTypes.from_string("some-invalid-string") diff --git a/tests/enums/test_sort_order.py b/tests/enums/test_sort_order.py new file mode 100644 index 0000000..15592d2 --- /dev/null +++ b/tests/enums/test_sort_order.py @@ -0,0 +1,28 @@ +import pytest + +from openstackquery.enums.sort_order import SortOrder +from openstackquery.exceptions.parse_query_error import ParseQueryError + + +@pytest.mark.parametrize("sort_order_type", ["asc", "Asc", "Ascending"]) +def test_asc_serialization(sort_order_type): + """ + Tests that variants of ASC can be serialized + """ + assert SortOrder.from_string(sort_order_type) is SortOrder.ASC + + +@pytest.mark.parametrize("sort_order_type", ["desc", "Desc", "Descending"]) +def test_desc_serialization(sort_order_type): + """ + Tests that variants of DESC can be serialized + """ + assert SortOrder.from_string(sort_order_type) is SortOrder.DESC + + +def test_get_preset_from_string_invalid(): + """ + Tests that error is raised when passed invalid string + """ + with pytest.raises(ParseQueryError): + SortOrder.from_string("some-invalid-string") diff --git a/tests/handlers/test_client_side_handler.py b/tests/handlers/test_client_side_handler.py index cda7d1b..7789908 100644 --- a/tests/handlers/test_client_side_handler.py +++ b/tests/handlers/test_client_side_handler.py @@ -2,10 +2,10 @@ import pytest -from exceptions.parse_query_error import ParseQueryError -from exceptions.query_preset_mapping_error import QueryPresetMappingError +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.exceptions.query_preset_mapping_error import QueryPresetMappingError -from handlers.client_side_handler import ClientSideHandler +from openstackquery.handlers.client_side_handler import ClientSideHandler from tests.mocks.mocked_query_presets import MockQueryPresets from tests.mocks.mocked_props import MockProperties @@ -223,9 +223,7 @@ def test_get_filter_func_prop_invalid(instance): ) -@pytest.mark.parametrize( - "error_type", [ParseQueryError, TypeError, NameError] -) +@pytest.mark.parametrize("error_type", [ParseQueryError, TypeError, NameError]) def test_get_filter_func_filter_raises_error(error_type, instance, mock_filter): """ Tests get_filter_func method when filter function raises an error. diff --git a/tests/handlers/test_client_side_handler_datetime.py b/tests/handlers/test_client_side_handler_datetime.py index 9b84e5d..aa8cf7a 100644 --- a/tests/handlers/test_client_side_handler_datetime.py +++ b/tests/handlers/test_client_side_handler_datetime.py @@ -1,10 +1,10 @@ from unittest.mock import patch, NonCallableMock, MagicMock, call import pytest -from handlers.client_side_handler_datetime import ( +from openstackquery.handlers.client_side_handler_datetime import ( ClientSideHandlerDateTime, ) -from enums.query_presets import QueryPresetsDateTime +from openstackquery.enums.query_presets import QueryPresetsDateTime from tests.mocks.mocked_props import MockProperties @@ -27,8 +27,8 @@ def run_prop_test_case_fixture(instance): fixture to run a test cases for each client-side filter function """ - @patch("time_utils.TimeUtils.get_timestamp_in_seconds") - @patch("handlers.client_side_handler_datetime.datetime") + @patch("openstackquery.time_utils.TimeUtils.get_timestamp_in_seconds") + @patch("openstackquery.handlers.client_side_handler_datetime.datetime") def _run_prop_test_case( preset_to_test, prop_value, to_compare, mock_datetime, mock_get_timestamp ): diff --git a/tests/handlers/test_client_side_handler_generic.py b/tests/handlers/test_client_side_handler_generic.py index 5d1d282..3ea8c6f 100644 --- a/tests/handlers/test_client_side_handler_generic.py +++ b/tests/handlers/test_client_side_handler_generic.py @@ -1,11 +1,11 @@ from unittest.mock import NonCallableMock, MagicMock import pytest -from exceptions.query_preset_mapping_error import QueryPresetMappingError -from handlers.client_side_handler_generic import ( +from openstackquery.exceptions.query_preset_mapping_error import QueryPresetMappingError +from openstackquery.handlers.client_side_handler_generic import ( ClientSideHandlerGeneric, ) -from enums.query_presets import QueryPresetsGeneric +from openstackquery.enums.query_presets import QueryPresetsGeneric from tests.mocks.mocked_props import MockProperties diff --git a/tests/handlers/test_client_side_handler_integer.py b/tests/handlers/test_client_side_handler_integer.py index 83577a5..55b5d3f 100644 --- a/tests/handlers/test_client_side_handler_integer.py +++ b/tests/handlers/test_client_side_handler_integer.py @@ -1,10 +1,10 @@ from unittest.mock import NonCallableMock, MagicMock import pytest -from handlers.client_side_handler_integer import ( +from openstackquery.handlers.client_side_handler_integer import ( ClientSideHandlerInteger, ) -from enums.query_presets import QueryPresetsInteger +from openstackquery.enums.query_presets import QueryPresetsInteger from tests.mocks.mocked_props import MockProperties diff --git a/tests/handlers/test_client_side_handler_string.py b/tests/handlers/test_client_side_handler_string.py index 3d702e2..c0df78a 100644 --- a/tests/handlers/test_client_side_handler_string.py +++ b/tests/handlers/test_client_side_handler_string.py @@ -1,8 +1,8 @@ from unittest.mock import NonCallableMock, MagicMock import pytest -from enums.query_presets import QueryPresetsString -from handlers.client_side_handler_string import ClientSideHandlerString +from openstackquery.enums.query_presets import QueryPresetsString +from openstackquery.handlers.client_side_handler_string import ClientSideHandlerString from tests.mocks.mocked_props import MockProperties diff --git a/tests/handlers/test_server_side_handler.py b/tests/handlers/test_server_side_handler.py index 0eeb792..51cc72e 100644 --- a/tests/handlers/test_server_side_handler.py +++ b/tests/handlers/test_server_side_handler.py @@ -2,8 +2,8 @@ import pytest -from exceptions.query_preset_mapping_error import QueryPresetMappingError -from handlers.server_side_handler import ServerSideHandler +from openstackquery.exceptions.query_preset_mapping_error import QueryPresetMappingError +from openstackquery.handlers.server_side_handler import ServerSideHandler from tests.mocks.mocked_props import MockProperties from tests.mocks.mocked_query_presets import MockQueryPresets diff --git a/tests/mappings/conftest.py b/tests/mappings/conftest.py index 2a863ae..2259e32 100644 --- a/tests/mappings/conftest.py +++ b/tests/mappings/conftest.py @@ -1,11 +1,11 @@ from typing import Dict, List, Tuple import pytest -from aliases import PresetPropMappings -from enums.props.prop_enum import PropEnum -from enums.query_presets import QueryPresets, QueryPresetsGeneric -from handlers.client_side_handler import ClientSideHandler -from handlers.server_side_handler import ServerSideHandler +from openstackquery.aliases import PresetPropMappings +from openstackquery.enums.props.prop_enum import PropEnum +from openstackquery.enums.query_presets import QueryPresets, QueryPresetsGeneric +from openstackquery.handlers.client_side_handler import ClientSideHandler +from openstackquery.handlers.server_side_handler import ServerSideHandler @pytest.fixture(scope="function", name="client_side_test_mappings") diff --git a/tests/mappings/test_flavor_mapping.py b/tests/mappings/test_flavor_mapping.py index 978a963..2b95d49 100644 --- a/tests/mappings/test_flavor_mapping.py +++ b/tests/mappings/test_flavor_mapping.py @@ -1,13 +1,13 @@ -from enums.props.flavor_properties import FlavorProperties -from enums.props.server_properties import ServerProperties -from enums.query_presets import ( +from openstackquery.enums.props.flavor_properties import FlavorProperties +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsString, QueryPresetsInteger, ) -from handlers.server_side_handler import ServerSideHandler -from mappings.flavor_mapping import FlavorMapping -from runners.flavor_runner import FlavorRunner +from openstackquery.handlers.server_side_handler import ServerSideHandler +from openstackquery.mappings.flavor_mapping import FlavorMapping +from openstackquery.runners.flavor_runner import FlavorRunner def test_get_runner_mapping(): diff --git a/tests/mappings/test_hypervisor_mapping.py b/tests/mappings/test_hypervisor_mapping.py index 9b86b91..b2fdb83 100644 --- a/tests/mappings/test_hypervisor_mapping.py +++ b/tests/mappings/test_hypervisor_mapping.py @@ -1,13 +1,13 @@ -from enums.props.hypervisor_properties import HypervisorProperties -from enums.props.server_properties import ServerProperties -from enums.query_presets import ( +from openstackquery.enums.props.hypervisor_properties import HypervisorProperties +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsString, QueryPresetsInteger, ) -from handlers.server_side_handler import ServerSideHandler -from mappings.hypervisor_mapping import HypervisorMapping -from runners.hypervisor_runner import HypervisorRunner +from openstackquery.handlers.server_side_handler import ServerSideHandler +from openstackquery.mappings.hypervisor_mapping import HypervisorMapping +from openstackquery.runners.hypervisor_runner import HypervisorRunner def test_get_runner_mapping(): diff --git a/tests/mappings/test_image_mapping.py b/tests/mappings/test_image_mapping.py index 719db88..8063657 100644 --- a/tests/mappings/test_image_mapping.py +++ b/tests/mappings/test_image_mapping.py @@ -1,16 +1,16 @@ from unittest.mock import patch -from enums.props.server_properties import ServerProperties -from enums.props.image_properties import ImageProperties -from enums.query_presets import ( +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.props.image_properties import ImageProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsString, QueryPresetsInteger, QueryPresetsDateTime, ) -from handlers.server_side_handler import ServerSideHandler -from mappings.image_mapping import ImageMapping -from runners.image_runner import ImageRunner +from openstackquery.handlers.server_side_handler import ServerSideHandler +from openstackquery.mappings.image_mapping import ImageMapping +from openstackquery.runners.image_runner import ImageRunner def test_get_runner_mapping(): @@ -74,7 +74,7 @@ def test_server_side_handler_mappings_any_in(server_side_any_in_mappings): ) -@patch("mappings.image_mapping.TimeUtils") +@patch("openstackquery.mappings.image_mapping.TimeUtils") def test_server_side_handler_mappings_older_than_or_equal_to( mock_time_utils, server_side_test_mappings ): @@ -96,7 +96,7 @@ def test_server_side_handler_mappings_older_than_or_equal_to( ) -@patch("mappings.image_mapping.TimeUtils") +@patch("openstackquery.mappings.image_mapping.TimeUtils") def test_server_side_handler_mappings_older_than( mock_time_utils, server_side_test_mappings ): @@ -118,7 +118,7 @@ def test_server_side_handler_mappings_older_than( ) -@patch("mappings.image_mapping.TimeUtils") +@patch("openstackquery.mappings.image_mapping.TimeUtils") def test_server_side_handler_mappings_younger_than_or_equal_to( mock_time_utils, server_side_test_mappings ): @@ -140,7 +140,7 @@ def test_server_side_handler_mappings_younger_than_or_equal_to( ) -@patch("mappings.image_mapping.TimeUtils") +@patch("openstackquery.mappings.image_mapping.TimeUtils") def test_server_side_handler_mappings_younger_than( mock_time_utils, server_side_test_mappings ): diff --git a/tests/mappings/test_project_mapping.py b/tests/mappings/test_project_mapping.py index 74d719d..86a91ed 100644 --- a/tests/mappings/test_project_mapping.py +++ b/tests/mappings/test_project_mapping.py @@ -1,12 +1,12 @@ -from enums.props.project_properties import ProjectProperties -from enums.props.server_properties import ServerProperties -from enums.query_presets import ( +from openstackquery.enums.props.project_properties import ProjectProperties +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsString, ) -from handlers.server_side_handler import ServerSideHandler -from mappings.project_mapping import ProjectMapping -from runners.project_runner import ProjectRunner +from openstackquery.handlers.server_side_handler import ServerSideHandler +from openstackquery.mappings.project_mapping import ProjectMapping +from openstackquery.runners.project_runner import ProjectRunner def test_get_runner_mapping(): diff --git a/tests/mappings/test_server_mapping.py b/tests/mappings/test_server_mapping.py index e4c4908..b1f0d28 100644 --- a/tests/mappings/test_server_mapping.py +++ b/tests/mappings/test_server_mapping.py @@ -1,19 +1,19 @@ from unittest.mock import patch -from enums.props.flavor_properties import FlavorProperties -from enums.props.hypervisor_properties import HypervisorProperties -from enums.props.image_properties import ImageProperties -from enums.props.project_properties import ProjectProperties -from enums.props.server_properties import ServerProperties -from enums.props.user_properties import UserProperties -from enums.query_presets import ( +from openstackquery.enums.props.flavor_properties import FlavorProperties +from openstackquery.enums.props.hypervisor_properties import HypervisorProperties +from openstackquery.enums.props.image_properties import ImageProperties +from openstackquery.enums.props.project_properties import ProjectProperties +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.props.user_properties import UserProperties +from openstackquery.enums.query_presets import ( QueryPresetsGeneric, QueryPresetsDateTime, QueryPresetsString, ) -from handlers.server_side_handler import ServerSideHandler -from mappings.server_mapping import ServerMapping -from runners.server_runner import ServerRunner +from openstackquery.handlers.server_side_handler import ServerSideHandler +from openstackquery.mappings.server_mapping import ServerMapping +from openstackquery.runners.server_runner import ServerRunner def test_get_runner_mapping(): @@ -89,7 +89,7 @@ def test_server_side_handler_mappings_any_in(server_side_any_in_mappings): ) -@patch("mappings.server_mapping.TimeUtils") +@patch("openstackquery.mappings.server_mapping.TimeUtils") def test_server_side_handler_mappings_older_than_or_equal_to( mock_time_utils, server_side_test_mappings ): @@ -112,7 +112,7 @@ def test_server_side_handler_mappings_older_than_or_equal_to( mock_time_utils.convert_to_timestamp.assert_called_once_with(value="test") -@patch("mappings.server_mapping.TimeUtils") +@patch("openstackquery.mappings.server_mapping.TimeUtils") def test_server_side_handler_mappings_younger_than_or_equal_to( mock_time_utils, server_side_test_mappings ): diff --git a/tests/mappings/test_user_mapping.py b/tests/mappings/test_user_mapping.py index 251b12f..da5006e 100644 --- a/tests/mappings/test_user_mapping.py +++ b/tests/mappings/test_user_mapping.py @@ -1,9 +1,9 @@ -from enums.props.server_properties import ServerProperties -from enums.props.user_properties import UserProperties -from enums.query_presets import QueryPresetsGeneric, QueryPresetsString -from handlers.server_side_handler import ServerSideHandler -from mappings.user_mapping import UserMapping -from runners.user_runner import UserRunner +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.props.user_properties import UserProperties +from openstackquery.enums.query_presets import QueryPresetsGeneric, QueryPresetsString +from openstackquery.handlers.server_side_handler import ServerSideHandler +from openstackquery.mappings.user_mapping import UserMapping +from openstackquery.runners.user_runner import UserRunner def test_get_runner_mapping(): diff --git a/tests/mocks/mocked_props.py b/tests/mocks/mocked_props.py index 738524d..baa5130 100644 --- a/tests/mocks/mocked_props.py +++ b/tests/mocks/mocked_props.py @@ -1,7 +1,10 @@ -from enums.props.prop_enum import PropEnum +from openstackquery.enums.props.prop_enum import PropEnum # pylint:disable=too-few-public-methods +# We're just using this for testing so we're not worried about implementing abstract methods +# pylint:disable=abstract-method + class MockProperties(PropEnum): """ diff --git a/tests/mocks/mocked_query_presets.py b/tests/mocks/mocked_query_presets.py index aa960c6..c1c01f6 100644 --- a/tests/mocks/mocked_query_presets.py +++ b/tests/mocks/mocked_query_presets.py @@ -1,5 +1,5 @@ from typing import Dict -from enums.enum_with_aliases import EnumWithAliases +from openstackquery.enums.enum_with_aliases import EnumWithAliases # pylint:disable=too-few-public-methods diff --git a/tests/mocks/mocked_structs.py b/tests/mocks/mocked_structs.py index 8da3ccb..6d7469a 100644 --- a/tests/mocks/mocked_structs.py +++ b/tests/mocks/mocked_structs.py @@ -1,10 +1,10 @@ -from structs.query_preset_details import QueryPresetDetails -from structs.query_output_details import QueryOutputDetails +from openstackquery.structs.query_preset_details import QueryPresetDetails +from openstackquery.structs.query_output_details import QueryOutputDetails -from enums.query_output_types import QueryOutputTypes +from openstackquery.enums.query_output_types import QueryOutputTypes -from tests.lib.mocks.mocked_props import MockProperties -from tests.lib.mocks.mocked_query_presets import MockQueryPresets +from tests.mocks.mocked_props import MockProperties +from tests.mocks.mocked_query_presets import MockQueryPresets # Mocked Preset Details Dataclass object - which uses mocked Prop and Preset Enums MOCKED_PRESET_DETAILS = QueryPresetDetails( diff --git a/tests/query_blocks/test_query_builder.py b/tests/query_blocks/test_query_builder.py index 6974b03..baa4a15 100644 --- a/tests/query_blocks/test_query_builder.py +++ b/tests/query_blocks/test_query_builder.py @@ -1,10 +1,12 @@ from unittest.mock import MagicMock, patch, NonCallableMock import pytest -from query_blocks.query_builder import QueryBuilder +from openstackquery.query_blocks.query_builder import QueryBuilder -from exceptions.query_preset_mapping_error import QueryPresetMappingError -from exceptions.query_property_mapping_error import QueryPropertyMappingError +from openstackquery.exceptions.query_preset_mapping_error import QueryPresetMappingError +from openstackquery.exceptions.query_property_mapping_error import ( + QueryPropertyMappingError, +) from tests.mocks.mocked_query_presets import MockQueryPresets from tests.mocks.mocked_props import MockProperties @@ -393,7 +395,7 @@ def test_server_filter_fallback(instance): assert res == ["some-client-side-filter"] -@patch("query_blocks.query_builder.get_preset_from_string") +@patch("openstackquery.query_blocks.query_builder.get_preset_from_string") def test_parse_where_with_string_aliases( mock_get_preset_from_string, instance, diff --git a/tests/query_blocks/test_query_chainer.py b/tests/query_blocks/test_query_chainer.py index 53b1981..b5952dc 100644 --- a/tests/query_blocks/test_query_chainer.py +++ b/tests/query_blocks/test_query_chainer.py @@ -2,9 +2,9 @@ import pytest -from enums.query_presets import QueryPresetsGeneric -from exceptions.query_chaining_error import QueryChainingError -from query_blocks.query_chainer import QueryChainer +from openstackquery.enums.query_presets import QueryPresetsGeneric +from openstackquery.exceptions.query_chaining_error import QueryChainingError +from openstackquery.query_blocks.query_chainer import QueryChainer from tests.mocks.mocked_props import MockProperties @@ -28,9 +28,9 @@ def run_parse_then_query_valid_fixture(instance): Fixture that runs a then_query() method test case """ - @patch("query_factory.QueryFactory") - @patch("api.query_api.QueryAPI") - @patch("query_blocks.query_chainer.QueryTypes") + @patch("openstackquery.query_factory.QueryFactory") + @patch("openstackquery.api.query_api.QueryAPI") + @patch("openstackquery.query_blocks.query_chainer.QueryTypes") def _run_parse_then_query_valid( mock_keep_previous_results, mock_query_types_cls, @@ -220,7 +220,7 @@ def test_parse_then_no_results(instance): mock_current_query.to_props.assert_called_once() -@patch("query_blocks.query_chainer.QueryTypes") +@patch("openstackquery.query_blocks.query_chainer.QueryTypes") def test_run_append_from_query(mock_query_types, instance): """ tests run_append_from_query method - calls then() to get a new query and runs it, selecting diff --git a/tests/query_blocks/test_query_executor.py b/tests/query_blocks/test_query_executor.py index 831eae9..5d7e06b 100644 --- a/tests/query_blocks/test_query_executor.py +++ b/tests/query_blocks/test_query_executor.py @@ -1,7 +1,7 @@ from unittest.mock import MagicMock, NonCallableMock, patch, call import pytest -from query_blocks.query_executor import QueryExecutor +from openstackquery.query_blocks.query_executor import QueryExecutor from tests.mocks.mocked_props import MockProperties @@ -20,7 +20,7 @@ def instance_fixture(mock_connection_cls): """ mock_prop_enum_cls = MockProperties mock_runner_cls = MagicMock() - with patch("query_blocks.query_executor.ResultsContainer"): + with patch("openstackquery.query_blocks.query_executor.ResultsContainer"): return QueryExecutor(mock_prop_enum_cls, mock_runner_cls, mock_connection_cls) @@ -62,7 +62,7 @@ def run_with_openstacksdk_runner_fixture(instance, mock_connection_cls): Fixture to run run_with_openstacksdk() test cases with different args """ - @patch("runners.runner_utils.RunnerUtils.apply_client_side_filters") + @patch("openstackquery.runners.runner_utils.RunnerUtils.apply_client_side_filters") def _run_with_openstacksdk_runner( mock_server_side_filters, use_client_side_filters, @@ -180,7 +180,7 @@ def test_run_with_openstacksdk_no_filters(run_with_openstacksdk_runner): run_with_openstacksdk_runner(None, False) -@patch("runners.runner_utils.RunnerUtils.apply_client_side_filters") +@patch("openstackquery.runners.runner_utils.RunnerUtils.apply_client_side_filters") def test_with_subset(mock_apply_client_side_filters, instance): """ Tests run_with_subset diff --git a/tests/query_blocks/test_query_grouper.py b/tests/query_blocks/test_query_grouper.py index 389b625..2580862 100644 --- a/tests/query_blocks/test_query_grouper.py +++ b/tests/query_blocks/test_query_grouper.py @@ -1,10 +1,10 @@ from unittest.mock import call, patch import pytest -from query_blocks.query_grouper import QueryGrouper -from enums.props.server_properties import ServerProperties +from openstackquery.query_blocks.query_grouper import QueryGrouper +from openstackquery.enums.props.server_properties import ServerProperties -from exceptions.parse_query_error import ParseQueryError +from openstackquery.exceptions.parse_query_error import ParseQueryError from tests.mocks.mocked_props import MockProperties @@ -85,7 +85,7 @@ def test_parse_group_by_with_string_aliases(mock_results_container): instance.parse_group_by(ServerProperties.SERVER_NAME) res = instance.run_group_by(mock_obj_list) for key, vals in res.items(): - assert key in res.keys() + assert key in res assert expected_out[key] == [i.as_object() for i in vals] diff --git a/tests/query_blocks/test_query_output.py b/tests/query_blocks/test_query_output.py index 35f85a5..2668f8e 100644 --- a/tests/query_blocks/test_query_output.py +++ b/tests/query_blocks/test_query_output.py @@ -1,9 +1,9 @@ from unittest.mock import MagicMock, patch, call, NonCallableMock, mock_open import pytest -from exceptions.parse_query_error import ParseQueryError -from query_blocks.query_output import QueryOutput -from enums.props.server_properties import ServerProperties +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.query_blocks.query_output import QueryOutput +from openstackquery.enums.props.server_properties import ServerProperties from tests.mocks.mocked_props import MockProperties @@ -174,7 +174,7 @@ def test_to_props_grouped_results_with_flatten_and_group(instance): assert res == {"group1": {"prop1": ["val1", "val3"], "prop2": ["val2", "val4"]}} -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_html_results_empty(mock_tabulate, instance): """ Tests to_html method with no extra params and empty results @@ -189,7 +189,7 @@ def test_to_html_results_empty(mock_tabulate, instance): assert res == "No results found

" -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_html_ungrouped_results(mock_tabulate, instance): """ Tests to_html method with no extra params and ungrouped results @@ -210,7 +210,7 @@ def test_to_html_ungrouped_results(mock_tabulate, instance): assert res == "tabulate-output

" -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_html_grouped_results(mock_tabulate, instance): """ Tests to_html method with no extra params and grouped results @@ -246,7 +246,7 @@ def test_to_html_grouped_results(mock_tabulate, instance): ) -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_html_with_title(mock_tabulate, instance): """ Tests to_html method with title param and ungrouped results @@ -267,7 +267,7 @@ def test_to_html_with_title(mock_tabulate, instance): assert res == ("mock-title:
" "tabulate-output

") -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_html_with_title_grouped_results(mock_tabulate, instance): """ Tests to_html method with title param and grouped results @@ -304,7 +304,7 @@ def test_to_html_with_title_grouped_results(mock_tabulate, instance): ) -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_html_with_title_and_group(mock_tabulate, instance): """ Tests to_html method with title and group params and grouped results @@ -334,7 +334,7 @@ def test_to_html_with_title_and_group(mock_tabulate, instance): ) -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_string_results_empty(mock_tabulate, instance): """ Tests to_string method with no extra params and empty results @@ -349,7 +349,7 @@ def test_to_string_results_empty(mock_tabulate, instance): assert res == "No results found\n\n" -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_string_ungrouped_results(mock_tabulate, instance): """ Tests to_string method with no extra params and ungrouped results @@ -370,7 +370,7 @@ def test_to_string_ungrouped_results(mock_tabulate, instance): assert res == "tabulate-output\n\n" -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_string_grouped_results(mock_tabulate, instance): """ Tests to_string method with no extra params and grouped results @@ -405,7 +405,7 @@ def test_to_string_grouped_results(mock_tabulate, instance): ) -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_string_with_title(mock_tabulate, instance): """ Tests to_string method with title param and ungrouped results @@ -426,7 +426,7 @@ def test_to_string_with_title(mock_tabulate, instance): assert res == ("mock-title:\n" "tabulate-output\n\n") -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_string_with_title_grouped_results(mock_tabulate, instance): """ Tests to_string method with title param and grouped results @@ -463,7 +463,7 @@ def test_to_string_with_title_grouped_results(mock_tabulate, instance): ) -@patch("query_blocks.query_output.tabulate") +@patch("openstackquery.query_blocks.query_output.tabulate") def test_to_string_with_title_and_group(mock_tabulate, instance): """ Tests to_string method with title and group params and grouped results @@ -534,8 +534,8 @@ def test_parse_select_overwrites_old(instance): @patch("builtins.open", new_callable=mock_open) -@patch("query_blocks.query_output.csv.DictWriter") -@patch("query_blocks.query_output.Path") +@patch("openstackquery.query_blocks.query_output.csv.DictWriter") +@patch("openstackquery.query_blocks.query_output.Path") def test_to_csv_ungrouped_results( mock_path, mock_dict_writer, mock_open_call, instance ): @@ -575,8 +575,8 @@ def test_to_csv_ungrouped_results( @patch("builtins.open", new_callable=mock_open) -@patch("query_blocks.query_output.csv.DictWriter") -@patch("query_blocks.query_output.Path") +@patch("openstackquery.query_blocks.query_output.csv.DictWriter") +@patch("openstackquery.query_blocks.query_output.Path") def test_to_csv_grouped_results(mock_path, mock_dict_writer, mock_open_call, instance): """ Tests to_csv with grouped results - should call open to write multiple files @@ -631,7 +631,7 @@ def test_to_csv_grouped_results(mock_path, mock_dict_writer, mock_open_call, ins ) -@patch("query_blocks.query_output.Path") +@patch("openstackquery.query_blocks.query_output.Path") def test_to_csv_results_empty(mock_path, instance): """ Tests to_csv with empty results - should raise Runtime error diff --git a/tests/query_blocks/test_query_parser.py b/tests/query_blocks/test_query_parser.py index 0ea1e7e..8404589 100644 --- a/tests/query_blocks/test_query_parser.py +++ b/tests/query_blocks/test_query_parser.py @@ -1,12 +1,12 @@ from unittest.mock import patch, NonCallableMock import pytest -from query_blocks.query_parser import QueryParser +from openstackquery.query_blocks.query_parser import QueryParser @pytest.fixture(name="instance") -@patch("query_blocks.query_parser.QueryGrouper") -@patch("query_blocks.query_parser.QuerySorter") +@patch("openstackquery.query_blocks.query_parser.QueryGrouper") +@patch("openstackquery.query_blocks.query_parser.QuerySorter") def instance_fixture(mock_sorter, mock_grouper): """ Returns an instance of QueryParser with mocked injects diff --git a/tests/query_blocks/test_query_sorter.py b/tests/query_blocks/test_query_sorter.py index b26c610..f7b3465 100644 --- a/tests/query_blocks/test_query_sorter.py +++ b/tests/query_blocks/test_query_sorter.py @@ -1,11 +1,11 @@ from unittest.mock import call, patch import pytest -from enums.props.server_properties import ServerProperties -from enums.sort_order import SortOrder -from exceptions.parse_query_error import ParseQueryError +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.sort_order import SortOrder +from openstackquery.exceptions.parse_query_error import ParseQueryError -from query_blocks.query_sorter import QuerySorter +from openstackquery.query_blocks.query_sorter import QuerySorter from tests.mocks.mocked_props import MockProperties diff --git a/tests/query_blocks/test_result.py b/tests/query_blocks/test_result.py index 01aa193..77eb8d2 100644 --- a/tests/query_blocks/test_result.py +++ b/tests/query_blocks/test_result.py @@ -1,7 +1,7 @@ from unittest.mock import MagicMock, patch, call import pytest -from query_blocks.result import Result +from openstackquery.query_blocks.result import Result from tests.mocks.mocked_props import MockProperties @@ -42,7 +42,7 @@ def test_as_object(): assert Result(MockProperties, mock_obj).as_object() == mock_obj -@patch("query_blocks.result.Result.get_prop") +@patch("openstackquery.query_blocks.result.Result.get_prop") def test_as_props_no_forwarded_props(mock_get_prop, instance): """ test property getter as_props just gets as_props when no forwarded_props given @@ -59,7 +59,7 @@ def test_as_props_no_forwarded_props(mock_get_prop, instance): } -@patch("query_blocks.result.Result.get_prop") +@patch("openstackquery.query_blocks.result.Result.get_prop") def test_as_props_with_forwarded_props(mock_get_prop, instance): """ test property getter as_props gets as_props result and forwarded_props set, diff --git a/tests/query_blocks/test_result_container.py b/tests/query_blocks/test_result_container.py index d74b80a..84dc889 100644 --- a/tests/query_blocks/test_result_container.py +++ b/tests/query_blocks/test_result_container.py @@ -2,7 +2,7 @@ from unittest.mock import MagicMock, patch, call, NonCallableMock import pytest -from query_blocks.results_container import ResultsContainer +from openstackquery.query_blocks.results_container import ResultsContainer from tests.mocks.mocked_props import MockProperties @@ -12,7 +12,7 @@ def setup_instance_with_results_fixture(): Fixture to get setup an instance of ResultsContainer with a set of mock results """ - @patch("query_blocks.results_container.Result") + @patch("openstackquery.query_blocks.results_container.Result") def _setup_instance(results, mock_result_obj): """ sets up a ResultsContainer storing set of results given diff --git a/tests/runners/test_flavor_runner.py b/tests/runners/test_flavor_runner.py index 9d83fbc..f36e6db 100644 --- a/tests/runners/test_flavor_runner.py +++ b/tests/runners/test_flavor_runner.py @@ -1,7 +1,7 @@ from unittest.mock import MagicMock, NonCallableMock, patch import pytest -from runners.flavor_runner import FlavorRunner +from openstackquery.runners.flavor_runner import FlavorRunner @pytest.fixture(name="instance") @@ -24,7 +24,7 @@ def test_parse_query_params(instance): ) -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_no_server_filters( mock_run_paginated_query, instance, mock_marker_prop_func ): diff --git a/tests/runners/test_hypervisor_runner.py b/tests/runners/test_hypervisor_runner.py index 6af9e97..e4db9fa 100644 --- a/tests/runners/test_hypervisor_runner.py +++ b/tests/runners/test_hypervisor_runner.py @@ -1,7 +1,7 @@ from unittest.mock import MagicMock, NonCallableMock, patch import pytest -from runners.hypervisor_runner import HypervisorRunner +from openstackquery.runners.hypervisor_runner import HypervisorRunner @pytest.fixture(name="instance") @@ -24,7 +24,7 @@ def test_parse_query_params(instance): ) -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_no_server_filters( mock_run_paginated_query, instance, mock_marker_prop_func ): diff --git a/tests/runners/test_image_runner.py b/tests/runners/test_image_runner.py index 54c22b1..31c9f72 100644 --- a/tests/runners/test_image_runner.py +++ b/tests/runners/test_image_runner.py @@ -1,8 +1,8 @@ from unittest.mock import MagicMock, NonCallableMock, patch import pytest -from runners.image_runner import ImageRunner -from exceptions.parse_query_error import ParseQueryError +from openstackquery.runners.image_runner import ImageRunner +from openstackquery.exceptions.parse_query_error import ParseQueryError @pytest.fixture(name="instance") @@ -45,7 +45,7 @@ def test_parse_meta_params_with_all_projects(instance): assert res == {} -@patch("runners.runner_utils.RunnerUtils.parse_projects") +@patch("openstackquery.runners.runner_utils.RunnerUtils.parse_projects") def test_parse_meta_params_with_from_projects_as_admin(mock_parse_projects, instance): """ Tests parse_meta_params with valid from_projects argument and as_admin = True @@ -64,7 +64,7 @@ def test_parse_meta_params_with_from_projects_as_admin(mock_parse_projects, inst assert res["projects"] == mock_parse_projects.return_value -@patch("runners.runner_utils.RunnerUtils.parse_projects") +@patch("openstackquery.runners.runner_utils.RunnerUtils.parse_projects") def test_parse_meta_params_with_no_args(mock_parse_projects, instance): """ Tests parse_meta_params with no args @@ -82,7 +82,7 @@ def test_parse_meta_params_with_no_args(mock_parse_projects, instance): assert res["projects"] == mock_parse_projects.return_value -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_with_meta_arg_projects_with_server_side_queries( mock_run_paginated_query, instance, mock_marker_prop_func ): @@ -115,7 +115,7 @@ def test_run_query_with_meta_arg_projects_with_server_side_queries( assert res == ["server1", "server2", "server3", "server4"] -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_no_meta_params( mock_run_paginated_query, instance, mock_marker_prop_func ): diff --git a/tests/runners/test_project_runner.py b/tests/runners/test_project_runner.py index f98111c..593b03e 100644 --- a/tests/runners/test_project_runner.py +++ b/tests/runners/test_project_runner.py @@ -1,7 +1,7 @@ from unittest.mock import MagicMock, NonCallableMock, patch import pytest -from runners.project_runner import ProjectRunner +from openstackquery.runners.project_runner import ProjectRunner @pytest.fixture(name="instance") @@ -24,7 +24,7 @@ def test_parse_meta_params(instance): ) -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_no_server_filters( mock_run_paginated_query, instance, mock_marker_prop_func ): diff --git a/tests/runners/test_runner_utils.py b/tests/runners/test_runner_utils.py index 6900551..a56d53a 100644 --- a/tests/runners/test_runner_utils.py +++ b/tests/runners/test_runner_utils.py @@ -1,11 +1,11 @@ from unittest.mock import MagicMock, NonCallableMock, call import pytest - -from exceptions.parse_query_error import ParseQueryError -from runners.runner_utils import RunnerUtils from openstack.exceptions import ResourceNotFound, ForbiddenException +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.runners.runner_utils import RunnerUtils + def run_paginated_query_test(number_iterations): """ diff --git a/tests/runners/test_runner_wrapper.py b/tests/runners/test_runner_wrapper.py index b76ff15..caaa60e 100644 --- a/tests/runners/test_runner_wrapper.py +++ b/tests/runners/test_runner_wrapper.py @@ -1,8 +1,8 @@ from unittest.mock import MagicMock import pytest -from exceptions.parse_query_error import ParseQueryError -from runners.runner_wrapper import RunnerWrapper +from openstackquery.exceptions.parse_query_error import ParseQueryError +from openstackquery.runners.runner_wrapper import RunnerWrapper @pytest.fixture(name="instance") diff --git a/tests/runners/test_server_runner.py b/tests/runners/test_server_runner.py index 4efd92f..37e819e 100644 --- a/tests/runners/test_server_runner.py +++ b/tests/runners/test_server_runner.py @@ -1,8 +1,8 @@ from unittest.mock import MagicMock, NonCallableMock, patch import pytest -from runners.server_runner import ServerRunner -from exceptions.parse_query_error import ParseQueryError +from openstackquery.runners.server_runner import ServerRunner +from openstackquery.exceptions.parse_query_error import ParseQueryError @pytest.fixture(name="instance") @@ -45,7 +45,7 @@ def test_parse_meta_params_with_all_projects(instance): assert list(res.keys()) == ["all_tenants"] -@patch("runners.runner_utils.RunnerUtils.parse_projects") +@patch("openstackquery.runners.runner_utils.RunnerUtils.parse_projects") def test_parse_meta_params_with_from_projects_as_admin(mock_parse_projects, instance): """ Tests parse_meta_params with valid from_projects argument and as_admin = True @@ -65,7 +65,7 @@ def test_parse_meta_params_with_from_projects_as_admin(mock_parse_projects, inst assert res["all_tenants"] is True -@patch("runners.runner_utils.RunnerUtils.parse_projects") +@patch("openstackquery.runners.runner_utils.RunnerUtils.parse_projects") def test_parse_meta_params_with_no_args(mock_parse_projects, instance): """ Tests parse_meta_params with no args @@ -96,7 +96,7 @@ def test_run_query_project_meta_arg_preset_duplication(instance): ) -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_with_meta_arg_projects_with_server_side_queries( mock_run_paginated_query, instance, mock_marker_prop_func ): @@ -129,7 +129,7 @@ def test_run_query_with_meta_arg_projects_with_server_side_queries( assert res == ["server1", "server2", "server3", "server4"] -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_meta_arg_all_tenants_no_projects( mock_run_paginated_query, instance, mock_marker_prop_func ): @@ -148,7 +148,7 @@ def test_run_query_meta_arg_all_tenants_no_projects( assert res == ["server1", "server2"] -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_with_meta_arg_projects_with_no_server_queries( mock_run_paginated_query, instance, mock_marker_prop_func ): diff --git a/tests/runners/test_user_runner.py b/tests/runners/test_user_runner.py index 28a8989..ffeae6a 100644 --- a/tests/runners/test_user_runner.py +++ b/tests/runners/test_user_runner.py @@ -1,10 +1,7 @@ from unittest.mock import MagicMock, NonCallableMock, patch import pytest -from runners.user_runner import UserRunner - -from exceptions.parse_query_error import ParseQueryError -from exceptions.enum_mapping_error import EnumMappingError +from openstackquery.runners.user_runner import UserRunner @pytest.fixture(name="instance") @@ -44,7 +41,7 @@ def test_parse_meta_params_no_from_domain(instance): assert res == {"domain_id": mock_domain_id} -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_with_server_side_filters( mock_run_paginated_query, instance, mock_marker_prop_func ): @@ -78,7 +75,7 @@ def test_run_query_with_server_side_filters( assert res == mock_user_list -@patch("runners.runner_utils.RunnerUtils.run_paginated_query") +@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query") def test_run_query_with_no_server_filters( mock_run_paginated_query, instance, mock_marker_prop_func ): diff --git a/tests/structs/__init__.py b/tests/structs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/structs/test_query_output_details.py b/tests/structs/test_query_output_details.py new file mode 100644 index 0000000..e3b94cb --- /dev/null +++ b/tests/structs/test_query_output_details.py @@ -0,0 +1,83 @@ +import pytest +from openstackquery.structs.query_output_details import QueryOutputDetails +from openstackquery.enums.props.server_properties import ServerProperties +from openstackquery.enums.query_output_types import QueryOutputTypes + + +@pytest.fixture(name="instance") +def instance_fixture(): + """ + Returns an instance to run tests with + """ + return QueryOutputDetails + + +@pytest.fixture(name="run_kwargs_test_case") +def run_kwargs_test_case_fixture(instance): + """ + Fixture runs a test case with different kwargs + """ + + def _run_from_kwargs_case(kwargs): + """ + Helper function for running from_kwargs test cases + """ + return instance.from_kwargs(prop_cls=ServerProperties, **kwargs) + + return _run_from_kwargs_case + + +def test_from_kwargs_none_given(run_kwargs_test_case): + """ + tests that from_kwargs static method works expectedly - no kwargs given + method should create a QueryOutputDetails with default params + """ + res = run_kwargs_test_case({}) + assert res.properties_to_select == list(ServerProperties) + assert res.output_type == QueryOutputTypes.TO_STR + assert not res.group_by + assert not res.sort_by + assert not res.group_ranges + assert not res.include_ungrouped_results + + +def test_from_kwargs_props_given(run_kwargs_test_case): + """ + tests that from_kwargs static method works expectedly - props given + method should create a QueryOutputDetails with props set + """ + res = run_kwargs_test_case({"properties_to_select": ["server_id", "server_name"]}) + assert res.properties_to_select == [ + ServerProperties.SERVER_ID, + ServerProperties.SERVER_NAME, + ] + + +def test_from_kwargs_output_type_given(run_kwargs_test_case): + """ + tests that from_kwargs static method works expectedly - output type given + method should create a QueryOutputDetails with output type set + """ + res = run_kwargs_test_case({"output_type": "TO_LIST"}) + assert res.output_type == QueryOutputTypes.TO_LIST + + +def test_from_kwargs_group_by_given(run_kwargs_test_case): + """ + tests that from_kwargs static method works expectedly - group by given + method should create a QueryOutputDetails with group by set + """ + res = run_kwargs_test_case({"group_by": "server_name"}) + assert res.group_by == ServerProperties.SERVER_NAME + + +def test_from_kwargs_sort_by_given(run_kwargs_test_case): + """ + tests that from_kwargs static method works expectedly - sort by given + method should create a QueryOutputDetails with sort by set + """ + res = run_kwargs_test_case({"sort_by": ["server_name", "server_id"]}) + assert res.sort_by == [ + (ServerProperties.SERVER_NAME, False), + (ServerProperties.SERVER_ID, False), + ] diff --git a/tests/test_api_imports.py b/tests/test_api_imports.py index 849c34c..3c65678 100644 --- a/tests/test_api_imports.py +++ b/tests/test_api_imports.py @@ -1,6 +1,5 @@ import pytest - -import openstack_query +import openstackquery @pytest.mark.parametrize( @@ -16,4 +15,4 @@ ) def test_query_server_import(test_module_name): """Tests that query object imports can be done at root level""" - assert getattr(openstack_query, test_module_name) + assert getattr(openstackquery, test_module_name) diff --git a/tests/test_query_factory.py b/tests/test_query_factory.py index 57fc261..5174e6b 100644 --- a/tests/test_query_factory.py +++ b/tests/test_query_factory.py @@ -2,7 +2,7 @@ import pytest -from query_factory import QueryFactory +from openstackquery.query_factory import QueryFactory @pytest.fixture(name="run_build_query_deps_test_case") @@ -10,16 +10,16 @@ def run_build_query_deps_test_case_fixture(): """Fixture for running build_query_deps""" # pylint:disable=too-many-arguments - @patch("query_factory.QueryBuilder") - @patch("query_factory.QueryOutput") - @patch("query_factory.QueryParser") - @patch("query_factory.QueryExecutor") - @patch("query_factory.QueryChainer") - @patch("query_factory.QueryComponents") + @patch("openstackquery.query_factory.QueryBuilder") + @patch("openstackquery.query_factory.QueryOutput") + @patch("openstackquery.query_factory.QueryParser") + @patch("openstackquery.query_factory.QueryExecutor") + @patch("openstackquery.query_factory.QueryChainer") + @patch("openstackquery.query_factory.QueryComponents") def _run_build_query_deps_test_case( mock_query_components, mock_chainer, - mock_executer, + mock_executor, mock_parser, mock_output, mock_builder, @@ -45,7 +45,7 @@ def _run_build_query_deps_test_case( chain_mappings=mock_mapping_cls.get_chain_mappings.return_value ) - mock_executer.assert_called_once_with( + mock_executor.assert_called_once_with( prop_enum_cls=mock_prop_mapping, runner_cls=mock_mapping_cls.get_runner_mapping.return_value, ) @@ -54,7 +54,7 @@ def _run_build_query_deps_test_case( mock_output.return_value, mock_parser.return_value, mock_builder.return_value, - mock_executer.return_value, + mock_executor.return_value, mock_chainer.return_value, ) assert res == mock_query_components.return_value