diff --git a/c8y_api/app/__init__.py b/c8y_api/app/__init__.py index 29025c7..d3bacc9 100644 --- a/c8y_api/app/__init__.py +++ b/c8y_api/app/__init__.py @@ -343,3 +343,6 @@ def _get_tenant_instance(self, tenant_id: str) -> CumulocityApi: def __enter__(self) -> MultiTenantCumulocityApp: return self + + def __exit__(self, __exc_type, __exc_value, __traceback): + pass diff --git a/c8y_api/model/_base.py b/c8y_api/model/_base.py index c7f9e50..f1a7785 100644 --- a/c8y_api/model/_base.py +++ b/c8y_api/model/_base.py @@ -7,15 +7,13 @@ from __future__ import annotations import logging -from urllib.parse import quote_plus from typing import Any, Iterable, Set +from urllib.parse import quote_plus, urlencode from collections.abc import MutableMapping from deprecated import deprecated -from urllib.parse import urlencode from c8y_api._base_api import CumulocityRestApi - from c8y_api.model._util import _DateUtil, _StringUtil, _QueryUtil diff --git a/c8y_api/model/inventory.py b/c8y_api/model/inventory.py index d069146..d54232a 100644 --- a/c8y_api/model/inventory.py +++ b/c8y_api/model/inventory.py @@ -8,7 +8,6 @@ from __future__ import annotations from typing import Any, Generator, List -from urllib.parse import urlencode, quote_plus from c8y_api.model._base import CumulocityResource from c8y_api.model._util import _QueryUtil diff --git a/c8y_api/model/measurements.py b/c8y_api/model/measurements.py index f2c07bd..24addc6 100644 --- a/c8y_api/model/measurements.py +++ b/c8y_api/model/measurements.py @@ -9,7 +9,6 @@ import dataclasses from datetime import datetime, timedelta from typing import Type, List, Generator, Sequence -from urllib.parse import urlencode, quote_plus from c8y_api._base_api import CumulocityRestApi diff --git a/c8y_tk/interactive/context.py b/c8y_tk/interactive/context.py index d98d00f..4f04959 100644 --- a/c8y_tk/interactive/context.py +++ b/c8y_tk/interactive/context.py @@ -3,7 +3,6 @@ # and/or its subsidiaries and/or its affiliates and/or their licensors. # Use, reproduction, transfer, publication or disclosure is prohibited except # as specifically provided for in your License Agreement with Software AG. -import contextlib # pylint: disable=protected-access import getpass diff --git a/integration_tests/test_apps.py b/integration_tests/test_apps.py index b2b1369..6881a92 100644 --- a/integration_tests/test_apps.py +++ b/integration_tests/test_apps.py @@ -103,4 +103,4 @@ def test_context_manager(test_environment): assert c8y.username with MultiTenantCumulocityApp() as c8y: - assert c8y.username + assert c8y.bootstrap_instance.username diff --git a/integration_tests/test_measurements.py b/integration_tests/test_measurements.py index e0ec505..2e3caa9 100644 --- a/integration_tests/test_measurements.py +++ b/integration_tests/test_measurements.py @@ -66,6 +66,7 @@ def factory_fun(n: int, device=None, type=None, series=None) -> List[Measurement def test_select(live_c8y: CumulocityApi, measurement_factory): """Verify that selection works as expected.""" + # pylint: disable=too-many-statements) logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") @@ -77,21 +78,17 @@ def test_select(live_c8y: CumulocityApi, measurement_factory): # create a couple of measurements (at a new device) created_ms = measurement_factory(10, type=name, series=name) - created_values = [m[name]['series'].value for m in created_ms] # create a couple of measurements with different source source_ms = measurement_factory(10, type=name, series=name) - source_values = [m[name]['series'].value for m in source_ms] # create a couple of measurements with different type name device_id = created_ms[0].source device = live_c8y.device_inventory.get(created_ms[0].source) type_ms = measurement_factory(10, device=device, type=other_name, series=name) - type_values = [m[name]['series'].value for m in type_ms] # create a couple of measurements with different series name series_ms = measurement_factory(10, device=device, type=name, series=other_name) - series_values = [m[other_name]['series'].value for m in series_ms] # (1) all measurement collections can be selected separately diff --git a/tests/model/test_base.py b/tests/model/test_base.py index 883761d..2a7172e 100644 --- a/tests/model/test_base.py +++ b/tests/model/test_base.py @@ -247,11 +247,11 @@ def test_iteration(page_size, num_all, limit, expected): all_items = [{'i': i} for i in range(num_all)] # returns a 'page' from all items - def get_page(_, page): + def get_page(_, p): nonlocal all_items - s = page_size * (page - 1) - e = page_size * page - return [i for i in all_items[s:e]] + s = page_size * (p - 1) + e = page_size * p + return all_items[s:e] # parses an item as CumulocityObject def parse_fun(item): @@ -261,7 +261,7 @@ def parse_fun(item): # create class under test res = CumulocityResource(Mock(CumulocityRestApi), '') - res._get_page = get_page + res._get_page = Mock(side_effect=get_page) # iterate oder results result = list(res._iterate(base_query="q", page_number=None, limit=limit, parse_fun=parse_fun)) diff --git a/tests/model/test_inventory.py b/tests/model/test_inventory.py index e06795c..444346e 100644 --- a/tests/model/test_inventory.py +++ b/tests/model/test_inventory.py @@ -4,7 +4,7 @@ # Use, reproduction, transfer, publication or disclosure is prohibited except # as specifically provided for in your License Agreement with Software AG. # pylint: disable=protected-access -import itertools + from unittest.mock import Mock import pytest @@ -108,6 +108,7 @@ def _invoke_target_and_isolate_url(target, kwargs): def gen_common_select_cases(): + """Generate test case data for common select cases.""" return [ # expression has the highest priority ({'expression': 'EX', 'query': 'QUERY'}, ['?EX'], ['query=', 'QUERY']), @@ -156,6 +157,7 @@ def gen_common_select_cases(): def gen_common_select_cases_ids(): + """Generate test case ID for common select cases.""" return ['+'.join(x[0].keys()) for x in gen_common_select_cases()] @@ -171,6 +173,7 @@ def gen_common_select_cases_ids(): 'group_inventory.get_count', ]) def test_common_select_params(fun, params, expected, not_expected): + """Verify that common select parameters are handled correctly.""" url = _invoke_target_and_isolate_url(fun, params) for e in expected: assert e in url diff --git a/tests/model/test_operations.py b/tests/model/test_operations.py index 8288455..5eb3b99 100644 --- a/tests/model/test_operations.py +++ b/tests/model/test_operations.py @@ -5,14 +5,13 @@ # as specifically provided for in your License Agreement with Software AG. from datetime import timedelta -from unittest.mock import Mock, patch +from unittest.mock import Mock from urllib.parse import unquote_plus import pytest from c8y_api import CumulocityApi from c8y_api.model import Operations -from model import BulkOperations from tests.utils import isolate_last_call_arg