diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a7cd7c44..25ee5ad4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,15 +22,15 @@ repos: hooks: - id: uv-lock + - repo: https://github.com/pycqa/flake8 + rev: 7.3.0 + hooks: + - id: flake8 + additional_dependencies: [Flake8-pyproject, Flake8-AAA, wemake-python-styleguide==1.3.*] + - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.17.0 hooks: - id: mypy args: ["--config-file=pyproject.toml", "."] pass_filenames: false - - - repo: https://github.com/pycqa/flake8 - rev: 7.3.0 - hooks: - - id: flake8 - additional_dependencies: [wemake-python-styleguide==1.3.*] diff --git a/pyproject.toml b/pyproject.toml index ee4ebbaa..28464ecb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,8 @@ dependencies = [ [dependency-groups] dev = [ "dependency-injector>=4.48.2", + "flake8-aaa>=0.17.2", + "flake8-pyproject>=1.2.3", "freezegun==1.5.*", "ipdb==0.13.*", "ipython==9.*", @@ -61,7 +63,7 @@ build-backend = "hatchling.build" [tool.pytest.ini_options] testpaths = "tests" pythonpath = "." -addopts = "--cov=mpt_api_client --cov-report=term-missing --cov-report=html --cov-report=xml --import-mode=importlib" +addopts = "--cov=mpt_api_client --cov-report=term-missing --cov-report=xml --import-mode=importlib" log_cli = false asyncio_mode = "auto" asyncio_default_fixture_loop_scope = "function" @@ -81,18 +83,59 @@ exclude_also = [ "if __name__ == \"__main__\":", "raise NotImplementedError", ] -include = [ - "mpt_api_client/**", -] omit = [ "*/__init__.py" ] +[tool.flake8] +allowed-domain-names = ["result"] +aaa_act_block_style = "large" +doctests = true +extend-ignore = ["WPS226", "WPS412"] +extend-exclude = [ + ".coverage", + ".github", + ".idea", + ".mypy_cache", + ".pytest_cache", + ".ruff_cache", + "uv.lock", + ".venv" +] +format = "wemake" +max-imports = 17 +max-line-length = 100 +select = ["AAA", "E999", "WPS"] +show-source = true +statistics = false +per-file-ignores = [ + "mpt_api_client/mpt_client.py: WPS214 WPS235", + "mpt_api_client/http/mixins.py: WPS202 WPS204 WPS235", + "mpt_api_client/resources/*: WPS215", + "mpt_api_client/models/model.py: WPS215 WPS110", + "mpt_api_client/resources/accounts/*.py: WPS202 WPS215 WPS214 WPS235", + "mpt_api_client/resources/billing/*.py: WPS202 WPS204 WPS214 WPS215", + "mpt_api_client/resources/catalog/*.py: WPS110 WPS214 WPS215 WPS235", + "mpt_api_client/resources/catalog/mixins.py: WPS110 WPS202 WPS214 WPS215 WPS235", + "mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215 WPS235", + "mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214", + "tests/unit/http/test_async_service.py: WPS204 WPS202", + "tests/unit/http/test_service.py: WPS204 WPS202", + "tests/unit/http/test_mixins.py: WPS204 WPS202 WPS210", + "tests/unit/resources/catalog/test_products.py: WPS202 WPS210", + "tests/unit/resources/accounts/*.py: WPS204 WPS202 WPS210", + "tests/unit/resources/*/test_mixins.py: WPS118 WPS202 WPS204 WPS235", + "tests/unit/test_mpt_client.py: WPS235", + "tests/e2e/accounts/*.py: WPS430 WPS202", + "tests/e2e/catalog/*.py: WPS202 WPS421", + "tests/e2e/catalog/items/*.py: WPS110 WPS202", + "tests/*: WPS432 WPS202" +] + [tool.ruff] # Ruff config: https://docs.astral.sh/ruff/settings preview = true target-version = "py312" -extend-exclude = [".vscode", ".devcontainer", "swo"] output-format = "full" line-length = 100 @@ -165,7 +208,7 @@ ignore = [ "PT011", # pytest.raises({exception}) is too broad, set the match parameter or use a more specific exception "TRY003", # long exception messages from `tryceratops` ] -external = [ "WPS" ] +external = [ "AAA", "WPS" ] # Plugin configs: flake8-import-conventions.banned-from = [ "datetime" ] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c278fa56..00000000 --- a/setup.cfg +++ /dev/null @@ -1,60 +0,0 @@ -# All configuration for plugins -# and other utils is defined here and in `pyproject.toml` - -# === Linter configuration === - -# NOTE: You can use https://pypi.org/project/Flake8-pyproject/ -# to move all your `flake8` configuration to `pyproject.toml` - -[flake8] -# Base flake8 configuration: -# https://flake8.pycqa.org/en/latest/user/configuration.html -format = wemake -show-source = true -statistics = false -doctests = true - -# Self settings: -max-imports = 17 - -# Excluding some directories: -extend-exclude = - .venv - -# We only run `wemake-python-styleguide` with `flake8`: -select = WPS, E999 - -extend-ignore = - # Found string constant over-use - WPS226 - # Allow logic in WPS412 - WPS412 - - -per-file-ignores = - mpt_api_client/mpt_client.py: WPS214 WPS235 - mpt_api_client/http/mixins.py: WPS202 WPS204 WPS235 - mpt_api_client/resources/*: WPS215 - mpt_api_client/models/model.py: WPS215 WPS110 - mpt_api_client/resources/accounts/*.py: WPS202 WPS215 WPS214 WPS235 - mpt_api_client/resources/billing/*.py: WPS202 WPS204 WPS214 WPS215 - mpt_api_client/resources/catalog/*.py: WPS110 WPS214 WPS215 WPS235 - mpt_api_client/resources/catalog/mixins.py: WPS110 WPS202 WPS214 WPS215 WPS235 - mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215 WPS235 - mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214 - tests/unit/http/test_async_service.py: WPS204 WPS202 - tests/unit/http/test_service.py: WPS204 WPS202 - tests/unit/http/test_mixins.py: WPS204 WPS202 WPS210 - tests/unit/resources/catalog/test_products.py: WPS202 WPS210 - tests/unit/resources/accounts/*.py: WPS204 WPS202 WPS210 - tests/unit/resources/*/test_mixins.py: WPS118 WPS202 WPS204 WPS235 - tests/unit/test_mpt_client.py: WPS235 - tests/e2e/accounts/*.py: WPS430 WPS202 - tests/e2e/catalog/*.py: WPS202 WPS421 - tests/e2e/catalog/items/*.py: WPS110 WPS202 - - tests/*: - # Allow magic strings. - WPS432 - # Found too many modules members. - WPS202 diff --git a/tests/e2e/accounts/account/test_async_account.py b/tests/e2e/accounts/account/test_async_account.py index 7de87ac4..a221e4de 100644 --- a/tests/e2e/accounts/account/test_async_account.py +++ b/tests/e2e/accounts/account/test_async_account.py @@ -26,29 +26,33 @@ async def test_get_account_by_id_not_found(async_mpt_ops): async def test_get_account_by_id(async_mpt_ops, account_id): - account = await async_mpt_ops.accounts.accounts.get(account_id) - assert account is not None + result = await async_mpt_ops.accounts.accounts.get(account_id) + + assert result is not None async def test_list_accounts(async_mpt_ops): limit = 10 - accounts_page = await async_mpt_ops.accounts.accounts.fetch_page(limit=limit) - assert len(accounts_page) > 0 + + result = await async_mpt_ops.accounts.accounts.fetch_page(limit=limit) + + assert len(result) > 0 def test_create_account(async_created_account): - account = async_created_account - assert account is not None + result = async_created_account + + assert result is not None async def test_update_account(async_mpt_ops, async_created_account, account_factory, account_icon): updated_data = account_factory(name="Updated Account Name") - updated_account = await async_mpt_ops.accounts.accounts.update( + result = await async_mpt_ops.accounts.accounts.update( async_created_account.id, updated_data, logo=account_icon ) - assert updated_account is not None + assert result is not None async def test_update_account_invalid_data( @@ -76,9 +80,9 @@ async def test_update_account_not_found( async def test_account_enable(async_mpt_ops, account_factory, async_created_account): await async_mpt_ops.accounts.accounts.disable(async_created_account.id) - account = await async_mpt_ops.accounts.accounts.enable(async_created_account.id) + result = await async_mpt_ops.accounts.accounts.enable(async_created_account.id) - assert account is not None + assert result is not None async def test_account_enable_not_found(async_mpt_ops, invalid_account_id): @@ -87,9 +91,9 @@ async def test_account_enable_not_found(async_mpt_ops, invalid_account_id): async def test_account_disable(async_mpt_ops, async_created_account): - account = await async_mpt_ops.accounts.accounts.disable(async_created_account.id) + result = await async_mpt_ops.accounts.accounts.disable(async_created_account.id) - assert account is not None + assert result is not None async def test_account_disable_not_found(async_mpt_ops, invalid_account_id): @@ -105,6 +109,6 @@ async def test_account_rql_filter(async_mpt_ops, account_id): .select(*selected_fields) ) - accounts = [account async for account in filtered_accounts.iterate()] + result = [account async for account in filtered_accounts.iterate()] - assert len(accounts) > 0 + assert len(result) > 0 diff --git a/tests/e2e/accounts/account/test_sync_account.py b/tests/e2e/accounts/account/test_sync_account.py index 9742dfe8..9d3e4850 100644 --- a/tests/e2e/accounts/account/test_sync_account.py +++ b/tests/e2e/accounts/account/test_sync_account.py @@ -26,29 +26,31 @@ def test_get_account_by_id_not_found(mpt_ops): def test_get_account_by_id(mpt_ops, account_id): - account = mpt_ops.accounts.accounts.get(account_id) - assert account is not None + result = mpt_ops.accounts.accounts.get(account_id) + + assert result is not None def test_list_accounts(mpt_ops): limit = 10 - accounts_page = mpt_ops.accounts.accounts.fetch_page(limit=limit) - assert len(accounts_page) > 0 + + result = mpt_ops.accounts.accounts.fetch_page(limit=limit) + + assert len(result) > 0 def test_create_account(created_account): - account = created_account - assert account is not None + result = created_account + + assert result is not None def test_update_account(mpt_ops, created_account, account_factory, account_icon): updated_data = account_factory(name="Updated Account Name") - updated_account = mpt_ops.accounts.accounts.update( - created_account.id, updated_data, logo=account_icon - ) + result = mpt_ops.accounts.accounts.update(created_account.id, updated_data, logo=account_icon) - assert updated_account is not None + assert result is not None def test_update_account_invalid_data(mpt_ops, account_factory, created_account, account_icon): @@ -70,9 +72,9 @@ def test_update_account_not_found(mpt_ops, account_factory, invalid_account_id, def test_account_enable(mpt_ops, account_factory, created_account): mpt_ops.accounts.accounts.disable(created_account.id) - account = mpt_ops.accounts.accounts.enable(created_account.id) + result = mpt_ops.accounts.accounts.enable(created_account.id) - assert account is not None + assert result is not None def test_account_enable_not_found(mpt_ops, invalid_account_id): @@ -81,9 +83,9 @@ def test_account_enable_not_found(mpt_ops, invalid_account_id): def test_account_disable(mpt_ops, created_account): - account = mpt_ops.accounts.accounts.disable(created_account.id) + result = mpt_ops.accounts.accounts.disable(created_account.id) - assert account is not None + assert result is not None def test_account_disable_not_found(mpt_ops, invalid_account_id): @@ -99,6 +101,6 @@ def test_account_rql_filter(mpt_ops, account_id): .select(*selected_fields) ) - accounts = list(filtered_accounts.iterate()) + result = list(filtered_accounts.iterate()) - assert len(accounts) > 0 + assert len(result) > 0 diff --git a/tests/e2e/accounts/api_tokens/test_async_api_tokens.py b/tests/e2e/accounts/api_tokens/test_async_api_tokens.py index a9556d9e..8195cacf 100644 --- a/tests/e2e/accounts/api_tokens/test_async_api_tokens.py +++ b/tests/e2e/accounts/api_tokens/test_async_api_tokens.py @@ -22,14 +22,17 @@ async def created_api_token(async_mpt_vendor, api_token_factory): async def test_get_api_token_by_id(async_mpt_vendor, api_token_id): - api_token = await async_mpt_vendor.accounts.api_tokens.get(api_token_id) - assert api_token is not None + result = await async_mpt_vendor.accounts.api_tokens.get(api_token_id) + + assert result is not None async def test_list_api_tokens(async_mpt_vendor): limit = 10 - api_tokens = await async_mpt_vendor.accounts.api_tokens.fetch_page(limit=limit) - assert len(api_tokens) > 0 + + result = await async_mpt_vendor.accounts.api_tokens.fetch_page(limit=limit) + + assert len(result) > 0 async def test_get_api_token_by_id_not_found(async_mpt_vendor, invalid_api_token_id): @@ -39,25 +42,25 @@ async def test_get_api_token_by_id_not_found(async_mpt_vendor, invalid_api_token async def test_filter_api_tokens(async_mpt_vendor, api_token_id): select_fields = ["-description"] - filtered_api_tokens = ( async_mpt_vendor.accounts.api_tokens.filter(RQLQuery(id=api_token_id)) .filter(RQLQuery(name="E2E Seeded Token")) .select(*select_fields) ) - api_tokens = [filtered_api_token async for filtered_api_token in filtered_api_tokens.iterate()] + result = [filtered_api_token async for filtered_api_token in filtered_api_tokens.iterate()] - assert len(api_tokens) == 1 + assert len(result) == 1 def test_create_api_token(created_api_token): - new_api_token = created_api_token - assert new_api_token is not None + result = created_api_token + + assert result is not None async def test_delete_api_token(async_mpt_vendor, created_api_token): - await async_mpt_vendor.accounts.api_tokens.delete(created_api_token.id) + await async_mpt_vendor.accounts.api_tokens.delete(created_api_token.id) # act async def test_delete_api_token_not_found(async_mpt_vendor, invalid_api_token_id): @@ -68,11 +71,11 @@ async def test_delete_api_token_not_found(async_mpt_vendor, invalid_api_token_id async def test_update_api_token(async_mpt_vendor, api_token_factory, created_api_token): updated_api_token_data = api_token_factory(name="E2E Updated API Token") - updated_api_token = await async_mpt_vendor.accounts.api_tokens.update( + result = await async_mpt_vendor.accounts.api_tokens.update( created_api_token.id, updated_api_token_data ) - assert updated_api_token is not None + assert result is not None async def test_update_api_token_not_found( @@ -87,9 +90,9 @@ async def test_update_api_token_not_found( async def test_api_token_disable(async_mpt_vendor, created_api_token): - disabled_api_token = await async_mpt_vendor.accounts.api_tokens.disable(created_api_token.id) + result = await async_mpt_vendor.accounts.api_tokens.disable(created_api_token.id) - assert disabled_api_token is not None + assert result is not None async def test_api_token_disable_not_found(async_mpt_vendor, invalid_api_token_id): @@ -100,9 +103,9 @@ async def test_api_token_disable_not_found(async_mpt_vendor, invalid_api_token_i async def test_api_token_enable(async_mpt_vendor, created_api_token): await async_mpt_vendor.accounts.api_tokens.disable(created_api_token.id) - enabled_api_token = await async_mpt_vendor.accounts.api_tokens.enable(created_api_token.id) + result = await async_mpt_vendor.accounts.api_tokens.enable(created_api_token.id) - assert enabled_api_token is not None + assert result is not None async def test_api_token_enable_not_found(async_mpt_vendor, invalid_api_token_id): diff --git a/tests/e2e/accounts/api_tokens/test_sync_api_tokens.py b/tests/e2e/accounts/api_tokens/test_sync_api_tokens.py index 98179c5d..43884e7e 100644 --- a/tests/e2e/accounts/api_tokens/test_sync_api_tokens.py +++ b/tests/e2e/accounts/api_tokens/test_sync_api_tokens.py @@ -20,14 +20,17 @@ def created_api_token(mpt_vendor, api_token_factory): def test_get_api_token_by_id(mpt_vendor, api_token_id): - api_token = mpt_vendor.accounts.api_tokens.get(api_token_id) - assert api_token is not None + result = mpt_vendor.accounts.api_tokens.get(api_token_id) + + assert result is not None def test_list_api_tokens(mpt_vendor): limit = 10 - api_tokens = mpt_vendor.accounts.api_tokens.fetch_page(limit=limit) - assert len(api_tokens) > 0 + + result = mpt_vendor.accounts.api_tokens.fetch_page(limit=limit) + + assert len(result) > 0 def test_get_api_token_by_id_not_found(mpt_vendor, invalid_api_token_id): @@ -37,25 +40,25 @@ def test_get_api_token_by_id_not_found(mpt_vendor, invalid_api_token_id): def test_filter_api_tokens(mpt_vendor, api_token_id): select_fields = ["-name"] - filtered_api_tokens = ( mpt_vendor.accounts.api_tokens.filter(RQLQuery(id=api_token_id)) .filter(RQLQuery(name="E2E Seeded Token")) .select(*select_fields) ) - api_tokens = list(filtered_api_tokens.iterate()) + result = list(filtered_api_tokens.iterate()) - assert len(api_tokens) == 1 + assert len(result) == 1 def test_create_api_token(created_api_token): - new_api_token = created_api_token - assert new_api_token is not None + result = created_api_token + + assert result is not None def test_delete_api_token(mpt_vendor, created_api_token): - mpt_vendor.accounts.api_tokens.delete(created_api_token.id) + mpt_vendor.accounts.api_tokens.delete(created_api_token.id) # act def test_delete_api_token_not_found(mpt_vendor, invalid_api_token_id): @@ -66,11 +69,9 @@ def test_delete_api_token_not_found(mpt_vendor, invalid_api_token_id): def test_update_api_token(mpt_vendor, api_token_factory, created_api_token): updated_api_token_data = api_token_factory(name="E2E Updated API Token") - updated_api_token = mpt_vendor.accounts.api_tokens.update( - created_api_token.id, updated_api_token_data - ) + result = mpt_vendor.accounts.api_tokens.update(created_api_token.id, updated_api_token_data) - assert updated_api_token is not None + assert result is not None def test_update_api_token_not_found(mpt_vendor, api_token_factory, invalid_api_token_id): @@ -81,9 +82,9 @@ def test_update_api_token_not_found(mpt_vendor, api_token_factory, invalid_api_t def test_api_token_disable(mpt_vendor, created_api_token): - disabled_api_token = mpt_vendor.accounts.api_tokens.disable(created_api_token.id) + result = mpt_vendor.accounts.api_tokens.disable(created_api_token.id) - assert disabled_api_token is not None + assert result is not None def test_api_token_disable_not_found(mpt_vendor, invalid_api_token_id): @@ -94,9 +95,9 @@ def test_api_token_disable_not_found(mpt_vendor, invalid_api_token_id): def test_api_token_enable(mpt_vendor, created_api_token): mpt_vendor.accounts.api_tokens.disable(created_api_token.id) - enabled_api_token = mpt_vendor.accounts.api_tokens.enable(created_api_token.id) + result = mpt_vendor.accounts.api_tokens.enable(created_api_token.id) - assert enabled_api_token is not None + assert result is not None def test_api_token_enable_not_found(mpt_vendor, invalid_api_token_id): diff --git a/tests/e2e/accounts/buyers/test_async_buyers.py b/tests/e2e/accounts/buyers/test_async_buyers.py index 39e327ea..ebb61a57 100644 --- a/tests/e2e/accounts/buyers/test_async_buyers.py +++ b/tests/e2e/accounts/buyers/test_async_buyers.py @@ -26,14 +26,17 @@ async def async_created_buyer(async_mpt_ops, buyer_factory, buyer_account_id, ac async def test_get_buyer_by_id(async_mpt_ops, buyer_id): - buyer = await async_mpt_ops.accounts.buyers.get(buyer_id) - assert buyer is not None + result = await async_mpt_ops.accounts.buyers.get(buyer_id) + + assert result is not None async def test_list_buyers(async_mpt_ops): limit = 10 - buyers = await async_mpt_ops.accounts.buyers.fetch_page(limit=limit) - assert len(buyers) > 0 + + result = await async_mpt_ops.accounts.buyers.fetch_page(limit=limit) + + assert len(result) > 0 async def test_get_buyer_by_id_not_found(async_mpt_ops, invalid_buyer_id): @@ -43,24 +46,25 @@ async def test_get_buyer_by_id_not_found(async_mpt_ops, invalid_buyer_id): async def test_filter_buyers(async_mpt_ops, buyer_id): select_fields = ["-address"] - async_filtered_buyers = ( async_mpt_ops.accounts.buyers.filter(RQLQuery(id=buyer_id)) .filter(RQLQuery(name="E2E Seeded Buyer")) .select(*select_fields) ) - buyers = [filtered_buyer async for filtered_buyer in async_filtered_buyers.iterate()] + result = [filtered_buyer async for filtered_buyer in async_filtered_buyers.iterate()] - assert len(buyers) == 1 + assert len(result) == 1 def test_create_buyer(async_created_buyer): - assert async_created_buyer is not None + result = async_created_buyer + + assert result is not None async def test_delete_buyer(async_mpt_ops, async_created_buyer): - await async_mpt_ops.accounts.buyers.delete(async_created_buyer.id) + await async_mpt_ops.accounts.buyers.delete(async_created_buyer.id) # act async def test_delete_buyer_not_found(async_mpt_ops, invalid_buyer_id): @@ -73,11 +77,11 @@ async def test_update_buyer( ): updated_buyer_data = buyer_factory(name="E2E Updated Buyer", account_id=buyer_account_id) - updated_buyer = await async_mpt_ops.accounts.buyers.update( + result = await async_mpt_ops.accounts.buyers.update( async_created_buyer.id, updated_buyer_data, logo=account_icon ) - assert updated_buyer is not None + assert result is not None async def test_update_buyer_not_found( @@ -92,9 +96,9 @@ async def test_update_buyer_not_found( async def test_buyer_disable(async_mpt_ops, async_created_buyer): - disabled_buyer = await async_mpt_ops.accounts.buyers.disable(async_created_buyer.id) + result = await async_mpt_ops.accounts.buyers.disable(async_created_buyer.id) - assert disabled_buyer is not None + assert result is not None async def test_buyer_disable_not_found(async_mpt_ops, invalid_buyer_id): @@ -105,9 +109,9 @@ async def test_buyer_disable_not_found(async_mpt_ops, invalid_buyer_id): async def test_buyer_enable(async_mpt_ops, async_created_buyer): await async_mpt_ops.accounts.buyers.disable(async_created_buyer.id) - enabled_buyer = await async_mpt_ops.accounts.buyers.enable(async_created_buyer.id) + result = await async_mpt_ops.accounts.buyers.enable(async_created_buyer.id) - assert enabled_buyer is not None + assert result is not None async def test_buyer_enable_not_found(async_mpt_ops, invalid_buyer_id): diff --git a/tests/e2e/accounts/buyers/test_sync_buyers.py b/tests/e2e/accounts/buyers/test_sync_buyers.py index 36c10750..a3bbd55f 100644 --- a/tests/e2e/accounts/buyers/test_sync_buyers.py +++ b/tests/e2e/accounts/buyers/test_sync_buyers.py @@ -24,14 +24,17 @@ def created_buyer(mpt_ops, buyer_factory, buyer_account_id, account_icon): def test_get_buyer_by_id(mpt_ops, buyer_id): - buyer = mpt_ops.accounts.buyers.get(buyer_id) - assert buyer is not None + result = mpt_ops.accounts.buyers.get(buyer_id) + + assert result is not None def test_list_buyers(mpt_ops): limit = 10 - buyers = mpt_ops.accounts.buyers.fetch_page(limit=limit) - assert len(buyers) > 0 + + result = mpt_ops.accounts.buyers.fetch_page(limit=limit) + + assert len(result) > 0 def test_get_buyer_by_id_not_found(mpt_ops, invalid_buyer_id): @@ -41,25 +44,25 @@ def test_get_buyer_by_id_not_found(mpt_ops, invalid_buyer_id): def test_filter_buyers(mpt_ops, buyer_id): select_fields = ["-address"] - filtered_buyers = ( mpt_ops.accounts.buyers.filter(RQLQuery(id=buyer_id)) .filter(RQLQuery(name="E2E Seeded Buyer")) .select(*select_fields) ) - buyers = list(filtered_buyers.iterate()) + result = list(filtered_buyers.iterate()) - assert len(buyers) == 1 + assert len(result) == 1 def test_create_buyer(created_buyer): - new_buyer = created_buyer - assert new_buyer is not None + result = created_buyer + + assert result is not None def test_delete_buyer(mpt_ops, created_buyer): - mpt_ops.accounts.buyers.delete(created_buyer.id) + mpt_ops.accounts.buyers.delete(created_buyer.id) # act def test_delete_buyer_not_found(mpt_ops, invalid_buyer_id): @@ -70,11 +73,9 @@ def test_delete_buyer_not_found(mpt_ops, invalid_buyer_id): def test_update_buyer(mpt_ops, buyer_factory, buyer_account_id, account_icon, created_buyer): updated_buyer_data = buyer_factory(name="E2E Updated Buyer", account_id=buyer_account_id) - updated_buyer = mpt_ops.accounts.buyers.update( - created_buyer.id, updated_buyer_data, logo=account_icon - ) + result = mpt_ops.accounts.buyers.update(created_buyer.id, updated_buyer_data, logo=account_icon) - assert updated_buyer is not None + assert result is not None def test_update_buyer_not_found( @@ -87,9 +88,9 @@ def test_update_buyer_not_found( def test_buyer_disable(mpt_ops, created_buyer): - disabled_buyer = mpt_ops.accounts.buyers.disable(created_buyer.id) + result = mpt_ops.accounts.buyers.disable(created_buyer.id) - assert disabled_buyer is not None + assert result is not None def test_buyer_disable_not_found(mpt_ops, invalid_buyer_id): @@ -100,9 +101,9 @@ def test_buyer_disable_not_found(mpt_ops, invalid_buyer_id): def test_buyer_enable(mpt_ops, created_buyer): mpt_ops.accounts.buyers.disable(created_buyer.id) - enabled_buyer = mpt_ops.accounts.buyers.enable(created_buyer.id) + result = mpt_ops.accounts.buyers.enable(created_buyer.id) - assert enabled_buyer is not None + assert result is not None def test_buyer_enable_not_found(mpt_ops, invalid_buyer_id): diff --git a/tests/e2e/accounts/licensees/test_async_licensees.py b/tests/e2e/accounts/licensees/test_async_licensees.py index 5b090bdd..731c0c9f 100644 --- a/tests/e2e/accounts/licensees/test_async_licensees.py +++ b/tests/e2e/accounts/licensees/test_async_licensees.py @@ -23,14 +23,17 @@ async def async_created_licensee(async_mpt_client, licensee_factory, account_ico async def test_get_licensee_by_id(async_mpt_client, licensee_id): - licensee = await async_mpt_client.accounts.licensees.get(licensee_id) - assert licensee is not None + result = await async_mpt_client.accounts.licensees.get(licensee_id) + + assert result is not None async def test_list_licensees(async_mpt_client): limit = 10 - licensees = await async_mpt_client.accounts.licensees.fetch_page(limit=limit) - assert len(licensees) > 0 + + result = await async_mpt_client.accounts.licensees.fetch_page(limit=limit) + + assert len(result) > 0 async def test_get_licensee_by_id_not_found(async_mpt_client, invalid_licensee_id): @@ -40,22 +43,21 @@ async def test_get_licensee_by_id_not_found(async_mpt_client, invalid_licensee_i async def test_filter_licensees(async_mpt_client, licensee_id): select_fields = ["-address"] - async_filtered_licensees = ( async_mpt_client.accounts.licensees.filter(RQLQuery(id=licensee_id)) .filter(RQLQuery(name="E2E Seeded Licensee")) .select(*select_fields) ) - licensees = [ - filtered_licensee async for filtered_licensee in async_filtered_licensees.iterate() - ] + result = [filtered_licensee async for filtered_licensee in async_filtered_licensees.iterate()] - assert len(licensees) == 1 + assert len(result) == 1 def test_create_licensee(async_created_licensee): - assert async_created_licensee is not None + result = async_created_licensee + + assert result is not None async def test_delete_licensee(async_mpt_client, async_created_licensee): @@ -72,11 +74,11 @@ async def test_update_licensee( ): updated_licensee_data = licensee_factory(name="E2E Updated Licensee") - updated_licensee = await async_mpt_client.accounts.licensees.update( + result = await async_mpt_client.accounts.licensees.update( async_created_licensee.id, updated_licensee_data, logo=account_icon ) - assert updated_licensee is not None + assert result is not None async def test_update_licensee_not_found( @@ -91,9 +93,9 @@ async def test_update_licensee_not_found( async def test_licensee_disable(async_mpt_client, async_created_licensee): - disabled_licensee = await async_mpt_client.accounts.licensees.disable(async_created_licensee.id) + result = await async_mpt_client.accounts.licensees.disable(async_created_licensee.id) - assert disabled_licensee is not None + assert result is not None async def test_licensee_disable_not_found(async_mpt_client, invalid_licensee_id): @@ -104,9 +106,9 @@ async def test_licensee_disable_not_found(async_mpt_client, invalid_licensee_id) async def test_licensee_enable(async_mpt_client, async_created_licensee): await async_mpt_client.accounts.licensees.disable(async_created_licensee.id) - enabled_licensee = await async_mpt_client.accounts.licensees.enable(async_created_licensee.id) + result = await async_mpt_client.accounts.licensees.enable(async_created_licensee.id) - assert enabled_licensee is not None + assert result is not None async def test_licensee_enable_not_found(async_mpt_client, invalid_licensee_id): diff --git a/tests/e2e/accounts/licensees/test_sync_licensees.py b/tests/e2e/accounts/licensees/test_sync_licensees.py index 9c6c0550..c89d5492 100644 --- a/tests/e2e/accounts/licensees/test_sync_licensees.py +++ b/tests/e2e/accounts/licensees/test_sync_licensees.py @@ -23,14 +23,17 @@ def created_licensee(mpt_client, licensee_factory, account_icon): def test_get_licensee_by_id(mpt_client, licensee_id): - licensee = mpt_client.accounts.licensees.get(licensee_id) - assert licensee is not None + result = mpt_client.accounts.licensees.get(licensee_id) + + assert result is not None def test_list_licensees(mpt_client): limit = 10 - licensees = mpt_client.accounts.licensees.fetch_page(limit=limit) - assert len(licensees) > 0 + + result = mpt_client.accounts.licensees.fetch_page(limit=limit) + + assert len(result) > 0 def test_get_licensee_by_id_not_found(mpt_client, invalid_licensee_id): @@ -40,25 +43,25 @@ def test_get_licensee_by_id_not_found(mpt_client, invalid_licensee_id): def test_filter_licensees(mpt_client, licensee_id): select_fields = ["-address"] - filtered_licensees = ( mpt_client.accounts.licensees.filter(RQLQuery(id=licensee_id)) .filter(RQLQuery(name="E2E Seeded Licensee")) .select(*select_fields) ) - licensees = list(filtered_licensees.iterate()) + result = list(filtered_licensees.iterate()) - assert len(licensees) == 1 + assert len(result) == 1 def test_create_licensee(created_licensee): - new_licensee = created_licensee - assert new_licensee is not None + result = created_licensee + + assert result is not None def test_delete_licensee(mpt_client, created_licensee): - mpt_client.accounts.licensees.delete(created_licensee.id) + mpt_client.accounts.licensees.delete(created_licensee.id) # act def test_delete_licensee_not_found(mpt_client, invalid_licensee_id): @@ -69,11 +72,11 @@ def test_delete_licensee_not_found(mpt_client, invalid_licensee_id): def test_update_licensee(mpt_client, licensee_factory, account_icon, created_licensee): updated_licensee_data = licensee_factory(name="E2E Updated Licensee") - updated_licensee = mpt_client.accounts.licensees.update( + result = mpt_client.accounts.licensees.update( created_licensee.id, updated_licensee_data, logo=account_icon ) - assert updated_licensee is not None + assert result is not None def test_update_licensee_not_found(mpt_client, licensee_factory, account_icon, invalid_licensee_id): @@ -86,9 +89,9 @@ def test_update_licensee_not_found(mpt_client, licensee_factory, account_icon, i def test_licensee_disable(mpt_client, created_licensee): - disabled_licensee = mpt_client.accounts.licensees.disable(created_licensee.id) + result = mpt_client.accounts.licensees.disable(created_licensee.id) - assert disabled_licensee is not None + assert result is not None def test_licensee_disable_not_found(mpt_client, invalid_licensee_id): @@ -99,9 +102,9 @@ def test_licensee_disable_not_found(mpt_client, invalid_licensee_id): def test_licensee_enable(mpt_client, created_licensee): mpt_client.accounts.licensees.disable(created_licensee.id) - enabled_licensee = mpt_client.accounts.licensees.enable(created_licensee.id) + result = mpt_client.accounts.licensees.enable(created_licensee.id) - assert enabled_licensee is not None + assert result is not None def test_licensee_enable_not_found(mpt_client, invalid_licensee_id): diff --git a/tests/e2e/accounts/modules/test_async_modules.py b/tests/e2e/accounts/modules/test_async_modules.py index f345f7de..055f1494 100644 --- a/tests/e2e/accounts/modules/test_async_modules.py +++ b/tests/e2e/accounts/modules/test_async_modules.py @@ -5,14 +5,17 @@ async def test_get_module_by_id(async_mpt_ops, module_id): - module = await async_mpt_ops.accounts.modules.get(module_id) - assert module is not None + result = await async_mpt_ops.accounts.modules.get(module_id) + + assert result is not None async def test_list_modules(async_mpt_ops): limit = 10 - modules = await async_mpt_ops.accounts.modules.fetch_page(limit=limit) - assert len(modules) > 0 + + result = await async_mpt_ops.accounts.modules.fetch_page(limit=limit) + + assert len(result) > 0 async def test_get_module_by_id_not_found(async_mpt_ops, invalid_module_id): @@ -22,13 +25,12 @@ async def test_get_module_by_id_not_found(async_mpt_ops, invalid_module_id): async def test_filter_modules(async_mpt_ops, module_id, module_name): select_fields = ["-description"] - filtered_modules = ( async_mpt_ops.accounts.modules.filter(RQLQuery(id=module_id)) .filter(RQLQuery(name=module_name)) .select(*select_fields) ) - modules = [filtered_module async for filtered_module in filtered_modules.iterate()] + result = [filtered_module async for filtered_module in filtered_modules.iterate()] - assert len(modules) == 1 + assert len(result) == 1 diff --git a/tests/e2e/accounts/modules/test_sync_modules.py b/tests/e2e/accounts/modules/test_sync_modules.py index dd121b95..4df5faaf 100644 --- a/tests/e2e/accounts/modules/test_sync_modules.py +++ b/tests/e2e/accounts/modules/test_sync_modules.py @@ -5,14 +5,17 @@ def test_get_module_by_id(mpt_ops, module_id): - module = mpt_ops.accounts.modules.get(module_id) - assert module is not None + result = mpt_ops.accounts.modules.get(module_id) + + assert result is not None def test_list_modules(mpt_ops): limit = 10 - modules = mpt_ops.accounts.modules.fetch_page(limit=limit) - assert len(modules) > 0 + + result = mpt_ops.accounts.modules.fetch_page(limit=limit) + + assert len(result) > 0 def test_get_module_by_id_not_found(mpt_ops, invalid_module_id): @@ -22,13 +25,12 @@ def test_get_module_by_id_not_found(mpt_ops, invalid_module_id): def test_filter_modules(mpt_ops, module_id, module_name): select_fields = ["-description"] - filtered_modules = ( mpt_ops.accounts.modules.filter(RQLQuery(id=module_id)) .filter(RQLQuery(name=module_name)) .select(*select_fields) ) - modules = list(filtered_modules.iterate()) + result = list(filtered_modules.iterate()) - assert len(modules) == 1 + assert len(result) == 1 diff --git a/tests/e2e/accounts/sellers/test_async_sellers.py b/tests/e2e/accounts/sellers/test_async_sellers.py index 3e90a82a..4ae5bd67 100644 --- a/tests/e2e/accounts/sellers/test_async_sellers.py +++ b/tests/e2e/accounts/sellers/test_async_sellers.py @@ -30,16 +30,17 @@ async def _async_created_seller( async def test_get_seller_by_id(async_mpt_ops, seller_id): - seller = await async_mpt_ops.accounts.sellers.get(seller_id) - assert seller is not None + result = await async_mpt_ops.accounts.sellers.get(seller_id) + + assert result is not None async def test_list_sellers(async_mpt_ops): limit = 10 - sellers = await async_mpt_ops.accounts.sellers.fetch_page(limit=limit) + result = await async_mpt_ops.accounts.sellers.fetch_page(limit=limit) - assert len(sellers) > 0 + assert len(result) > 0 async def test_get_seller_by_id_not_found(async_mpt_ops, invalid_seller_id): @@ -49,26 +50,27 @@ async def test_get_seller_by_id_not_found(async_mpt_ops, invalid_seller_id): async def test_filter_sellers(async_mpt_ops, seller_id): select_fields = ["-address"] - async_filtered_sellers = ( async_mpt_ops.accounts.sellers.filter(RQLQuery(id=seller_id)) .filter(RQLQuery(name="E2E Seeded Seller")) .select(*select_fields) ) - sellers = [filtered_seller async for filtered_seller in async_filtered_sellers.iterate()] + result = [filtered_seller async for filtered_seller in async_filtered_sellers.iterate()] - assert len(sellers) == 1 + assert len(result) == 1 async def test_create_seller(async_created_seller, timestamp): - seller_data = await async_created_seller(external_id=f"Async Create E2E Seller - {timestamp}") - assert seller_data is not None + result = await async_created_seller(external_id=f"Async Create E2E Seller - {timestamp}") + + assert result is not None async def test_delete_seller(async_mpt_ops, async_created_seller, timestamp): - seller_data = await async_created_seller(external_id=f"Async Delete E2E Seller - {timestamp}") - await async_mpt_ops.accounts.sellers.delete(seller_data.id) + result = await async_created_seller(external_id=f"Async Delete E2E Seller - {timestamp}") + + await async_mpt_ops.accounts.sellers.delete(result.id) async def test_delete_seller_not_found(async_mpt_ops, invalid_seller_id): @@ -82,8 +84,10 @@ async def test_update_seller(async_mpt_ops, seller_factory, async_created_seller external_id=f"Async Update E2E Seller - {timestamp}", name=f"Updated Update E2E Seller - {timestamp}", ) - updated_seller = await async_mpt_ops.accounts.sellers.update(seller_data.id, update_data) - assert updated_seller is not None + + result = await async_mpt_ops.accounts.sellers.update(seller_data.id, update_data) + + assert result is not None async def test_update_seller_mpt_error(async_mpt_ops, seller_factory, timestamp, invalid_seller_id): @@ -91,6 +95,7 @@ async def test_update_seller_mpt_error(async_mpt_ops, seller_factory, timestamp, external_id=f"Async Update E2E Seller Not Found - {timestamp}", name=f"Updated Update E2E Seller Not Found - {timestamp}", ) + with pytest.raises(MPTAPIError): await async_mpt_ops.accounts.sellers.update(invalid_seller_id, update_data) @@ -98,9 +103,10 @@ async def test_update_seller_mpt_error(async_mpt_ops, seller_factory, timestamp, async def test_activate_seller(async_mpt_ops, async_created_seller, timestamp): seller_data = await async_created_seller(external_id=f"Async Activate E2E Seller - {timestamp}") await async_mpt_ops.accounts.sellers.disable(seller_data.id) - activated_seller = await async_mpt_ops.accounts.sellers.activate(seller_data.id) - assert activated_seller is not None + result = await async_mpt_ops.accounts.sellers.activate(seller_data.id) + + assert result is not None async def test_activate_seller_mpt_error(async_mpt_ops, invalid_seller_id): @@ -112,9 +118,10 @@ async def test_deactivate_seller(async_mpt_ops, async_created_seller, timestamp) seller_data = await async_created_seller( external_id=f"Async Deactivate E2E Seller - {timestamp}" ) - deactivated_seller = await async_mpt_ops.accounts.sellers.disable(seller_data.id) - assert deactivated_seller is not None + result = await async_mpt_ops.accounts.sellers.disable(seller_data.id) + + assert result is not None async def test_deactivate_seller_mpt_error(async_mpt_ops, invalid_seller_id): @@ -124,9 +131,10 @@ async def test_deactivate_seller_mpt_error(async_mpt_ops, invalid_seller_id): async def test_disable_seller(async_mpt_ops, async_created_seller, timestamp): seller_data = await async_created_seller(external_id=f"Async Disable E2E Seller - {timestamp}") - disabled_seller = await async_mpt_ops.accounts.sellers.disable(seller_data.id) - assert disabled_seller is not None + result = await async_mpt_ops.accounts.sellers.disable(seller_data.id) + + assert result is not None async def test_disable_seller_mpt_error(async_mpt_ops, invalid_seller_id): diff --git a/tests/e2e/accounts/sellers/test_sync_sellers.py b/tests/e2e/accounts/sellers/test_sync_sellers.py index 14ff0e6d..20760e36 100644 --- a/tests/e2e/accounts/sellers/test_sync_sellers.py +++ b/tests/e2e/accounts/sellers/test_sync_sellers.py @@ -29,16 +29,17 @@ def _created_seller( def test_get_seller_by_id(mpt_ops, seller_id): - seller = mpt_ops.accounts.sellers.get(seller_id) - assert seller is not None + result = mpt_ops.accounts.sellers.get(seller_id) + + assert result is not None def test_list_sellers(mpt_ops): limit = 10 - sellers = mpt_ops.accounts.sellers.fetch_page(limit=limit) + result = mpt_ops.accounts.sellers.fetch_page(limit=limit) - assert len(sellers) > 0 + assert len(result) > 0 def test_get_seller_by_id_not_found(mpt_ops, invalid_seller_id): @@ -48,26 +49,27 @@ def test_get_seller_by_id_not_found(mpt_ops, invalid_seller_id): def test_filter_sellers(mpt_ops, seller_id): select_fields = ["-address"] - filtered_sellers = ( mpt_ops.accounts.sellers.filter(RQLQuery(id=seller_id)) .filter(RQLQuery(name="E2E Seeded Seller")) .select(*select_fields) ) - sellers = list(filtered_sellers.iterate()) + result = list(filtered_sellers.iterate()) - assert len(sellers) == 1 + assert len(result) == 1 def test_create_seller(created_seller, timestamp): - seller_data = created_seller(external_id=f"Create E2E Seller - {timestamp}") - assert seller_data is not None + result = created_seller(external_id=f"Create E2E Seller - {timestamp}") + + assert result is not None def test_delete_seller(mpt_ops, created_seller, timestamp): seller_data = created_seller(external_id=f"Delete E2E Seller - {timestamp}") - mpt_ops.accounts.sellers.delete(seller_data.id) + + mpt_ops.accounts.sellers.delete(seller_data.id) # act def test_delete_seller_not_found(mpt_ops, invalid_seller_id): @@ -81,8 +83,10 @@ def test_update_seller(mpt_ops, seller_factory, created_seller, timestamp): external_id=f"Update E2E Seller - {timestamp}", name=f"Updated Update E2E Seller - {timestamp}", ) - updated_seller = mpt_ops.accounts.sellers.update(seller_data.id, update_data) - assert updated_seller is not None + + result = mpt_ops.accounts.sellers.update(seller_data.id, update_data) + + assert result is not None def test_update_seller_mpt_error(mpt_ops, seller_factory, timestamp, invalid_seller_id): @@ -90,6 +94,7 @@ def test_update_seller_mpt_error(mpt_ops, seller_factory, timestamp, invalid_sel external_id=f"Async Update E2E Seller Not Found - {timestamp}", name=f"Updated Update E2E Seller Not Found - {timestamp}", ) + with pytest.raises(MPTAPIError): mpt_ops.accounts.sellers.update(invalid_seller_id, update_data) @@ -97,9 +102,10 @@ def test_update_seller_mpt_error(mpt_ops, seller_factory, timestamp, invalid_sel def test_activate_seller(mpt_ops, created_seller, timestamp): seller_data = created_seller(external_id=f"Activate E2E Seller - {timestamp}") mpt_ops.accounts.sellers.disable(seller_data.id) - activated_seller = mpt_ops.accounts.sellers.activate(seller_data.id) - assert activated_seller is not None + result = mpt_ops.accounts.sellers.activate(seller_data.id) + + assert result is not None def test_activate_seller_mpt_error(mpt_ops, invalid_seller_id): @@ -109,9 +115,10 @@ def test_activate_seller_mpt_error(mpt_ops, invalid_seller_id): def test_deactivate_seller(mpt_ops, created_seller, timestamp): seller_data = created_seller(external_id=f"Deactivate E2E Seller - {timestamp}") - deactivated_seller = mpt_ops.accounts.sellers.disable(seller_data.id) - assert deactivated_seller is not None + result = mpt_ops.accounts.sellers.disable(seller_data.id) + + assert result is not None def test_deactivate_seller_mpt_error(mpt_ops, invalid_seller_id): @@ -121,9 +128,10 @@ def test_deactivate_seller_mpt_error(mpt_ops, invalid_seller_id): def test_disable_seller(mpt_ops, created_seller, timestamp): seller_data = created_seller(external_id=f"Disable E2E Seller - {timestamp}") - disabled_seller = mpt_ops.accounts.sellers.disable(seller_data.id) - assert disabled_seller is not None + result = mpt_ops.accounts.sellers.disable(seller_data.id) + + assert result is not None def test_disable_seller_mpt_error(mpt_ops, invalid_seller_id): diff --git a/tests/e2e/accounts/user_groups/test_async_user_groups.py b/tests/e2e/accounts/user_groups/test_async_user_groups.py index 324070c4..d93d85c7 100644 --- a/tests/e2e/accounts/user_groups/test_async_user_groups.py +++ b/tests/e2e/accounts/user_groups/test_async_user_groups.py @@ -28,8 +28,10 @@ async def test_get_user_group_by_id(async_mpt_ops, user_group_id): async def test_list_user_groups(async_mpt_ops): limit = 10 - user_groups = await async_mpt_ops.accounts.user_groups.fetch_page(limit=limit) - assert len(user_groups) > 0 + + result = await async_mpt_ops.accounts.user_groups.fetch_page(limit=limit) + + assert len(result) > 0 async def test_get_user_group_by_id_not_found(async_mpt_ops, invalid_user_group_id): @@ -39,27 +41,25 @@ async def test_get_user_group_by_id_not_found(async_mpt_ops, invalid_user_group_ async def test_filter_user_groups(async_mpt_ops, user_group_id): select_fields = ["-name"] - filtered_user_groups = ( async_mpt_ops.accounts.user_groups.filter(RQLQuery(id=user_group_id)) .filter(RQLQuery(name="E2E Seeded User Group")) .select(*select_fields) ) - user_groups = [ - filtered_user_group async for filtered_user_group in filtered_user_groups.iterate() - ] + result = [filtered_user_group async for filtered_user_group in filtered_user_groups.iterate()] - assert len(user_groups) == 1 + assert len(result) == 1 def test_create_user_group(created_user_group): - new_user_group = created_user_group - assert new_user_group is not None + result = created_user_group + + assert result is not None async def test_delete_user_group(async_mpt_ops, created_user_group): - await async_mpt_ops.accounts.user_groups.delete(created_user_group.id) + await async_mpt_ops.accounts.user_groups.delete(created_user_group.id) # act async def test_delete_user_group_not_found(async_mpt_ops, invalid_user_group_id): @@ -70,11 +70,11 @@ async def test_delete_user_group_not_found(async_mpt_ops, invalid_user_group_id) async def test_update_user_group(async_mpt_ops, user_group_factory, created_user_group): updated_user_group_data = user_group_factory(name="E2E Updated User Group") - updated_user_group = await async_mpt_ops.accounts.user_groups.update( + result = await async_mpt_ops.accounts.user_groups.update( created_user_group.id, updated_user_group_data ) - assert updated_user_group is not None + assert result is not None async def test_update_user_group_not_found( diff --git a/tests/e2e/accounts/user_groups/test_sync_user_groups.py b/tests/e2e/accounts/user_groups/test_sync_user_groups.py index bbd3cf45..228a1147 100644 --- a/tests/e2e/accounts/user_groups/test_sync_user_groups.py +++ b/tests/e2e/accounts/user_groups/test_sync_user_groups.py @@ -20,14 +20,17 @@ def created_user_group(mpt_ops, user_group_factory): def test_get_user_group_by_id(mpt_ops, user_group_id): - user_group = mpt_ops.accounts.user_groups.get(user_group_id) - assert user_group is not None + result = mpt_ops.accounts.user_groups.get(user_group_id) + + assert result is not None def test_list_user_groups(mpt_ops): limit = 10 - user_groups = mpt_ops.accounts.user_groups.fetch_page(limit=limit) - assert len(user_groups) > 0 + + result = mpt_ops.accounts.user_groups.fetch_page(limit=limit) + + assert len(result) > 0 def test_get_user_group_by_id_not_found(mpt_ops, invalid_user_group_id): @@ -37,25 +40,25 @@ def test_get_user_group_by_id_not_found(mpt_ops, invalid_user_group_id): def test_filter_user_groups(mpt_ops, user_group_id): select_fields = ["-name"] - filtered_user_groups = ( mpt_ops.accounts.user_groups.filter(RQLQuery(id=user_group_id)) .filter(RQLQuery(name="E2E Seeded User Group")) .select(*select_fields) ) - user_groups = list(filtered_user_groups.iterate()) + result = list(filtered_user_groups.iterate()) - assert len(user_groups) == 1 + assert len(result) == 1 def test_create_user_group(created_user_group): - new_user_group = created_user_group - assert new_user_group is not None + result = created_user_group + + assert result is not None def test_delete_user_group(mpt_ops, created_user_group): - mpt_ops.accounts.user_groups.delete(created_user_group.id) + mpt_ops.accounts.user_groups.delete(created_user_group.id) # act def test_delete_user_group_not_found(mpt_ops, invalid_user_group_id): @@ -66,11 +69,9 @@ def test_delete_user_group_not_found(mpt_ops, invalid_user_group_id): def test_update_user_group(mpt_ops, user_group_factory, created_user_group): updated_user_group_data = user_group_factory(name="E2E Updated User Group") - updated_user_group = mpt_ops.accounts.user_groups.update( - created_user_group.id, updated_user_group_data - ) + result = mpt_ops.accounts.user_groups.update(created_user_group.id, updated_user_group_data) - assert updated_user_group is not None + assert result is not None def test_update_user_group_not_found(mpt_ops, user_group_factory, invalid_user_group_id): diff --git a/tests/e2e/catalog/items/test_async_item.py b/tests/e2e/catalog/items/test_async_item.py index baf5bc7a..fa104f88 100644 --- a/tests/e2e/catalog/items/test_async_item.py +++ b/tests/e2e/catalog/items/test_async_item.py @@ -18,14 +18,18 @@ async def async_created_item(logger, async_mpt_vendor, item_data): def test_create_item(async_created_item): - assert async_created_item.name == "e2e - please delete" + result = async_created_item.name == "e2e - please delete" + + assert result is True async def test_update_item(async_mpt_vendor, async_created_item): service = async_mpt_vendor.catalog.items update_data = {"name": "e2e - delete me (updated)"} - item = await service.update(async_created_item.id, update_data) - assert item.name == "e2e - delete me (updated)" + + result = await service.update(async_created_item.id, update_data) + + assert result.name == "e2e - delete me (updated)" @pytest.mark.skip(reason="Leaves test items in the catalog") @@ -39,31 +43,41 @@ async def test_review_and_publish_item(async_mpt_vendor, async_mpt_ops, async_cr async def test_get_item(async_mpt_vendor, item_id): service = async_mpt_vendor.catalog.items - item = await service.get(item_id) - assert item.id == item_id + + result = await service.get(item_id) + + assert result.id == item_id async def test_iterate_items(async_mpt_vendor, async_created_item): service = async_mpt_vendor.catalog.items items = [item async for item in service.iterate()] - assert any(item.id == async_created_item.id for item in items) + + result = any(item.id == async_created_item.id for item in items) + + assert result is True async def test_filter(async_mpt_vendor, item_id): service = async_mpt_vendor.catalog.items - items = [item async for item in service.filter(RQLQuery(id=item_id)).iterate()] - assert len(items) == 1 - assert items[0].id == item_id + + result = [item async for item in service.filter(RQLQuery(id=item_id)).iterate()] + + assert len(result) == 1 + assert result[0].id == item_id async def test_not_found(async_mpt_vendor): service = async_mpt_vendor.catalog.items + with pytest.raises(MPTAPIError): await service.get("ITM-000-000") async def test_delete_item(async_mpt_vendor, async_created_item): service = async_mpt_vendor.catalog.items - await service.delete(async_created_item.id) + + await service.delete(async_created_item.id) # act + with pytest.raises(MPTAPIError): await service.get(async_created_item.id) diff --git a/tests/e2e/catalog/items/test_sync_item.py b/tests/e2e/catalog/items/test_sync_item.py index e3498ab6..e952489b 100644 --- a/tests/e2e/catalog/items/test_sync_item.py +++ b/tests/e2e/catalog/items/test_sync_item.py @@ -18,17 +18,21 @@ def created_item(logger, mpt_vendor, item_data): def test_create_item(created_item): - assert created_item.name == "e2e - please delete" + result = created_item.name == "e2e - please delete" + + assert result is True def test_update_item(mpt_vendor, created_item): service = mpt_vendor.catalog.items update_data = {"name": "please delete me"} - item = service.update(created_item.id, update_data) - assert item.name == "please delete me" + + result = service.update(created_item.id, update_data) + + assert result.name == "please delete me" -@pytest.mark.skip(reason="Leaves test items in the catalog") +@pytest.mark.skip(reason="Leaves test items in the catalog") # noqa: AAA01 def test_review_and_publish_item(mpt_vendor, mpt_ops, created_item): item = mpt_vendor.catalog.items.review(created_item.id) assert item.status == "Pending" @@ -39,31 +43,41 @@ def test_review_and_publish_item(mpt_vendor, mpt_ops, created_item): def test_get_item(mpt_vendor, item_id): service = mpt_vendor.catalog.items - item = service.get(item_id) - assert item.id == item_id + + result = service.get(item_id) + + assert result.id == item_id def test_iterate_items(mpt_vendor, created_item): service = mpt_vendor.catalog.items items = list(service.iterate()) - assert any(item.id == created_item.id for item in items) + + result = any(item.id == created_item.id for item in items) + + assert result is True def test_filter(mpt_vendor, item_id): service = mpt_vendor.catalog.items - items = list(service.filter(RQLQuery(id=item_id)).iterate()) - assert len(items) == 1 - assert items[0].id == item_id + + result = list(service.filter(RQLQuery(id=item_id)).iterate()) + + assert len(result) == 1 + assert result[0].id == item_id def test_not_found(mpt_vendor): service = mpt_vendor.catalog.items + with pytest.raises(MPTAPIError): service.get("ITM-000-000") def test_delete_item(mpt_vendor, created_item): service = mpt_vendor.catalog.items - service.delete(created_item.id) + + service.delete(created_item.id) # act + with pytest.raises(MPTAPIError): service.get(created_item.id) diff --git a/tests/e2e/catalog/pricing_policies/test_async_pricing_policies.py b/tests/e2e/catalog/pricing_policies/test_async_pricing_policies.py index 07dc685c..f41c5f2f 100644 --- a/tests/e2e/catalog/pricing_policies/test_async_pricing_policies.py +++ b/tests/e2e/catalog/pricing_policies/test_async_pricing_policies.py @@ -24,26 +24,33 @@ async def async_created_pricing_policy(async_pricing_policies_service, pricing_p def test_create_pricing_policy(async_created_pricing_policy, pricing_policy_data): - assert async_created_pricing_policy.name == pricing_policy_data["name"] + result = async_created_pricing_policy + + assert result.name == pricing_policy_data["name"] async def test_get_pricing_policy(async_pricing_policies_service, async_created_pricing_policy): - fetched = await async_pricing_policies_service.get(async_created_pricing_policy.id) - assert fetched.id == async_created_pricing_policy.id + result = await async_pricing_policies_service.get(async_created_pricing_policy.id) + + assert result.id == async_created_pricing_policy.id async def test_get_pricing_policy_by_id( async_pricing_policies_service, async_created_pricing_policy ): - fetched = await async_pricing_policies_service.get(async_created_pricing_policy.id) - assert fetched.id == async_created_pricing_policy.id + result = await async_pricing_policies_service.get(async_created_pricing_policy.id) + + assert result.id == async_created_pricing_policy.id async def test_iterate_pricing_policies( async_pricing_policies_service, async_created_pricing_policy ): policies = [policy async for policy in async_pricing_policies_service.iterate()] - assert any(policy.id == async_created_pricing_policy.id for policy in policies) + + result = any(policy.id == async_created_pricing_policy.id for policy in policies) + + assert result is True async def test_filter_pricing_policies( @@ -52,12 +59,14 @@ async def test_filter_pricing_policies( target_id = async_created_pricing_policy.id select_fields = ["-description"] filtered = async_pricing_policies_service.filter(RQLQuery(id=target_id)).select(*select_fields) - policies = [policy async for policy in filtered.iterate()] - assert len(policies) == 1 - assert policies[0].id == target_id + result = [policy async for policy in filtered.iterate()] -async def test_activate_deactivate_pricing_policy( + assert len(result) == 1 + assert result[0].id == target_id + + +async def test_activate_deactivate_pricing_policy( # noqa: AAA01 async_pricing_policies_service, async_created_pricing_policy ): deactivate = await async_pricing_policies_service.disable(async_created_pricing_policy.id) @@ -73,11 +82,13 @@ async def test_delete_pricing_policy(async_pricing_policies_service, async_creat async def test_get_pricing_policy_not_found(async_pricing_policies_service): bogus_id = "PPY-0000-NOTFOUND" + with pytest.raises(MPTAPIError, match=r"404 Not Found"): await async_pricing_policies_service.get(bogus_id) async def test_create_pricing_policy_invalid_data(async_pricing_policies_service): invalid_data = {"name": "e2e - delete me", "description": "invalid data"} + with pytest.raises(MPTAPIError, match=r"400 One or more validation errors occurred"): await async_pricing_policies_service.create(invalid_data) diff --git a/tests/e2e/catalog/pricing_policies/test_sync_pricing_policies.py b/tests/e2e/catalog/pricing_policies/test_sync_pricing_policies.py index ba479509..64ac8539 100644 --- a/tests/e2e/catalog/pricing_policies/test_sync_pricing_policies.py +++ b/tests/e2e/catalog/pricing_policies/test_sync_pricing_policies.py @@ -24,36 +24,46 @@ def created_pricing_policy(pricing_policies_service, pricing_policy_data): def test_create_pricing_policy(created_pricing_policy, pricing_policy_data): - assert created_pricing_policy.name == pricing_policy_data["name"] + result = created_pricing_policy + + assert result.name == pricing_policy_data["name"] def test_get_pricing_policy(pricing_policies_service, created_pricing_policy): - fetched = pricing_policies_service.get(created_pricing_policy.id) - assert fetched.id == created_pricing_policy.id + result = pricing_policies_service.get(created_pricing_policy.id) + + assert result.id == created_pricing_policy.id def test_get_pricing_policy_by_id(pricing_policies_service, pricing_policy_id): if not pricing_policy_id: pytest.skip("No pricing_policy_id configured") - fetched = pricing_policies_service.get(pricing_policy_id) - assert fetched.id == pricing_policy_id + + result = pricing_policies_service.get(pricing_policy_id) + + assert result.id == pricing_policy_id def test_iterate_pricing_policies(pricing_policies_service, created_pricing_policy): policies = list(pricing_policies_service.iterate()) - assert any(policy.id == created_pricing_policy.id for policy in policies) + + result = any(policy.id == created_pricing_policy.id for policy in policies) + + assert result is True def test_filter_pricing_policies(pricing_policies_service, created_pricing_policy): target_id = created_pricing_policy.id select_fields = ["-description"] filtered = pricing_policies_service.filter(RQLQuery(id=target_id)).select(*select_fields) - policies = list(filtered.iterate()) - assert len(policies) == 1 - assert policies[0].id == target_id + + result = list(filtered.iterate()) + + assert len(result) == 1 + assert result[0].id == target_id -def test_activate_deactivate_pricing_policy(pricing_policies_service, created_pricing_policy): +def test_activate_deactivate_pricing_policy(pricing_policies_service, created_pricing_policy): # noqa: AAA01 deactivate = pricing_policies_service.disable(created_pricing_policy.id) assert deactivate.id == created_pricing_policy.id @@ -67,11 +77,13 @@ def test_delete_pricing_policy(pricing_policies_service, created_pricing_policy) def test_get_pricing_policy_not_found(pricing_policies_service): bogus_id = "PPY-0000-NOTFOUND" + with pytest.raises(MPTAPIError, match=r"404 Not Found"): pricing_policies_service.get(bogus_id) def test_create_pricing_policy_invalid_data(pricing_policies_service): invalid_data = {"name": "e2e - delete me", "description": "invalid data"} + with pytest.raises(MPTAPIError, match=r"400 One or more validation errors occurred"): pricing_policies_service.create(invalid_data) diff --git a/tests/e2e/catalog/product/documents/test_async_document.py b/tests/e2e/catalog/product/documents/test_async_document.py index e923bb00..f8c15148 100644 --- a/tests/e2e/catalog/product/documents/test_async_document.py +++ b/tests/e2e/catalog/product/documents/test_async_document.py @@ -33,36 +33,43 @@ async def created_document_from_link_async(logger, async_document_service, docum print(f"TEARDOWN - Unable to delete document {document.id}: {error.title}") -def test_create_document_async(created_document_from_file_async, document_data): +def test_create_document_async(created_document_from_file_async, document_data): # noqa: AAA01 assert created_document_from_file_async.name == document_data["name"] assert created_document_from_file_async.description == document_data["description"] -def test_create_from_link_async(created_document_from_link_async, pdf_url, document_data): +def test_create_from_link_async(created_document_from_link_async, pdf_url, document_data): # noqa: AAA01 assert created_document_from_link_async.name == document_data["name"] assert created_document_from_link_async.description == document_data["description"] async def test_update_document_async(async_document_service, created_document_from_file_async): update_data = {"name": "Updated e2e test document - please delete"} - document = await async_document_service.update(created_document_from_file_async.id, update_data) - assert document.name == update_data["name"] + + result = await async_document_service.update(created_document_from_file_async.id, update_data) + + assert result.name == update_data["name"] async def test_get_document_async(async_document_service, document_id): - document = await async_document_service.get(document_id) - assert document.id == document_id + result = await async_document_service.get(document_id) + + assert result.id == document_id async def test_download_document_async(async_document_service, document_id): - file_response = await async_document_service.download(document_id) - assert file_response.file_contents is not None - assert file_response.filename == "pdf - empty.pdf" + result = await async_document_service.download(document_id) + + assert result.file_contents is not None + assert result.filename == "pdf - empty.pdf" async def test_iterate_documents_async(async_document_service, created_document_from_file_async): documents = [doc async for doc in async_document_service.iterate()] - assert any(doc.id == created_document_from_file_async.id for doc in documents) + + result = any(doc.id == created_document_from_file_async.id for doc in documents) + + assert result is True async def test_filter_documents_async(async_document_service, created_document_from_file_async): diff --git a/tests/e2e/catalog/product/documents/test_sync_document.py b/tests/e2e/catalog/product/documents/test_sync_document.py index 0e2da5f2..2283813a 100644 --- a/tests/e2e/catalog/product/documents/test_sync_document.py +++ b/tests/e2e/catalog/product/documents/test_sync_document.py @@ -28,47 +28,55 @@ def created_document_from_url(logger, vendor_document_service, document_data, pd print(f"TEARDOWN - Unable to delete document {document.id}: {error.title}") -def test_create_document(created_document_from_file, document_data): +def test_create_document(created_document_from_file, document_data): # noqa: AAA01 assert created_document_from_file.name == document_data["name"] assert created_document_from_file.description == document_data["description"] -def test_create_document_from_url(created_document_from_url, document_data): +def test_create_document_from_url(created_document_from_url, document_data): # noqa: AAA01 assert created_document_from_url.name == document_data["name"] assert created_document_from_url.description == document_data["description"] def test_update_document(vendor_document_service, created_document_from_file): update_data = {"name": "Updated e2e test document - please delete"} - document = vendor_document_service.update(created_document_from_file.id, update_data) - assert document.name == update_data["name"] + + result = vendor_document_service.update(created_document_from_file.id, update_data) + + assert result.name == update_data["name"] def test_get_document(vendor_document_service, document_id): - document = vendor_document_service.get(document_id) - assert document.id == document_id + result = vendor_document_service.get(document_id) + + assert result.id == document_id def test_download_document(vendor_document_service, document_id): - file_response = vendor_document_service.download(document_id) - assert file_response.file_contents is not None - assert file_response.filename == "pdf - empty.pdf" + result = vendor_document_service.download(document_id) + + assert result.file_contents is not None + assert result.filename == "pdf - empty.pdf" def test_iterate_documents(vendor_document_service, created_document_from_file): documents = list(vendor_document_service.iterate()) - assert any(doc.id == created_document_from_file.id for doc in documents) + + result = any(doc.id == created_document_from_file.id for doc in documents) + + assert result is True def test_filter_documents(vendor_document_service, created_document_from_file): - documents = list( + result = list( vendor_document_service.filter(RQLQuery(id=created_document_from_file.id)).iterate() ) - assert len(documents) == 1 - assert documents[0].id == created_document_from_file.id + assert len(result) == 1 + assert result[0].id == created_document_from_file.id -@pytest.mark.skip(reason="Leaves test documents in published state") + +@pytest.mark.skip(reason="Leaves test documents in published state") # noqa: AAA01 def test_review_and_publish_document(mpt_vendor, mpt_ops, created_document_from_file, product_id): vendor_service = mpt_vendor.catalog.products.documents(product_id) ops_service = mpt_ops.catalog.products.documents(product_id) @@ -89,6 +97,7 @@ def test_not_found(vendor_document_service): def test_delete_document(vendor_document_service, created_document_from_file): - vendor_document_service.delete(created_document_from_file.id) + vendor_document_service.delete(created_document_from_file.id) # act + with pytest.raises(MPTAPIError): vendor_document_service.get(created_document_from_file.id) diff --git a/tests/e2e/catalog/product/item_groups/test_async_item_groups.py b/tests/e2e/catalog/product/item_groups/test_async_item_groups.py index e28a3f1d..a0174d2d 100644 --- a/tests/e2e/catalog/product/item_groups/test_async_item_groups.py +++ b/tests/e2e/catalog/product/item_groups/test_async_item_groups.py @@ -18,36 +18,43 @@ async def async_created_item_group(logger, async_mpt_vendor, product_id, item_gr def test_create_item_group(async_created_item_group): - assert async_created_item_group.name == "e2e - please delete" + result = async_created_item_group.name == "e2e - please delete" + + assert result is True async def test_update_item_group(async_mpt_vendor, product_id, async_created_item_group): service = async_mpt_vendor.catalog.products.item_groups(product_id) update_data = {"name": "e2e - delete me (updated)"} - group = await service.update(async_created_item_group.id, update_data) - assert group.name == "e2e - delete me (updated)" + + result = await service.update(async_created_item_group.id, update_data) + + assert result.name == "e2e - delete me (updated)" async def test_get_item_group(async_mpt_vendor, product_id, item_group_id): service = async_mpt_vendor.catalog.products.item_groups(product_id) - group = await service.get(item_group_id) - assert group.id == item_group_id + + result = await service.get(item_group_id) + + assert result.id == item_group_id async def test_get_item_group_by_id(async_mpt_vendor, product_id, item_group_id): service = async_mpt_vendor.catalog.products.item_groups(product_id) - group = await service.get(item_group_id) + result = await service.get(item_group_id) - assert group.id == item_group_id + assert result.id == item_group_id async def test_iterate_item_groups(async_mpt_vendor, product_id, async_created_item_group): service = async_mpt_vendor.catalog.products.item_groups(product_id) - groups = [group async for group in service.iterate()] - assert any(group.id == async_created_item_group.id for group in groups) + result = any(group.id == async_created_item_group.id for group in groups) + + assert result is True async def test_filter_item_groups(async_mpt_vendor, product_id, item_group_id): @@ -58,16 +65,16 @@ async def test_filter_item_groups(async_mpt_vendor, product_id, item_group_id): .select(*select_fields) ) - groups = [group async for group in filtered_item_groups.iterate()] + result = [group async for group in filtered_item_groups.iterate()] - assert len(groups) == 1 - assert groups[0].id == item_group_id + assert len(result) == 1 + assert result[0].id == item_group_id async def test_delete_item_group(async_mpt_vendor, product_id, async_created_item_group): service = async_mpt_vendor.catalog.products.item_groups(product_id) - await service.delete(async_created_item_group.id) + await service.delete(async_created_item_group.id) # act with pytest.raises(MPTAPIError): await service.get(async_created_item_group.id) diff --git a/tests/e2e/catalog/product/item_groups/test_sync_item_groups.py b/tests/e2e/catalog/product/item_groups/test_sync_item_groups.py index 4e7dc0c5..87afd306 100644 --- a/tests/e2e/catalog/product/item_groups/test_sync_item_groups.py +++ b/tests/e2e/catalog/product/item_groups/test_sync_item_groups.py @@ -18,38 +18,43 @@ def created_item_group(logger, mpt_vendor, product_id, item_group_data): def test_create_item_group(created_item_group): - assert created_item_group.name == "e2e - please delete" + result = created_item_group.name == "e2e - please delete" + + assert result is True def test_update_item_group(mpt_vendor, product_id, created_item_group): service = mpt_vendor.catalog.products.item_groups(product_id) update_data = {"name": "please delete me"} - group = service.update(created_item_group.id, update_data) + result = service.update(created_item_group.id, update_data) - assert group.name == "please delete me" + assert result.name == "please delete me" def test_get_item_group(mpt_vendor, product_id, created_item_group): service = mpt_vendor.catalog.products.item_groups(product_id) - group = service.get(created_item_group.id) + result = service.get(created_item_group.id) - assert group.id == created_item_group.id + assert result.id == created_item_group.id def test_get_item_group_by_id(mpt_vendor, product_id, item_group_id): service = mpt_vendor.catalog.products.item_groups(product_id) - group = service.get(item_group_id) + result = service.get(item_group_id) - assert group.id == item_group_id + assert result.id == item_group_id def test_iterate_item_groups(mpt_vendor, product_id, created_item_group): service = mpt_vendor.catalog.products.item_groups(product_id) groups = list(service.iterate()) - assert any(group.id == created_item_group.id for group in groups) + + result = any(group.id == created_item_group.id for group in groups) + + assert result is True def test_filter_item_groups(mpt_vendor, product_id, item_group_id): @@ -59,13 +64,17 @@ def test_filter_item_groups(mpt_vendor, product_id, item_group_id): .filter(RQLQuery(id=item_group_id)) .select(*select_fields) ) - groups = list(filtered_item_groups.iterate()) - assert len(groups) == 1 - assert groups[0].id == item_group_id + + result = list(filtered_item_groups.iterate()) + + assert len(result) == 1 + assert result[0].id == item_group_id def test_delete_item_group(mpt_vendor, product_id, created_item_group): service = mpt_vendor.catalog.products.item_groups(product_id) - service.delete(created_item_group.id) + + service.delete(created_item_group.id) # act + with pytest.raises(MPTAPIError): service.get(created_item_group.id) diff --git a/tests/e2e/catalog/product/media/test_async_media.py b/tests/e2e/catalog/product/media/test_async_media.py index 41a1ae0f..f60f3e44 100644 --- a/tests/e2e/catalog/product/media/test_async_media.py +++ b/tests/e2e/catalog/product/media/test_async_media.py @@ -36,20 +36,22 @@ async def created_media_from_url_async(logger, async_media_service, media_data, print(f"TEARDOWN - Unable to delete media {media.id}: {error.title}") -def test_create_media_async(created_media_from_file_async, media_data): +def test_create_media_async(created_media_from_file_async, media_data): # noqa: AAA01 assert created_media_from_file_async.name == media_data["name"] assert created_media_from_file_async.description == media_data["description"] -def test_create_media_async_from_url(created_media_from_file_async, media_data): +def test_create_media_async_from_url(created_media_from_file_async, media_data): # noqa: AAA01 assert created_media_from_file_async.name == media_data["name"] assert created_media_from_file_async.description == media_data["description"] async def test_update_media_async(async_media_service, created_media_from_file_async): update_data = {"name": "Updated e2e test media - please delete"} - media = await async_media_service.update(created_media_from_file_async.id, update_data) - assert media.name == update_data["name"] + + result = await async_media_service.update(created_media_from_file_async.id, update_data) + + assert result.name == update_data["name"] async def test_media_lifecycle_async( @@ -67,20 +69,23 @@ async def test_media_lifecycle_async( async def test_delete_media_async(async_vendor_media_service, created_media_from_file_async): - await async_vendor_media_service.delete(created_media_from_file_async.id) + await async_vendor_media_service.delete(created_media_from_file_async.id) # act + with pytest.raises(MPTAPIError): await async_vendor_media_service.get(created_media_from_file_async.id) async def test_get_media_async(async_vendor_media_service, created_media_from_file_async): - media = await async_vendor_media_service.get(created_media_from_file_async.id) - assert media.id == created_media_from_file_async.id + result = await async_vendor_media_service.get(created_media_from_file_async.id) + + assert result.id == created_media_from_file_async.id async def test_download_media_async(async_vendor_media_service, created_media_from_file_async): - file_response = await async_vendor_media_service.download(created_media_from_file_async.id) - assert file_response.file_contents is not None - assert file_response.filename == "logo.png" + result = await async_vendor_media_service.download(created_media_from_file_async.id) + + assert result.file_contents is not None + assert result.filename == "logo.png" async def test_get_not_found_media_async(async_vendor_media_service): diff --git a/tests/e2e/catalog/product/media/test_sync_media.py b/tests/e2e/catalog/product/media/test_sync_media.py index f7c9eafd..2956d074 100644 --- a/tests/e2e/catalog/product/media/test_sync_media.py +++ b/tests/e2e/catalog/product/media/test_sync_media.py @@ -31,23 +31,25 @@ def created_media_from_url(logger, vendor_media_service, media_data, jpg_url): print(f"TEARDOWN - Unable to delete media {media.id}: {error.title}") -def test_create_media(created_media_from_file, media_data): +def test_create_media(created_media_from_file, media_data): # noqa: AAA01 assert created_media_from_file.name == media_data["name"] assert created_media_from_file.description == media_data["description"] -def test_create_media_from_url(created_media_from_file, media_data): +def test_create_media_from_url(created_media_from_file, media_data): # noqa: AAA01 assert created_media_from_file.name == media_data["name"] assert created_media_from_file.description == media_data["description"] def test_update_media(vendor_media_service, created_media_from_file): update_data = {"name": "Updated e2e test media - please delete"} - media = vendor_media_service.update(created_media_from_file.id, update_data) - assert media.name == update_data["name"] + result = vendor_media_service.update(created_media_from_file.id, update_data) -def test_media_lifecycle(mpt_vendor, mpt_ops, created_media_from_file): + assert result.name == update_data["name"] + + +def test_media_lifecycle(mpt_vendor, mpt_ops, created_media_from_file): # noqa: AAA01 mpt_vendor.catalog.products.media(created_media_from_file.product.id).review( created_media_from_file.id ) @@ -61,19 +63,22 @@ def test_media_lifecycle(mpt_vendor, mpt_ops, created_media_from_file): def test_delete_media(vendor_media_service, created_media_from_file): vendor_media_service.delete(created_media_from_file.id) + with pytest.raises(MPTAPIError): vendor_media_service.get(created_media_from_file.id) def test_get_media(vendor_media_service, created_media_from_file): - media = vendor_media_service.get(created_media_from_file.id) - assert media.id == created_media_from_file.id + result = vendor_media_service.get(created_media_from_file.id) + + assert result.id == created_media_from_file.id def test_download_media(vendor_media_service, created_media_from_file): - file_response = vendor_media_service.download(created_media_from_file.id) - assert file_response.file_contents is not None - assert file_response.filename == "logo.png" + result = vendor_media_service.download(created_media_from_file.id) + + assert result.file_contents is not None + assert result.filename == "logo.png" async def test_get_not_found_media(vendor_media_service): diff --git a/tests/e2e/catalog/product/parameter_groups/test_async_parameter_groups.py b/tests/e2e/catalog/product/parameter_groups/test_async_parameter_groups.py index 94c485bb..564392e6 100644 --- a/tests/e2e/catalog/product/parameter_groups/test_async_parameter_groups.py +++ b/tests/e2e/catalog/product/parameter_groups/test_async_parameter_groups.py @@ -16,22 +16,28 @@ async def async_created_parameter_group(logger, async_mpt_vendor, product_id, pa @pytest.mark.flaky def test_create_parameter_group(async_created_parameter_group): - assert async_created_parameter_group.name == "e2e - please delete" + result = async_created_parameter_group.name == "e2e - please delete" + + assert result is True @pytest.mark.flaky async def test_update_parameter_group(async_mpt_vendor, product_id, async_created_parameter_group): service = async_mpt_vendor.catalog.products.parameter_groups(product_id) update_data = {"name": "e2e - delete me (updated)"} - group = await service.update(async_created_parameter_group.id, update_data) - assert group.name == "e2e - delete me (updated)" + + result = await service.update(async_created_parameter_group.id, update_data) + + assert result.name == "e2e - delete me (updated)" @pytest.mark.flaky async def test_get_parameter_group(async_mpt_vendor, product_id, parameter_group_id): service = async_mpt_vendor.catalog.products.parameter_groups(product_id) - group = await service.get(parameter_group_id) - assert group.id == parameter_group_id + + result = await service.get(parameter_group_id) + + assert result.id == parameter_group_id @pytest.mark.flaky @@ -40,12 +46,16 @@ async def test_iterate_parameter_groups( ): service = async_mpt_vendor.catalog.products.parameter_groups(product_id) groups = [group async for group in service.iterate()] - assert any(group.id == async_created_parameter_group.id for group in groups) + + result = any(group.id == async_created_parameter_group.id for group in groups) + + assert result is True @pytest.mark.flaky async def test_delete_parameter_group(async_mpt_vendor, product_id, async_created_parameter_group): service = async_mpt_vendor.catalog.products.parameter_groups(product_id) await service.delete(async_created_parameter_group.id) + with pytest.raises(MPTAPIError): await service.get(async_created_parameter_group.id) diff --git a/tests/e2e/catalog/product/parameter_groups/test_sync_parameter_groups.py b/tests/e2e/catalog/product/parameter_groups/test_sync_parameter_groups.py index 0cd68f64..d8655c8e 100644 --- a/tests/e2e/catalog/product/parameter_groups/test_sync_parameter_groups.py +++ b/tests/e2e/catalog/product/parameter_groups/test_sync_parameter_groups.py @@ -16,34 +16,45 @@ def created_parameter_group(logger, mpt_vendor, product_id, parameter_group_data @pytest.mark.flaky def test_create_parameter_group(created_parameter_group): - assert created_parameter_group.name == "e2e - please delete" + result = created_parameter_group.name == "e2e - please delete" + + assert result is True @pytest.mark.flaky def test_update_parameter_group(mpt_vendor, product_id, created_parameter_group): service = mpt_vendor.catalog.products.parameter_groups(product_id) update_data = {"name": "please delete me"} - group = service.update(created_parameter_group.id, update_data) - assert group.name == "please delete me" + + result = service.update(created_parameter_group.id, update_data) + + assert result.name == "please delete me" @pytest.mark.flaky def test_get_parameter_group_get(mpt_vendor, product_id, parameter_group_id): service = mpt_vendor.catalog.products.parameter_groups(product_id) - group = service.get(parameter_group_id) - assert group.id == parameter_group_id + + result = service.get(parameter_group_id) + + assert result.id == parameter_group_id @pytest.mark.flaky def test_iterate_parameter_groups(mpt_vendor, product_id, created_parameter_group): service = mpt_vendor.catalog.products.parameter_groups(product_id) groups = list(service.iterate()) - assert any(group.id == created_parameter_group.id for group in groups) + + result = any(group.id == created_parameter_group.id for group in groups) + + assert result is True @pytest.mark.flaky def test_delete_parameter_group(mpt_vendor, product_id, created_parameter_group): service = mpt_vendor.catalog.products.parameter_groups(product_id) - service.delete(created_parameter_group.id) + + service.delete(created_parameter_group.id) # act + with pytest.raises(MPTAPIError): service.get(created_parameter_group.id) diff --git a/tests/e2e/catalog/product/parameters/test_async_parameters.py b/tests/e2e/catalog/product/parameters/test_async_parameters.py index edb427b1..cc2eca5c 100644 --- a/tests/e2e/catalog/product/parameters/test_async_parameters.py +++ b/tests/e2e/catalog/product/parameters/test_async_parameters.py @@ -17,12 +17,15 @@ async def async_created_parameter(async_mpt_vendor, product_id, parameter_data): def test_create_parameter(async_created_parameter): - assert async_created_parameter.name == "e2e - please delete" + result = async_created_parameter.name == "e2e - please delete" + + assert result is True async def test_create_parameter_wrong_data(async_mpt_vendor, product_id): parameter_data = {"name": "e2e - please delete - wrong data test"} service = async_mpt_vendor.catalog.products.parameters(product_id) + with pytest.raises(MPTAPIError): await service.create(parameter_data) @@ -30,24 +33,33 @@ async def test_create_parameter_wrong_data(async_mpt_vendor, product_id): async def test_update_parameter(async_mpt_vendor, product_id, async_created_parameter): service = async_mpt_vendor.catalog.products.parameters(product_id) update_data = {"name": "please delete me"} - parameter = await service.update(async_created_parameter.id, update_data) - assert parameter.name == "please delete me" + + result = await service.update(async_created_parameter.id, update_data) + + assert result.name == "please delete me" async def test_get_parameter(async_mpt_vendor, product_id, parameter_id): service = async_mpt_vendor.catalog.products.parameters(product_id) - parameter = await service.get(parameter_id) - assert parameter.id == parameter_id + + result = await service.get(parameter_id) + + assert result.id == parameter_id async def test_iterate_parameters(async_mpt_vendor, product_id, async_created_parameter): service = async_mpt_vendor.catalog.products.parameters(product_id) product_parameters = [product_param async for product_param in service.iterate()] - assert any(parameter.id == async_created_parameter.id for parameter in product_parameters) + + result = any(parameter.id == async_created_parameter.id for parameter in product_parameters) + + assert result is True async def test_delete_parameter(async_mpt_vendor, product_id, async_created_parameter): service = async_mpt_vendor.catalog.products.parameters(product_id) await service.delete(async_created_parameter.id) - parameter = await service.get(async_created_parameter.id) - assert parameter.status == "Deleted" + + result = await service.get(async_created_parameter.id) + + assert result.status == "Deleted" diff --git a/tests/e2e/catalog/product/parameters/test_sync_parameters.py b/tests/e2e/catalog/product/parameters/test_sync_parameters.py index 30702a3e..0eff9ea2 100644 --- a/tests/e2e/catalog/product/parameters/test_sync_parameters.py +++ b/tests/e2e/catalog/product/parameters/test_sync_parameters.py @@ -17,12 +17,15 @@ def created_parameter(mpt_vendor, product_id, parameter_data): def test_create_parameter(created_parameter): - assert created_parameter.name == "e2e - please delete" + result = created_parameter.name == "e2e - please delete" + + assert result is True def test_create_parameter_wrong_data(mpt_vendor, product_id): parameter_data = {"name": "e2e - please delete - wrong data test"} service = mpt_vendor.catalog.products.parameters(product_id) + with pytest.raises(MPTAPIError): service.create( parameter_data, @@ -32,25 +35,33 @@ def test_create_parameter_wrong_data(mpt_vendor, product_id): def test_update_parameter(mpt_vendor, product_id, created_parameter): service = mpt_vendor.catalog.products.parameters(product_id) update_data = {"name": "please delete me"} - parameter = service.update(created_parameter.id, update_data) - assert parameter.name == "please delete me" + + result = service.update(created_parameter.id, update_data) + + assert result.name == "please delete me" def test_get_parameter(mpt_vendor, product_id, parameter_id): service = mpt_vendor.catalog.products.parameters(product_id) - parameter = service.get(parameter_id) - assert parameter.id == parameter_id + + result = service.get(parameter_id) + + assert result.id == parameter_id def test_iterate_parameters(mpt_vendor, product_id, created_parameter): service = mpt_vendor.catalog.products.parameters(product_id) product_parameters = list(service.iterate()) - assert any(parameter.id == created_parameter.id for parameter in product_parameters) + + result = any(parameter.id == created_parameter.id for parameter in product_parameters) + + assert result is True def test_delete_parameter(mpt_vendor, product_id, created_parameter): service = mpt_vendor.catalog.products.parameters(product_id) service.delete(created_parameter.id) - parameter = service.get(created_parameter.id) - assert parameter.status == "Deleted" + result = service.get(created_parameter.id) + + assert result.status == "Deleted" diff --git a/tests/e2e/catalog/product/templates/test_async_templates.py b/tests/e2e/catalog/product/templates/test_async_templates.py index 329b88d4..48d31adc 100644 --- a/tests/e2e/catalog/product/templates/test_async_templates.py +++ b/tests/e2e/catalog/product/templates/test_async_templates.py @@ -22,26 +22,29 @@ async def async_created_template(async_template_service, template_payload): async def test_list_templates(async_template_service): - templates = [template async for template in async_template_service.iterate()] - assert isinstance(templates, list) + result = [template async for template in async_template_service.iterate()] + + assert isinstance(result, list) def test_created_template(async_created_template, template_payload): - assert async_created_template.name == template_payload["name"] + result = async_created_template.name == template_payload["name"] + + assert result is True async def test_get_template(async_template_service, template_id): - template = await async_template_service.get(template_id) + result = await async_template_service.get(template_id) - assert template.id == template_id + assert result.id == template_id async def test_update_template(async_created_template, async_template_service): update_payload = {"name": "Updated name"} - updated_template = await async_template_service.update( - async_created_template.id, update_payload - ) - assert updated_template.name == "Updated name" + + result = await async_template_service.update(async_created_template.id, update_payload) + + assert result.name == "Updated name" async def test_delete_template(async_template_service, async_created_template): @@ -52,8 +55,9 @@ async def test_delete_template(async_template_service, async_created_template): async def test_filter_templates(async_template_service, template_id): - template = await async_template_service.filter(RQLQuery(id=template_id)).fetch_one() - assert template.id == template_id + result = await async_template_service.filter(RQLQuery(id=template_id)).fetch_one() + + assert result.id == template_id async def test_not_found(async_template_service): diff --git a/tests/e2e/catalog/product/templates/test_sync_templates.py b/tests/e2e/catalog/product/templates/test_sync_templates.py index 8f7a7694..65210245 100644 --- a/tests/e2e/catalog/product/templates/test_sync_templates.py +++ b/tests/e2e/catalog/product/templates/test_sync_templates.py @@ -24,26 +24,29 @@ def created_template(template_service, template_payload): def test_list_templates(template_service, product_id): - templates = list(template_service.iterate()) - assert isinstance(templates, list) + result = list(template_service.iterate()) + + assert isinstance(result, list) def test_created_template(created_template, template_payload): - assert created_template.name == template_payload["name"] + result = created_template.name == template_payload["name"] + + assert result is True def test_get_template(template_service, template_id): - template = template_service.get(template_id) + result = template_service.get(template_id) - assert template.id == template_id + assert result.id == template_id def test_update_template(created_template, template_service): update_payload = {"name": "Updated name"} - updated_template = template_service.update(created_template.id, update_payload) + result = template_service.update(created_template.id, update_payload) - assert updated_template.name == "Updated name" + assert result.name == "Updated name" def test_delete_template(template_service, created_template, template_payload): @@ -54,9 +57,9 @@ def test_delete_template(template_service, created_template, template_payload): def test_filter_templates(template_service, template_id): - template = template_service.filter(RQLQuery(id=template_id)).fetch_one() + result = template_service.filter(RQLQuery(id=template_id)).fetch_one() - assert template.id == template_id + assert result.id == template_id def test_not_found(template_service): diff --git a/tests/e2e/catalog/product/terms/test_async_terms.py b/tests/e2e/catalog/product/terms/test_async_terms.py index 2a68edc3..07de31b3 100644 --- a/tests/e2e/catalog/product/terms/test_async_terms.py +++ b/tests/e2e/catalog/product/terms/test_async_terms.py @@ -23,45 +23,57 @@ async def async_created_term(async_vendor_terms_service, term_data): def test_create_term(async_created_term): - term = async_created_term - assert term.name == "e2e - please delete" + result = async_created_term + + assert result.name == "e2e - please delete" async def test_update_term(async_vendor_terms_service, async_created_term): service = async_vendor_terms_service update_data = {"name": "e2e - delete me (updated)"} - term = await service.update(async_created_term.id, update_data) - assert term.name == "e2e - delete me (updated)" + + result = await service.update(async_created_term.id, update_data) + + assert result.name == "e2e - delete me (updated)" async def test_get_term(async_vendor_terms_service, term_id): service = async_vendor_terms_service - term = await service.get(term_id) - assert term.id == term_id + + result = await service.get(term_id) + + assert result.id == term_id async def test_get_term_by_id(async_vendor_terms_service, term_id): service = async_vendor_terms_service - term = await service.get(term_id) - assert term.id == term_id + + result = await service.get(term_id) + + assert result.id == term_id async def test_iterate_terms(async_vendor_terms_service, async_created_term): service = async_vendor_terms_service - terms = [term async for term in service.iterate()] - assert any(term.id == async_created_term.id for term in terms) + + result = [term async for term in service.iterate()] + + assert any(term.id == async_created_term.id for term in result) async def test_filter_terms(async_vendor_terms_service, term_id): select_fields = ["-description"] filtered_terms = async_vendor_terms_service.filter(RQLQuery(id=term_id)).select(*select_fields) - terms = [term async for term in filtered_terms.iterate()] - assert len(terms) == 1 - assert terms[0].id == term_id + + result = [term async for term in filtered_terms.iterate()] + + assert len(result) == 1 + assert result[0].id == term_id async def test_delete_term(async_vendor_terms_service, async_created_term): service = async_vendor_terms_service await service.delete(async_created_term.id) + with pytest.raises(MPTAPIError): await service.get(async_created_term.id) diff --git a/tests/e2e/catalog/product/terms/test_sync_terms.py b/tests/e2e/catalog/product/terms/test_sync_terms.py index 462a579d..e7573a56 100644 --- a/tests/e2e/catalog/product/terms/test_sync_terms.py +++ b/tests/e2e/catalog/product/terms/test_sync_terms.py @@ -35,45 +35,58 @@ def created_term_from_url(logger, vendor_terms_service, term_data, pdf_url): def test_create_term(created_term): - term = created_term - assert term.name == "e2e - please delete" + result = created_term + + assert result.name == "e2e - please delete" def test_update_term(vendor_terms_service, created_term): service = vendor_terms_service update_data = {"name": "e2e - delete me (updated)"} - term = service.update(created_term.id, update_data) - assert term.name == "e2e - delete me (updated)" + + result = service.update(created_term.id, update_data) + + assert result.name == "e2e - delete me (updated)" def test_get_term(vendor_terms_service, term_id): service = vendor_terms_service - term = service.get(term_id) - assert term.id == term_id + + result = service.get(term_id) + + assert result.id == term_id def test_get_term_by_id(vendor_terms_service, term_id): service = vendor_terms_service - term = service.get(term_id) - assert term.id == term_id + + result = service.get(term_id) + + assert result.id == term_id def test_iterate_terms(vendor_terms_service, created_term): service = vendor_terms_service - terms = list(service.iterate()) - assert any(term.id == created_term.id for term in terms) + + result = list(service.iterate()) + + assert any(term.id == created_term.id for term in result) def test_filter_terms(vendor_terms_service, term_id): select_fields = ["-description"] filtered_terms = vendor_terms_service.filter(RQLQuery(id=term_id)).select(*select_fields) - terms = list(filtered_terms.iterate()) - assert len(terms) == 1 - assert terms[0].id == term_id + + result = list(filtered_terms.iterate()) + + assert len(result) == 1 + assert result[0].id == term_id def test_delete_term(vendor_terms_service, created_term): service = vendor_terms_service - service.delete(created_term.id) + + service.delete(created_term.id) # act + with pytest.raises(MPTAPIError): service.get(created_term.id) diff --git a/tests/e2e/catalog/product/terms/variants/test_async_variants.py b/tests/e2e/catalog/product/terms/variants/test_async_variants.py index 2d807f74..389c048d 100644 --- a/tests/e2e/catalog/product/terms/variants/test_async_variants.py +++ b/tests/e2e/catalog/product/terms/variants/test_async_variants.py @@ -42,12 +42,15 @@ async def created_variant_from_url( def test_create_variant(async_created_variant): - variant = async_created_variant - assert variant.name == "e2e - please delete" + result = async_created_variant + + assert result.name == "e2e - please delete" def test_create_variant_from_url(created_variant_from_url, variant_data): - assert created_variant_from_url.name == variant_data["name"] + result = created_variant_from_url.name == variant_data["name"] + + assert result is True async def test_update_variant( @@ -55,32 +58,40 @@ async def test_update_variant( ): service = async_vendor_variant_service update_data = {"name": "e2e - delete me (updated)"} - variant = await service.update(async_created_variant.id, update_data) - assert variant.name == "e2e - delete me (updated)" + + result = await service.update(async_created_variant.id, update_data) + + assert result.name == "e2e - delete me (updated)" async def test_get_variant( async_mpt_vendor, product_id, term_id, variant_id, async_vendor_variant_service ): service = async_vendor_variant_service - variant = await service.get(variant_id) - assert variant.id == variant_id + + result = await service.get(variant_id) + + assert result.id == variant_id async def test_get_variant_by_id( async_mpt_vendor, product_id, term_id, variant_id, async_vendor_variant_service ): service = async_vendor_variant_service - variant = await service.get(variant_id) - assert variant.id == variant_id + + result = await service.get(variant_id) + + assert result.id == variant_id async def test_iterate_variants( async_mpt_vendor, product_id, term_id, async_created_variant, async_vendor_variant_service ): service = async_vendor_variant_service - variants = [variant async for variant in service.iterate()] - assert any(variant.id == async_created_variant.id for variant in variants) + + result = [variant async for variant in service.iterate()] + + assert any(variant.id == async_created_variant.id for variant in result) async def test_filter_variants( @@ -90,9 +101,11 @@ async def test_filter_variants( filtered_variants = async_vendor_variant_service.filter(RQLQuery(id=variant_id)).select( *select_fields ) - variants = [variant async for variant in filtered_variants.iterate()] - assert len(variants) == 1 - assert variants[0].id == variant_id + + result = [variant async for variant in filtered_variants.iterate()] + + assert len(result) == 1 + assert result[0].id == variant_id async def test_delete_variant( @@ -100,5 +113,6 @@ async def test_delete_variant( ): service = async_vendor_variant_service await service.delete(async_created_variant.id) + with pytest.raises(MPTAPIError): await service.get(async_created_variant.id) diff --git a/tests/e2e/catalog/product/terms/variants/test_sync_variants.py b/tests/e2e/catalog/product/terms/variants/test_sync_variants.py index 4833125a..7fec0dee 100644 --- a/tests/e2e/catalog/product/terms/variants/test_sync_variants.py +++ b/tests/e2e/catalog/product/terms/variants/test_sync_variants.py @@ -34,32 +34,41 @@ def created_variant_from_url(logger, vendor_variant_service, variant_data, pdf_u def test_create_variant(created_variant, variant_data): - assert created_variant.name == variant_data["name"] + result = created_variant.name == variant_data["name"] + + assert result is True def test_create_variant_from_url(created_variant_from_url, variant_data): - assert created_variant_from_url.name == variant_data["name"] + result = created_variant_from_url.name == variant_data["name"] + + assert result is True def test_update_variant(vendor_variant_service, created_variant): update_data = {"name": "e2e - delete me (updated)"} - variant = vendor_variant_service.update(created_variant.id, update_data) - assert variant.name == "e2e - delete me (updated)" + + result = vendor_variant_service.update(created_variant.id, update_data) + + assert result.name == "e2e - delete me (updated)" def test_get_variant(vendor_variant_service, variant_id): - variant = vendor_variant_service.get(variant_id) - assert variant.id == variant_id + result = vendor_variant_service.get(variant_id) + + assert result.id == variant_id def test_get_variant_by_id(vendor_variant_service, variant_id): - variant = vendor_variant_service.get(variant_id) - assert variant.id == variant_id + result = vendor_variant_service.get(variant_id) + + assert result.id == variant_id def test_iterate_variants(vendor_variant_service, created_variant): - variants = list(vendor_variant_service.iterate()) - assert any(variant.id == created_variant.id for variant in variants) + result = list(vendor_variant_service.iterate()) + + assert any(variant.id == created_variant.id for variant in result) def test_filter_variants(vendor_variant_service, variant_id): @@ -67,12 +76,15 @@ def test_filter_variants(vendor_variant_service, variant_id): filtered_variants = vendor_variant_service.filter(RQLQuery(id=variant_id)).select( *select_fields ) - variants = list(filtered_variants.iterate()) - assert len(variants) == 1 - assert variants[0].id == variant_id + + result = list(filtered_variants.iterate()) + + assert len(result) == 1 + assert result[0].id == variant_id def test_delete_variant(vendor_variant_service, created_variant): vendor_variant_service.delete(created_variant.id) + with pytest.raises(MPTAPIError): vendor_variant_service.get(created_variant.id) diff --git a/tests/e2e/catalog/product/test_async_product.py b/tests/e2e/catalog/product/test_async_product.py index 9909910c..5abab202 100644 --- a/tests/e2e/catalog/product/test_async_product.py +++ b/tests/e2e/catalog/product/test_async_product.py @@ -18,20 +18,22 @@ async def async_created_product(logger, async_mpt_vendor, product_data, logo_fd) @pytest.mark.flaky def test_create_product(async_created_product, product_data): - assert async_created_product.name == product_data["name"] + result = async_created_product.name == product_data["name"] + + assert result is True @pytest.mark.flaky async def test_update_product(async_mpt_vendor, async_created_product, logo_fd): update_data = {"name": "Updated Product"} - product = await async_mpt_vendor.catalog.products.update( + result = await async_mpt_vendor.catalog.products.update( async_created_product.id, update_data, icon=logo_fd, ) - assert product.name == update_data["name"] + assert result.name == update_data["name"] @pytest.mark.skip(reason="Leaves test products in the catalog") @@ -42,13 +44,13 @@ async def test_product_review_and_publish(async_mpt_vendor, async_mpt_ops, async @pytest.mark.flaky -async def test_get_product(async_mpt_vendor, product_id, logger): - await async_mpt_vendor.catalog.products.get(product_id) +async def test_get_product(async_mpt_vendor, product_id): + await async_mpt_vendor.catalog.products.get(product_id) # act @pytest.mark.flaky async def test_product_save_settings(async_mpt_vendor, async_created_product): - await async_mpt_vendor.catalog.products.update_settings( + await async_mpt_vendor.catalog.products.update_settings( # act async_created_product.id, {"itemSelection": True} ) @@ -56,12 +58,12 @@ async def test_product_save_settings(async_mpt_vendor, async_created_product): @pytest.mark.flaky async def test_filter_and_select_products(async_mpt_vendor, product_id): select_fields = ["-icon", "-revision", "-settings", "-vendor", "-statistics", "-website"] - filtered_products = ( async_mpt_vendor.catalog.products.filter(RQLQuery(id=product_id)) .filter(RQLQuery(name="E2E Seeded")) .select(*select_fields) ) - products = [product async for product in filtered_products.iterate()] - assert len(products) == 1 + result = [product async for product in filtered_products.iterate()] + + assert len(result) == 1 diff --git a/tests/e2e/catalog/product/test_sync_product.py b/tests/e2e/catalog/product/test_sync_product.py index dd5f166e..da9de00a 100644 --- a/tests/e2e/catalog/product/test_sync_product.py +++ b/tests/e2e/catalog/product/test_sync_product.py @@ -18,19 +18,21 @@ def created_product(logger, mpt_vendor, product_data, logo_fd): @pytest.mark.flaky def test_create_product(created_product, product_data): - assert created_product.name == product_data["name"] + result = created_product.name == product_data["name"] + + assert result is True @pytest.mark.flaky def test_update_product(mpt_vendor, created_product, logo_fd): update_data = {"name": "Updated Product"} - product = mpt_vendor.catalog.products.update(created_product.id, update_data, icon=logo_fd) + result = mpt_vendor.catalog.products.update(created_product.id, update_data, icon=logo_fd) - assert product.name == update_data["name"] + assert result.name == update_data["name"] -@pytest.mark.skip(reason="Leaves test products in the catalog") +@pytest.mark.skip(reason="Leaves test products in the catalog") # noqa: AAA01 @pytest.mark.flaky def test_product_review_and_publish(mpt_vendor, mpt_ops, created_product): mpt_vendor.catalog.products.review(created_product.id) @@ -39,23 +41,23 @@ def test_product_review_and_publish(mpt_vendor, mpt_ops, created_product): @pytest.mark.flaky def test_get_product(mpt_vendor, product_id): - mpt_vendor.catalog.products.get(product_id) + mpt_vendor.catalog.products.get(product_id) # act @pytest.mark.flaky def test_product_save_settings(mpt_vendor, created_product): - mpt_vendor.catalog.products.update_settings(created_product.id, {"itemSelection": True}) + mpt_vendor.catalog.products.update_settings(created_product.id, {"itemSelection": True}) # act @pytest.mark.flaky def test_filter_and_select_products(mpt_vendor, product_id): select_fields = ["-icon", "-revision", "-settings", "-vendor", "-statistics", "-website"] - filtered_products = ( mpt_vendor.catalog.products.filter(RQLQuery(id=product_id)) .filter(RQLQuery(name="E2E Seeded")) .select(*select_fields) ) - products = list(filtered_products.iterate()) - assert len(products) == 1 + result = list(filtered_products.iterate()) + + assert len(result) == 1 diff --git a/tests/e2e/test_access.py b/tests/e2e/test_access.py index cf032e4e..3f295ca9 100644 --- a/tests/e2e/test_access.py +++ b/tests/e2e/test_access.py @@ -14,5 +14,6 @@ def test_unauthorised(base_url): @pytest.mark.flaky def test_access(mpt_vendor, product_id): - product = mpt_vendor.catalog.products.get(product_id) - assert product.id == product_id + result = mpt_vendor.catalog.products.get(product_id) + + assert result.id == product_id diff --git a/tests/seed/catalog/test_catalog.py b/tests/seed/catalog/test_catalog.py index 9f3514bb..4cce3e8c 100644 --- a/tests/seed/catalog/test_catalog.py +++ b/tests/seed/catalog/test_catalog.py @@ -10,7 +10,7 @@ async def test_seed_catalog_stage1() -> None: "seed.catalog.catalog.seed_parameter_group", new_callable=AsyncMock ) as mock_param_group, ): - await seed_groups_and_group_params() + await seed_groups_and_group_params() # act mock_item_group.assert_called_once() mock_param_group.assert_called_once() @@ -21,7 +21,7 @@ async def test_seed_catalog_stage2() -> None: patch("seed.catalog.catalog.seed_items", new_callable=AsyncMock) as mock_items, patch("seed.catalog.catalog.seed_parameters", new_callable=AsyncMock) as mock_params, ): - await seed_items_and_params() + await seed_items_and_params() # act mock_items.assert_called_once() mock_params.assert_called_once() @@ -37,7 +37,7 @@ async def test_seed_catalog() -> None: "seed.catalog.catalog.seed_groups_and_group_params", new_callable=AsyncMock ) as seed_groups_and_group_params, ): - await seed_catalog() + await seed_catalog() # act mock_product.assert_called_once() seed_items_and_params.assert_called_once() diff --git a/tests/seed/catalog/test_item.py b/tests/seed/catalog/test_item.py index 2bfdb094..eecdbdf6 100644 --- a/tests/seed/catalog/test_item.py +++ b/tests/seed/catalog/test_item.py @@ -29,24 +29,25 @@ async def test_get_item(context: Context, vendor_client, resource_item) -> None: service.get.return_value = resource_item vendor_client.catalog.items = service - fetched_item = await get_item(context=context, mpt_vendor=vendor_client) + result = await get_item(context=context, mpt_vendor=vendor_client) - assert fetched_item == resource_item + assert result == resource_item assert context.get(f"catalog.item[{resource_item.id}]") == resource_item async def test_get_item_without_id(context: Context) -> None: - missing_item = await get_item(context=context) - assert missing_item is None + result = await get_item(context=context) + + assert result is None async def test_create_item(context: Context, vendor_client, resource_item, items_service) -> None: # noqa: WPS110 items_service.create.return_value = resource_item vendor_client.catalog.items = items_service - created = await create_item(context=context, mpt_vendor=vendor_client) + result = await create_item(context=context, mpt_vendor=vendor_client) - assert created == resource_item + assert result == resource_item assert context.get("catalog.item.id") == resource_item.id assert context.get(f"catalog.item[{resource_item.id}]") == resource_item @@ -60,9 +61,9 @@ async def test_review_item_draft_status( context.set_resource("catalog.item", resource_item) context["catalog.item.id"] = resource_item.id - reviewed_item = await review_item(context=context, mpt_vendor=vendor_client) + result = await review_item(context=context, mpt_vendor=vendor_client) - assert reviewed_item == resource_item + assert result == resource_item items_service.review.assert_called_once() @@ -70,13 +71,13 @@ async def test_review_item_non_draft_status( context: Context, vendor_client, resource_item, items_service ) -> None: # noqa: WPS110 resource_item.status = "Published" - items_service.review.return_value = resource_item vendor_client.catalog.items = items_service context.set_resource("catalog.item", resource_item) context["catalog.item.id"] = resource_item.id - await review_item(context=context, mpt_vendor=vendor_client) + await review_item(context=context, mpt_vendor=vendor_client) # act + items_service.review.assert_not_called() @@ -89,9 +90,9 @@ async def test_publish_item_reviewing_status( context.set_resource("catalog.item", resource_item) context["catalog.item.id"] = resource_item.id - published_item = await publish_item(context=context, mpt_operations=operations_client) + result = await publish_item(context=context, mpt_operations=operations_client) - assert published_item == resource_item + assert result == resource_item operations_client.catalog.items.publish.assert_called_once() @@ -104,7 +105,7 @@ async def test_publish_item_non_reviewing_status( context.set_resource("catalog.item", resource_item) context["catalog.item.id"] = resource_item.id - await publish_item(context=context, mpt_operations=operations_client) + await publish_item(context=context, mpt_operations=operations_client) # act operations_client.catalog.items.publish.assert_not_called() @@ -118,7 +119,7 @@ async def test_seed_items(context: Context) -> None: patch("seed.catalog.item.review_item", new_callable=AsyncMock) as mock_review, patch("seed.catalog.item.publish_item", new_callable=AsyncMock) as mock_publish, ): - await seed_items(context=context) + await seed_items(context=context) # act mock_refresh.assert_called_once() mock_create.assert_called_once() diff --git a/tests/seed/catalog/test_item_group.py b/tests/seed/catalog/test_item_group.py index 63f7a791..c043ce7c 100644 --- a/tests/seed/catalog/test_item_group.py +++ b/tests/seed/catalog/test_item_group.py @@ -43,23 +43,23 @@ async def test_get_item_group(context, vendor_client, item_group, mock_set_item_ vendor_client.catalog.products.item_groups.return_value = service mock_set_item_group.return_value = item_group - fetched_group = await get_item_group(context=context, mpt_vendor=vendor_client) + result = await get_item_group(context=context, mpt_vendor=vendor_client) - assert fetched_group == item_group + assert result == item_group service.get.assert_called_once_with(context["catalog.item_group.id"]) service.create.assert_not_called() async def test_get_item_group_without_id(context) -> None: - no_group = await get_item_group(context=context) + result = await get_item_group(context=context) - assert no_group is None + assert result is None def test_set_item_group(context, item_group) -> None: - stored_group = set_item_group(item_group, context=context) + result = set_item_group(item_group, context=context) - assert stored_group == item_group + assert result == item_group assert context.get("catalog.item_group.id") == "group-123" assert context.get("catalog.item_group[group-123]") == item_group @@ -67,9 +67,9 @@ def test_set_item_group(context, item_group) -> None: def test_build_item_group(context) -> None: context["catalog.product.id"] = "product-123" - item_group_payload = build_item_group(context=context) + result = build_item_group(context=context) - assert item_group_payload["product"]["id"] == "product-123" + assert result["product"]["id"] == "product-123" async def test_get_or_create_item_group_create_new( @@ -84,15 +84,15 @@ async def test_get_or_create_item_group_create_new( patch("seed.catalog.item_group.build_item_group", return_value=item_group), patch("seed.catalog.item_group.set_item_group", return_value=item_group) as set_item_group, ): - created_group = await init_item_group(context=context, mpt_vendor=vendor_client) + result = await init_item_group(context=context, mpt_vendor=vendor_client) - assert created_group == item_group + assert result == item_group set_item_group.assert_called_once_with(item_group) item_group_service.create.assert_called_once() async def test_seed_item_group() -> None: with patch("seed.catalog.item_group.init_item_group", new_callable=AsyncMock) as mock_create: - await seed_item_group() + await seed_item_group() # act mock_create.assert_called_once() diff --git a/tests/seed/catalog/test_product.py b/tests/seed/catalog/test_product.py index f22d057e..be4b7f05 100644 --- a/tests/seed/catalog/test_product.py +++ b/tests/seed/catalog/test_product.py @@ -29,15 +29,16 @@ async def test_get_product(context: Context, vendor_client, product, products_se products_service.get.return_value = product vendor_client.catalog.products = products_service - fetched_product = await get_product(context=context, mpt_vendor=vendor_client) + result = await get_product(context=context, mpt_vendor=vendor_client) - assert fetched_product == product + assert result == product assert context.get_resource("catalog.product", product.id) == product async def test_get_product_without_id(context: Context) -> None: - product = await get_product(context=context) - assert product is None + result = await get_product(context=context) + + assert result is None async def test_get_or_create_product_create_new( @@ -52,8 +53,9 @@ async def test_get_or_create_product_create_new( patch("seed.catalog.product.icon", new=MagicMock()), patch("pathlib.Path.open", return_value=fake_icon_bytes), ): - created = await init_product(context, mpt_vendor=vendor_client) - assert created == product + result = await init_product(context, mpt_vendor=vendor_client) + + assert result == product products_service.create.assert_called_once() @@ -66,16 +68,18 @@ async def test_review_product_draft_status( with ( patch("seed.catalog.product.get_product", return_value=product), ): - reviewed = await review_product(context, mpt_vendor=vendor_client) - assert reviewed == product + result = await review_product(context, mpt_vendor=vendor_client) + + assert result == product products_service.review.assert_called_once() async def test_review_product_non_draft_status(product) -> None: product.status = "Published" with patch("seed.catalog.product.get_product", return_value=product): - unchanged = await review_product() - assert unchanged == product + result = await review_product() + + assert result == product async def test_publish_product_reviewing_status(context, operations_client, product) -> None: @@ -84,16 +88,18 @@ async def test_publish_product_reviewing_status(context, operations_client, prod with ( patch("seed.catalog.product.get_product", return_value=product), ): - published = await publish_product(context, mpt_operations=operations_client) - assert published == product + result = await publish_product(context, mpt_operations=operations_client) + + assert result == product operations_client.catalog.products.publish.assert_called_once() async def test_publish_product_non_reviewing_status(product) -> None: product.status = "Draft" with patch("seed.catalog.product.get_product", return_value=product): - unchanged = await publish_product() - assert unchanged == product + result = await publish_product() + + assert result == product async def test_seed_product_sequence() -> None: @@ -102,7 +108,8 @@ async def test_seed_product_sequence() -> None: patch("seed.catalog.product.review_product", new_callable=AsyncMock) as mock_review, patch("seed.catalog.product.publish_product", new_callable=AsyncMock) as mock_publish, ): - await seed_product() + await seed_product() # act + mock_create.assert_called_once() mock_review.assert_called_once() mock_publish.assert_called_once() diff --git a/tests/seed/catalog/test_product_parameters.py b/tests/seed/catalog/test_product_parameters.py index 50737ded..d603db3c 100644 --- a/tests/seed/catalog/test_product_parameters.py +++ b/tests/seed/catalog/test_product_parameters.py @@ -1,4 +1,3 @@ -from typing import Any from unittest.mock import AsyncMock, MagicMock, patch import pytest @@ -41,25 +40,25 @@ async def test_get_parameter( service.get.return_value = parameter vendor_client.catalog.products.parameters.return_value = service - fetched_parameter = await get_parameter(context=context, mpt_vendor=vendor_client) + result = await get_parameter(context=context, mpt_vendor=vendor_client) - assert fetched_parameter == parameter + assert result == parameter assert context.get(f"{namespace}.id") == parameter.id assert context.get(f"{namespace}[{parameter.id}]") == parameter async def test_get_parameter_without_id(context: Context) -> None: - maybe_parameter = await get_parameter(context=context) + result = await get_parameter(context=context) - assert maybe_parameter is None + assert result is None def test_build_parameter(context: Context) -> None: context["catalog.product.parameter_group.id"] = "group-123" - parameter_payload: dict[str, Any] = build_parameter(context=context) + result = build_parameter(context=context) - assert parameter_payload["group"]["id"] == "group-123" + assert result["group"]["id"] == "group-123" async def test_get_or_create_parameter_create_new( @@ -73,9 +72,9 @@ async def test_get_or_create_parameter_create_new( patch("seed.catalog.product_parameters.get_parameter", return_value=None), patch("seed.catalog.product_parameters.build_parameter", return_value=parameter), ): - created_parameter = await init_parameter(context=context, mpt_vendor=vendor_client) + result = await init_parameter(context=context, mpt_vendor=vendor_client) - assert created_parameter == parameter + assert result == parameter assert context.get(f"{namespace}.id") == parameter.id assert context.get(f"{namespace}[{parameter.id}]") == parameter @@ -98,9 +97,9 @@ async def test_create_parameter_success( service.create.return_value = parameter vendor_client.catalog.products.parameters.return_value = service - created = await create_parameter(context=context, mpt_vendor=vendor_client) + result = await create_parameter(context=context, mpt_vendor=vendor_client) - assert created == parameter + assert result == parameter assert context.get("catalog.product.parameter.id") == parameter.id assert context.get(f"catalog.product.parameter[{parameter.id}]") == parameter diff --git a/tests/seed/catalog/test_product_parameters_group.py b/tests/seed/catalog/test_product_parameters_group.py index d6ff6b66..d3dd5cc7 100644 --- a/tests/seed/catalog/test_product_parameters_group.py +++ b/tests/seed/catalog/test_product_parameters_group.py @@ -34,22 +34,25 @@ async def test_get_parameter_group( parameter_groups_service.get.return_value = parameter_group vendor_client.catalog.products.parameter_groups.return_value = parameter_groups_service - fetched_parameter_group = await get_parameter_group(context=context, mpt_vendor=vendor_client) + result = await get_parameter_group(context=context, mpt_vendor=vendor_client) - assert fetched_parameter_group == parameter_group + assert result == parameter_group assert context.get("catalog.product.parameter_group.id") == parameter_group.id assert context.get(f"catalog.product.parameter_group[{parameter_group.id}]") == parameter_group async def test_get_parameter_group_without_id(context: Context) -> None: - maybe_parameter_group = await get_parameter_group(context=context) + result = await get_parameter_group(context=context) - assert maybe_parameter_group is None + assert result is None def test_build_parameter_group(context: Context) -> None: parameter_group_payload = build_parameter_group(context=context) - assert isinstance(parameter_group_payload, dict) + + result = isinstance(parameter_group_payload, dict) + + assert result is True async def test_get_or_create_parameter_group_create_new( diff --git a/tests/unit/http/test_async_client.py b/tests/unit/http/test_async_client.py index 995a7b6d..9ecb143b 100644 --- a/tests/unit/http/test_async_client.py +++ b/tests/unit/http/test_async_client.py @@ -23,7 +23,7 @@ def mock_response(mock_request): def test_async_http_initialization(mocker): mock_async_client = mocker.patch("mpt_api_client.http.async_client.AsyncClient") - AsyncHTTPClient(base_url=API_URL, api_token=API_TOKEN) + AsyncHTTPClient(base_url=API_URL, api_token=API_TOKEN) # act mock_async_client.assert_called_once_with( base_url=API_URL, @@ -43,7 +43,7 @@ def test_async_env_initialization(monkeypatch, mocker): monkeypatch.setenv("MPT_URL", API_URL) mock_async_client = mocker.patch("mpt_api_client.http.async_client.AsyncClient") - AsyncHTTPClient() + AsyncHTTPClient() # act mock_async_client.assert_called_once_with( base_url=API_URL, @@ -72,10 +72,10 @@ def test_async_http_without_url(): async def test_async_http_call_success(async_http_client, mock_response): success_route = respx.get(f"{API_URL}/").mock(return_value=mock_response) - success_response = await async_http_client.request("GET", "/") + result = await async_http_client.request("GET", "/") - assert success_response.status_code == codes.OK - assert json.loads(success_response.content) == {"message": "Hello, World!"} + assert result.status_code == codes.OK + assert json.loads(result.content) == {"message": "Hello, World!"} assert success_route.called @@ -92,18 +92,17 @@ async def test_async_http_call_failure(async_http_client): async def test_http_call_with_json_and_files(mocker, async_http_client, mock_httpx_response): # noqa: WPS210 json_data = {"foo": "bar"} files = {"file": ("test.txt", io.StringIO("file content"), "text/plain")} - parent_request = mocker.patch.object( async_http_client.httpx_client, "request", autospec=True, return_value=mock_httpx_response ) - await async_http_client.request("POST", "/upload", files=files, json=json_data) + + await async_http_client.request("POST", "/upload", files=files, json=json_data) # act called_kwargs = parent_request.call_args[1] assert called_kwargs["json"] is None sent_files = called_kwargs["files"] assert "file" in sent_files assert "_attachment_data" in sent_files - payload_tuple = sent_files["_attachment_data"] assert payload_tuple[2] == "application/json" assert payload_tuple[1].decode() == '{"foo":"bar"}' @@ -111,19 +110,16 @@ async def test_http_call_with_json_and_files(mocker, async_http_client, mock_htt async def test_http_call_force_multipart(mocker, async_http_client, mock_httpx_response): # noqa: WPS210 json_data = {"foo": "bar"} - parent_request = mocker.patch.object( async_http_client.httpx_client, "request", autospec=True, return_value=mock_httpx_response ) - await async_http_client.request("POST", "/upload", json=json_data, force_multipart=True) + await async_http_client.request("POST", "/upload", json=json_data, force_multipart=True) # act called_kwargs = parent_request.call_args[1] sent_files = called_kwargs["files"] - assert called_kwargs["json"] is None assert "_attachment_data" in sent_files - payload_tuple = sent_files["_attachment_data"] assert payload_tuple[2] == "application/json" assert payload_tuple[1].decode() == '{"foo":"bar"}' diff --git a/tests/unit/http/test_base_service.py b/tests/unit/http/test_base_service.py index a4b1afec..6d878d57 100644 --- a/tests/unit/http/test_base_service.py +++ b/tests/unit/http/test_base_service.py @@ -12,31 +12,34 @@ class ParametrisedDummyService( # noqa: WPS215 def test_endpoint(http_client): - service = ParametrisedDummyService( + result = ParametrisedDummyService( http_client=http_client, endpoint_params={"version": "vLatest", "tenant": "T-123"} ) - assert service.endpoint_params == {"version": "vLatest", "tenant": "T-123"} - assert service.path == "/api/vLatest/test/T-123" + assert result.endpoint_params == {"version": "vLatest", "tenant": "T-123"} + assert result.path == "/api/vLatest/test/T-123" def test_endpoint_with_multiple_params(http_client): - service = ParametrisedDummyService( + result = ParametrisedDummyService( http_client=http_client, endpoint_params={"version": "v2", "tenant": "test-tenant"} ) - assert service.path == "/api/v2/test/test-tenant" + assert result.path == "/api/v2/test/test-tenant" def test_build_url_no_query_params(dummy_service): - url = dummy_service.build_path() - assert url == "/api/v1/test" + result = dummy_service.build_path() + + assert result == "/api/v1/test" def test_build_url_with_query_params(dummy_service): query_params = {"limit": "10", "offset": "20"} - url = dummy_service.build_path(query_params) - assert url == "/api/v1/test?limit=10&offset=20" + + result = dummy_service.build_path(query_params) + + assert result == "/api/v1/test?limit=10&offset=20" def test_build_url_with_query_state(http_client, filter_status_active): @@ -47,8 +50,9 @@ def test_build_url_with_query_state(http_client, filter_status_active): ), ) - url = service_with_state.build_path() - assert url == "/api/v1/test?order=created,-name&select=id,name&eq(status,active)" + result = service_with_state.build_path() + + assert result == "/api/v1/test?order=created,-name&select=id,name&eq(status,active)" def test_build_url_with_query_state_and_params(http_client, filter_status_active): @@ -57,10 +61,11 @@ def test_build_url_with_query_state_and_params(http_client, filter_status_active query_state=QueryState(rql=filter_status_active), endpoint_params={"version": "v2", "tenant": "T-123"}, ) - query_params = {"limit": "5"} - url = service_with_state.build_path(query_params) - assert url == "/api/v2/test/T-123?limit=5&eq(status,active)" + + result = service_with_state.build_path(query_params) + + assert result == "/api/v2/test/T-123?limit=5&eq(status,active)" def test_build_url_with_chained_methods(dummy_service, filter_status_active): @@ -70,8 +75,9 @@ def test_build_url_with_chained_methods(dummy_service, filter_status_active): .select("id", "name", "-audit") ) - url = chained_service.build_path({"limit": "10"}) + result = chained_service.build_path({"limit": "10"}) + expected_url = ( "/api/v1/test?limit=10&order=-created,name&select=id,name,-audit&eq(status,active)" ) - assert url == expected_url + assert result == expected_url diff --git a/tests/unit/http/test_client.py b/tests/unit/http/test_client.py index a2e54d4c..041ab6d0 100644 --- a/tests/unit/http/test_client.py +++ b/tests/unit/http/test_client.py @@ -13,7 +13,7 @@ def test_http_initialization(mocker): mock_client = mocker.patch("mpt_api_client.http.client.Client") - HTTPClient(base_url=API_URL, api_token=API_TOKEN) + HTTPClient(base_url=API_URL, api_token=API_TOKEN) # act mock_client.assert_called_once_with( base_url=API_URL, @@ -32,7 +32,7 @@ def test_env_initialization(monkeypatch, mocker): monkeypatch.setenv("MPT_URL", API_URL) mock_client = mocker.patch("mpt_api_client.http.client.Client") - HTTPClient() + HTTPClient() # act mock_client.assert_called_once_with( base_url=API_URL, @@ -62,10 +62,10 @@ def test_http_call_success(http_client): return_value=Response(200, json={"message": "Hello, World!"}) ) - success_response = http_client.request("GET", "/") + result = http_client.request("GET", "/") - assert success_response.status_code == codes.OK - assert json.loads(success_response.content) == {"message": "Hello, World!"} + assert result.status_code == codes.OK + assert json.loads(result.content) == {"message": "Hello, World!"} assert success_route.called @@ -85,14 +85,13 @@ def test_http_call_with_json_and_files(mocker, http_client, mock_httpx_response) http_client.httpx_client, "request", autospec=True, return_value=mock_httpx_response ) - http_client.request("POST", "/upload", files=files, json={"foo": "bar"}) + http_client.request("POST", "/upload", files=files, json={"foo": "bar"}) # act called_kwargs = parent_request.call_args[1] assert called_kwargs["json"] is None sent_files = called_kwargs["files"] assert "file" in sent_files assert "_attachment_data" in sent_files - payload_tuple = sent_files["_attachment_data"] assert payload_tuple[2] == "application/json" assert payload_tuple[1].decode() == '{"foo":"bar"}' @@ -102,14 +101,12 @@ def test_http_call_force_multipart(mocker, http_client): json_data = {"foo": "bar"} parent_request = mocker.patch.object(http_client.httpx_client, "request", autospec=True) - http_client.request("POST", "/upload", json=json_data, force_multipart=True) + http_client.request("POST", "/upload", json=json_data, force_multipart=True) # act called_kwargs = parent_request.call_args[1] sent_files = called_kwargs["files"] - assert called_kwargs["json"] is None assert "_attachment_data" in sent_files - payload_tuple = sent_files["_attachment_data"] assert payload_tuple[2] == "application/json" assert payload_tuple[1].decode() == '{"foo":"bar"}' diff --git a/tests/unit/http/test_mixins.py b/tests/unit/http/test_mixins.py index f82ca114..a2427d41 100644 --- a/tests/unit/http/test_mixins.py +++ b/tests/unit/http/test_mixins.py @@ -132,15 +132,14 @@ async def test_async_create_mixin(async_dummy_service): # noqa: WPS210 resource_data = {"name": "Test Resource", "status": "active"} new_resource_data = {"id": "new-resource-id", "name": "Test Resource", "status": "active"} create_response = httpx.Response(httpx.codes.OK, json=new_resource_data) - with respx.mock: mock_route = respx.post("https://api.example.com/api/v1/test").mock( return_value=create_response ) - created_resource = await async_dummy_service.create(resource_data) + result = await async_dummy_service.create(resource_data) - assert created_resource.to_dict() == new_resource_data + assert result.to_dict() == new_resource_data assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.method == "POST" @@ -150,13 +149,12 @@ async def test_async_create_mixin(async_dummy_service): # noqa: WPS210 async def test_async_delete_mixin(async_dummy_service): # noqa: WPS210 delete_response = httpx.Response(httpx.codes.NO_CONTENT, json=None) - with respx.mock: mock_route = respx.delete("https://api.example.com/api/v1/test/RES-123").mock( return_value=delete_response ) - await async_dummy_service.delete("RES-123") + await async_dummy_service.delete("RES-123") # act assert mock_route.call_count == 1 @@ -164,15 +162,14 @@ async def test_async_delete_mixin(async_dummy_service): # noqa: WPS210 async def test_async_update_resource(async_dummy_service): # noqa: WPS210 resource_data = {"name": "Test Resource", "status": "active"} update_response = httpx.Response(httpx.codes.OK, json=resource_data) - with respx.mock: mock_route = respx.put("https://api.example.com/api/v1/test/RES-123").mock( return_value=update_response ) - await async_dummy_service.update("RES-123", resource_data) + await async_dummy_service.update("RES-123", resource_data) # act - request: httpx.Request = mock_route.calls[0].request + request = mock_route.calls[0].request assert mock_route.call_count == 1 assert json.loads(request.content.decode()) == resource_data @@ -181,15 +178,14 @@ def test_sync_create_mixin(dummy_service): # noqa: WPS210 resource_data = {"name": "Test Resource", "status": "active"} new_resource_data = {"id": "new-resource-id", "name": "Test Resource", "status": "active"} create_response = httpx.Response(httpx.codes.OK, json=new_resource_data) - with respx.mock: mock_route = respx.post("https://api.example.com/api/v1/test").mock( return_value=create_response ) - created_resource = dummy_service.create(resource_data) + result = dummy_service.create(resource_data) - assert created_resource.to_dict() == new_resource_data + assert result.to_dict() == new_resource_data assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.method == "POST" @@ -204,7 +200,7 @@ def test_sync_delete_mixin(dummy_service): return_value=delete_response ) - dummy_service.delete("RES-123") + dummy_service.delete("RES-123") # act assert mock_route.call_count == 1 @@ -217,7 +213,7 @@ def test_sync_update_resource(dummy_service): return_value=update_response ) - dummy_service.update("RES-123", resource_data) + dummy_service.update("RES-123", resource_data) # act request = mock_route.calls[0].request assert mock_route.call_count == 1 @@ -236,10 +232,10 @@ async def test_async_file_create_with_data(async_media_service): ) ) media_image = ("test.jpg", io.BytesIO(b"Image content"), "image/jpeg") - new_media = await async_media_service.create({"name": "Product image"}, file=media_image) - request: httpx.Request = mock_route.calls[0].request + result = await async_media_service.create({"name": "Product image"}, file=media_image) + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="media"\r\n' b"Content-Type: application/json\r\n\r\n" @@ -251,7 +247,7 @@ async def test_async_file_create_with_data(async_media_service): b"Image content\r\n" in request.content ) assert "multipart/form-data" in request.headers["Content-Type"] - assert new_media.to_dict() == media_data + assert result.to_dict() == media_data async def test_async_file_create_no_data(async_media_service): @@ -269,7 +265,7 @@ async def test_async_file_create_no_data(async_media_service): {}, file=("test.jpg", io.BytesIO(b"Image content"), "image/jpeg") ) - request: httpx.Request = mock_route.calls[0].request + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="file"; filename="test.jpg"\r\n' @@ -309,22 +305,20 @@ async def test_async_file_download(async_media_service): # noqa: WPS218 ) ) - downloaded_file = await async_media_service.download("MED-456") + result = await async_media_service.download("MED-456") assert mock_resource.call_count == 1 - request = mock_download.calls[0].request accept_header = (b"Accept", b"image/jpg") assert accept_header in request.headers.raw assert mock_download.call_count == 1 - assert downloaded_file.file_contents == media_content - assert downloaded_file.content_type == "image/jpg" - assert downloaded_file.filename == "product_image.jpg" + assert result.file_contents == media_content + assert result.content_type == "image/jpg" + assert result.filename == "product_image.jpg" def test_sync_file_download(media_service): # noqa: WPS218 media_content = b"Image file content or binary data" - with respx.mock: mock_resource = respx.get( "https://api.example.com/public/v1/catalog/products/PRD-001/media/MED-456", @@ -352,16 +346,16 @@ def test_sync_file_download(media_service): # noqa: WPS218 ) ) - downloaded_file = media_service.download("MED-456") - assert mock_resource.call_count == 1 + result = media_service.download("MED-456") + assert mock_resource.call_count == 1 request = mock_download.calls[0].request accept_header = (b"Accept", b"image/jpg") assert accept_header in request.headers.raw assert mock_download.call_count == 1 - assert downloaded_file.file_contents == media_content - assert downloaded_file.content_type == "image/jpg" - assert downloaded_file.filename == "product_image.jpg" + assert result.file_contents == media_content + assert result.content_type == "image/jpg" + assert result.filename == "product_image.jpg" def test_sync_file_create_with_data(media_service): @@ -376,10 +370,10 @@ def test_sync_file_create_with_data(media_service): ) ) image_file = ("test.jpg", io.BytesIO(b"Image content"), "image/jpeg") - new_media = media_service.create({"name": "Product image"}, image_file) - request: httpx.Request = mock_route.calls[0].request + result = media_service.create({"name": "Product image"}, image_file) + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="media"\r\n' b"Content-Type: application/json\r\n\r\n" @@ -391,7 +385,7 @@ def test_sync_file_create_with_data(media_service): b"Image content\r\n" in request.content ) assert "multipart/form-data" in request.headers["Content-Type"] - assert new_media.to_dict() == media_data + assert result.to_dict() == media_data def test_sync_file_create_no_data(media_service): @@ -406,16 +400,16 @@ def test_sync_file_create_no_data(media_service): ) ) image_file = ("test.jpg", io.BytesIO(b"Image content"), "image/jpeg") - new_media = media_service.create({}, image_file) - request: httpx.Request = mock_route.calls[0].request + result = media_service.create({}, image_file) + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="file"; filename="test.jpg"\r\n' b"Content-Type: image/jpeg\r\n\r\n" b"Image content\r\n" in request.content ) - assert new_media.to_dict() == media_data + assert result.to_dict() == media_data @pytest.mark.parametrize( @@ -432,12 +426,12 @@ def test_sync_get_mixin(dummy_service, select_value): "https://api.example.com/api/v1/test/RES-123", params={"select": "id,name"} ).mock(return_value=httpx.Response(httpx.codes.OK, json=resource_data)) - resource = dummy_service.get("RES-123", select=select_value) + result = dummy_service.get("RES-123", select=select_value) request = mock_route.calls[0].request accept_header = (b"Accept", b"application/json") assert accept_header in request.headers.raw - assert resource.to_dict() == resource_data + assert result.to_dict() == resource_data async def test_async_get(async_dummy_service): @@ -447,12 +441,12 @@ async def test_async_get(async_dummy_service): "https://api.example.com/api/v1/test/RES-123", params={"select": "id,name"} ).mock(return_value=httpx.Response(httpx.codes.OK, json=resource_data)) - resource = await async_dummy_service.get("RES-123", select=["id", "name"]) + result = await async_dummy_service.get("RES-123", select=["id", "name"]) request = mock_route.calls[0].request accept_header = (b"Accept", b"application/json") assert accept_header in request.headers.raw - assert resource.to_dict() == resource_data + assert result.to_dict() == resource_data async def test_async_get_select_str(async_dummy_service): @@ -462,22 +456,22 @@ async def test_async_get_select_str(async_dummy_service): "https://api.example.com/api/v1/test/RES-123", params={"select": "id,name"} ).mock(return_value=httpx.Response(httpx.codes.OK, json=resource_data)) - resource = await async_dummy_service.get("RES-123", select="id,name") + result = await async_dummy_service.get("RES-123", select="id,name") request = mock_route.calls[0].request accept_header = (b"Accept", b"application/json") assert accept_header in request.headers.raw - assert resource.to_dict() == resource_data + assert result.to_dict() == resource_data def test_queryable_mixin_order_by(dummy_service): - ordered_service = dummy_service.order_by("created", "-name") + result = dummy_service.order_by("created", "-name") - assert ordered_service != dummy_service + assert result != dummy_service assert dummy_service.query_state.order_by is None - assert ordered_service.query_state.order_by == ["created", "-name"] - assert ordered_service.http_client is dummy_service.http_client - assert ordered_service.endpoint_params == dummy_service.endpoint_params + assert result.query_state.order_by == ["created", "-name"] + assert result.http_client is dummy_service.http_client + assert result.endpoint_params == dummy_service.endpoint_params def test_queryable_mixin_order_by_exception(dummy_service): @@ -490,33 +484,33 @@ def test_queryable_mixin_order_by_exception(dummy_service): def test_queryable_mixin_filter(dummy_service, filter_status_active): - filtered_service = dummy_service.filter(filter_status_active) + result = dummy_service.filter(filter_status_active) - assert filtered_service != dummy_service + assert result != dummy_service assert dummy_service.query_state.filter is None - assert filtered_service.query_state.filter == filter_status_active - assert filtered_service.http_client is dummy_service.http_client - assert filtered_service.endpoint_params == dummy_service.endpoint_params + assert result.query_state.filter == filter_status_active + assert result.http_client is dummy_service.http_client + assert result.endpoint_params == dummy_service.endpoint_params def test_queryable_mixin_filters(dummy_service): filter1 = RQLQuery(status="active") filter2 = RQLQuery(name="test") - filtered_service = dummy_service.filter(filter1).filter(filter2) + result = dummy_service.filter(filter1).filter(filter2) assert dummy_service.query_state.filter is None - assert filtered_service.query_state.filter == filter1 & filter2 + assert result.query_state.filter == filter1 & filter2 def test_queryable_mixin_select(dummy_service): - selected_service = dummy_service.select("id", "name", "-audit") + result = dummy_service.select("id", "name", "-audit") - assert selected_service != dummy_service + assert result != dummy_service assert dummy_service.query_state.select is None - assert selected_service.query_state.select == ["id", "name", "-audit"] - assert selected_service.http_client is dummy_service.http_client - assert selected_service.endpoint_params == dummy_service.endpoint_params + assert result.query_state.select == ["id", "name", "-audit"] + assert result.http_client is dummy_service.http_client + assert result.endpoint_params == dummy_service.endpoint_params def test_queryable_mixin_select_exception(dummy_service): @@ -529,14 +523,14 @@ def test_queryable_mixin_select_exception(dummy_service): def test_queryable_mixin_method_chaining(dummy_service, filter_status_active): - chained_service = ( + result = ( dummy_service.filter(filter_status_active).order_by("created", "-name").select("id", "name") ) - assert chained_service != dummy_service - assert chained_service.query_state.filter == filter_status_active - assert chained_service.query_state.order_by == ["created", "-name"] - assert chained_service.query_state.select == ["id", "name"] + assert result != dummy_service + assert result.query_state.filter == filter_status_active + assert result.query_state.order_by == ["created", "-name"] + assert result.query_state.select == ["id", "name"] def test_col_mx_fetch_one_success(dummy_service, single_result_response): @@ -545,12 +539,11 @@ def test_col_mx_fetch_one_success(dummy_service, single_result_response): return_value=single_result_response ) - resource = dummy_service.fetch_one() + result = dummy_service.fetch_one() - assert resource.id == "ID-1" - assert resource.name == "Test Resource" + assert result.id == "ID-1" + assert result.name == "Test Resource" assert mock_route.called - first_request = mock_route.calls[0].request assert "limit=1" in str(first_request.url) assert "offset=0" in str(first_request.url) @@ -578,16 +571,15 @@ def test_col_mx_fetch_one_with_filters(dummy_service, single_result_response, fi filtered_collection = ( dummy_service.filter(filter_status_active).select("id", "name").order_by("created") ) - with respx.mock: mock_route = respx.get("https://api.example.com/api/v1/test").mock( return_value=single_result_response ) - resource = filtered_collection.fetch_one() - assert resource.id == "ID-1" - assert mock_route.called + result = filtered_collection.fetch_one() + assert result.id == "ID-1" + assert mock_route.called first_request = mock_route.calls[0].request assert first_request.method == "GET" assert first_request.url == ( @@ -603,7 +595,6 @@ def test_col_mx_fetch_page_with_filter(dummy_service, list_response, filter_stat .select("-audit", "product.agreements", "-product.agreements.product") .order_by("-created", "name") ) - expected_url = ( "https://api.example.com/api/v1/test?limit=10&offset=5" "&order=-created,name" @@ -614,9 +605,10 @@ def test_col_mx_fetch_page_with_filter(dummy_service, list_response, filter_stat mock_route = respx.get("https://api.example.com/api/v1/test").mock( return_value=list_response ) - collection_results = custom_collection.fetch_page(limit=10, offset=5) - assert collection_results.to_list() == [{"id": "ID-1"}] + result = custom_collection.fetch_page(limit=10, offset=5) + + assert result.to_list() == [{"id": "ID-1"}] assert mock_route.called assert mock_route.call_count == 1 request = mock_route.calls[0].request @@ -630,12 +622,12 @@ def test_col_mx_iterate_single_page(dummy_service, single_page_response): return_value=single_page_response ) - resources = list(dummy_service.iterate()) - request = mock_route.calls[0].request + result = list(dummy_service.iterate()) - assert len(resources) == 2 - assert resources[0].to_dict() == {"id": "ID-1", "name": "Resource 1"} - assert resources[1].to_dict() == {"id": "ID-2", "name": "Resource 2"} + request = mock_route.calls[0].request + assert len(result) == 2 + assert result[0].to_dict() == {"id": "ID-1", "name": "Resource 1"} + assert result[1].to_dict() == {"id": "ID-2", "name": "Resource 2"} assert mock_route.call_count == 1 assert request.url == "https://api.example.com/api/v1/test?limit=100&offset=0" @@ -651,13 +643,13 @@ def test_col_mx_iterate_multiple_pages( return_value=multi_page_response_page2 ) - resources = list(dummy_service.iterate(2)) + result = list(dummy_service.iterate(2)) - assert len(resources) == 4 - assert resources[0].id == "ID-1" - assert resources[1].id == "ID-2" - assert resources[2].id == "ID-3" - assert resources[3].id == "ID-4" + assert len(result) == 4 + assert result[0].id == "ID-1" + assert result[1].id == "ID-2" + assert result[2].id == "ID-3" + assert result[3].id == "ID-4" def test_col_mx_iterate_empty_results(dummy_service, empty_response): @@ -666,9 +658,9 @@ def test_col_mx_iterate_empty_results(dummy_service, empty_response): return_value=empty_response ) - resources = list(dummy_service.iterate(2)) + result = list(dummy_service.iterate(2)) - assert len(resources) == 0 + assert len(result) == 0 assert mock_route.call_count == 1 @@ -678,11 +670,11 @@ def test_col_mx_iterate_no_meta(dummy_service, no_meta_response): return_value=no_meta_response ) - resources = list(dummy_service.iterate()) + result = list(dummy_service.iterate()) - assert len(resources) == 2 - assert resources[0].id == "ID-1" - assert resources[1].id == "ID-2" + assert len(result) == 2 + assert result[0].id == "ID-1" + assert result[1].id == "ID-2" assert mock_route.call_count == 1 @@ -690,7 +682,6 @@ def test_col_mx_iterate_with_filters(dummy_service, filter_status_active): filtered_collection = ( dummy_service.filter(filter_status_active).select("id", "name").order_by("created") ) - response = httpx.Response( httpx.codes.OK, json={ @@ -704,16 +695,14 @@ def test_col_mx_iterate_with_filters(dummy_service, filter_status_active): }, }, ) - with respx.mock: mock_route = respx.get("https://api.example.com/api/v1/test").mock(return_value=response) - resources = list(filtered_collection.iterate()) - - assert len(resources) == 1 - assert resources[0].id == "ID-1" - assert resources[0].name == "Active Resource" + result = list(filtered_collection.iterate()) + assert len(result) == 1 + assert result[0].id == "ID-1" + assert result[0].name == "Active Resource" request = mock_route.calls[0].request assert ( str(request.url) == "https://api.example.com/api/v1/test" @@ -735,16 +724,13 @@ def test_col_mx_iterate_lazy_evaluation(dummy_service): }, }, ) - with respx.mock: mock_route = respx.get("https://api.example.com/api/v1/test").mock(return_value=response) - iterator = dummy_service.iterate() + result = dummy_service.iterate() assert mock_route.call_count == 0 - - first_resource = next(iterator) - + first_resource = next(result) assert mock_route.call_count == 1 assert first_resource.id == "ID-1" @@ -756,7 +742,6 @@ def test_col_mx_iterate_handles_api_errors(dummy_service): httpx.codes.INTERNAL_SERVER_ERROR, json={"error": "Internal Server Error"} ) ) - iterator = dummy_service.iterate() with pytest.raises(MPTAPIError): @@ -769,12 +754,11 @@ async def test_async_col_mx_fetch_one_success(async_dummy_service, single_result return_value=single_result_response ) - resource = await async_dummy_service.fetch_one() + result = await async_dummy_service.fetch_one() - assert resource.id == "ID-1" - assert resource.name == "Test Resource" + assert result.id == "ID-1" + assert result.name == "Test Resource" assert mock_route.called - first_request = mock_route.calls[0].request assert "limit=1" in str(first_request.url) assert "offset=0" in str(first_request.url) @@ -806,16 +790,14 @@ async def test_async_col_mx_fetch_one_with_filters( filtered_collection = ( async_dummy_service.filter(filter_status_active).select("id", "name").order_by("created") ) - with respx.mock: mock_route = respx.get("https://api.example.com/api/v1/test").mock( return_value=single_result_response ) - resource = await filtered_collection.fetch_one() + result = await filtered_collection.fetch_one() - assert resource.id == "ID-1" + assert result.id == "ID-1" assert mock_route.called - first_request = mock_route.calls[0].request assert first_request.method == "GET" assert first_request.url == ( @@ -833,7 +815,6 @@ async def test_async_col_mx_fetch_page_with_filter( .select("-audit", "product.agreements", "-product.agreements.product") .order_by("-created", "name") ) - expected_url = ( "https://api.example.com/api/v1/test?limit=10&offset=5" "&order=-created,name" @@ -844,9 +825,10 @@ async def test_async_col_mx_fetch_page_with_filter( mock_route = respx.get("https://api.example.com/api/v1/test").mock( return_value=list_response ) - collection_results = await custom_collection.fetch_page(limit=10, offset=5) - assert collection_results.to_list() == [{"id": "ID-1"}] + result = await custom_collection.fetch_page(limit=10, offset=5) + + assert result.to_list() == [{"id": "ID-1"}] assert mock_route.called assert mock_route.call_count == 1 request = mock_route.calls[0].request @@ -860,13 +842,12 @@ async def test_async_col_mx_iterate_single_page(async_dummy_service, single_page return_value=single_page_response ) - resources = [resource async for resource in async_dummy_service.iterate()] - - request = mock_route.calls[0].request + result = [resource async for resource in async_dummy_service.iterate()] - assert len(resources) == 2 - assert resources[0].to_dict() == {"id": "ID-1", "name": "Resource 1"} - assert resources[1].to_dict() == {"id": "ID-2", "name": "Resource 2"} + request = mock_route.calls[0].request + assert len(result) == 2 + assert result[0].to_dict() == {"id": "ID-1", "name": "Resource 1"} + assert result[1].to_dict() == {"id": "ID-2", "name": "Resource 2"} assert mock_route.call_count == 1 assert request.url == "https://api.example.com/api/v1/test?limit=100&offset=0" @@ -882,13 +863,13 @@ async def test_async_col_mx_iterate_multiple_pages( return_value=multi_page_response_page2 ) - resources = [resource async for resource in async_dummy_service.iterate(2)] + result = [resource async for resource in async_dummy_service.iterate(2)] - assert len(resources) == 4 - assert resources[0].id == "ID-1" - assert resources[1].id == "ID-2" - assert resources[2].id == "ID-3" - assert resources[3].id == "ID-4" + assert len(result) == 4 + assert result[0].id == "ID-1" + assert result[1].id == "ID-2" + assert result[2].id == "ID-3" + assert result[3].id == "ID-4" async def test_async_col_mx_iterate_empty_results(async_dummy_service, empty_response): @@ -897,9 +878,9 @@ async def test_async_col_mx_iterate_empty_results(async_dummy_service, empty_res return_value=empty_response ) - resources = [resource async for resource in async_dummy_service.iterate()] + result = [resource async for resource in async_dummy_service.iterate()] - assert len(resources) == 0 + assert len(result) == 0 assert mock_route.call_count == 1 @@ -909,11 +890,11 @@ async def test_async_col_mx_iterate_no_meta(async_dummy_service, no_meta_respons return_value=no_meta_response ) - resources = [resource async for resource in async_dummy_service.iterate()] + result = [resource async for resource in async_dummy_service.iterate()] - assert len(resources) == 2 - assert resources[0].id == "ID-1" - assert resources[1].id == "ID-2" + assert len(result) == 2 + assert result[0].id == "ID-1" + assert result[1].id == "ID-2" assert mock_route.call_count == 1 @@ -921,7 +902,6 @@ async def test_async_col_mx_iterate_with_filters(async_dummy_service, filter_sta filtered_collection = ( async_dummy_service.filter(filter_status_active).select("id", "name").order_by("created") ) - response = httpx.Response( httpx.codes.OK, json={ @@ -935,16 +915,14 @@ async def test_async_col_mx_iterate_with_filters(async_dummy_service, filter_sta }, }, ) - with respx.mock: mock_route = respx.get("https://api.example.com/api/v1/test").mock(return_value=response) - resources = [resource async for resource in filtered_collection.iterate()] - - assert len(resources) == 1 - assert resources[0].id == "ID-1" - assert resources[0].name == "Active Resource" + result = [resource async for resource in filtered_collection.iterate()] + assert len(result) == 1 + assert result[0].id == "ID-1" + assert result[0].name == "Active Resource" request = mock_route.calls[0].request assert ( str(request.url) == "https://api.example.com/api/v1/test" @@ -966,18 +944,15 @@ async def test_async_col_mx_iterate_lazy_evaluation(async_dummy_service): }, }, ) - with respx.mock: mock_route = respx.get("https://api.example.com/api/v1/test").mock(return_value=response) - iterator = async_dummy_service.iterate() + result = async_dummy_service.iterate() # No requests should be made until we start iterating assert mock_route.call_count == 0 - # Get first item to trigger the first request - first_resource = await anext(iterator) - + first_resource = await anext(result) assert first_resource.id == "ID-1" assert mock_route.call_count == 1 @@ -1006,10 +981,10 @@ def test_modifieable_resource_mixin(method_name): class Service(ModifiableResourceMixin[DummyModel]): # noqa: WPS431 """Dummy service class for testing required methods.""" - service = Service() + result = Service() - assert hasattr(service, method_name), f"ManagedResourceMixin should have {method_name} method" - assert callable(getattr(service, method_name)), f"{method_name} should be callable" + assert hasattr(result, method_name), f"ManagedResourceMixin should have {method_name} method" + assert callable(getattr(result, method_name)), f"{method_name} should be callable" @pytest.mark.parametrize( @@ -1024,12 +999,12 @@ def test_async_modifiable_resource_mixin(async_dummy_service, method_name): class Service(AsyncModifiableResourceMixin[DummyModel]): # noqa: WPS431 """Dummy service class for testing required methods.""" - service = Service() + result = Service() - assert hasattr(service, method_name), ( + assert hasattr(result, method_name), ( f"AsyncManagedResourceMixin should have {method_name} method" ) - assert callable(getattr(service, method_name)), f"{method_name} should be callable" + assert callable(getattr(result, method_name)), f"{method_name} should be callable" @pytest.mark.parametrize( @@ -1045,10 +1020,10 @@ def test_managed_resource_mixin(method_name): class ManagedService(ManagedResourceMixin[DummyModel]): # noqa: WPS431 """Dummy service class for testing required methods.""" - service = ManagedService() + result = ManagedService() - assert hasattr(service, method_name), f"ManagedResourceMixin should have {method_name} method" - assert callable(getattr(service, method_name)), f"{method_name} should be callable" + assert hasattr(result, method_name), f"ManagedResourceMixin should have {method_name} method" + assert callable(getattr(result, method_name)), f"{method_name} should be callable" @pytest.mark.parametrize( @@ -1064,12 +1039,12 @@ def test_async_managed_resource_mixin(async_dummy_service, method_name): class AsyncManagedService(AsyncManagedResourceMixin[DummyModel]): # noqa: WPS431 """Dummy service class for testing required methods.""" - async_service = AsyncManagedService() + result = AsyncManagedService() - assert hasattr(async_service, method_name), ( + assert hasattr(result, method_name), ( f"AsyncManagedResourceMixin should have {method_name} method" ) - assert callable(getattr(async_service, method_name)), f"{method_name} should be callable" + assert callable(getattr(result, method_name)), f"{method_name} should be callable" def test_sync_create_with_icon_with_data(icon_service): @@ -1077,7 +1052,6 @@ def test_sync_create_with_icon_with_data(icon_service): resource_key = "icon_data" icon = ("icon.png", io.BytesIO(b"Icon content"), "image/png") icon_key = "icon" - with respx.mock: mock_route = respx.post("https://api.example.com/public/v1/dummy/icon/").mock( return_value=httpx.Response( @@ -1085,15 +1059,15 @@ def test_sync_create_with_icon_with_data(icon_service): json=resource_data, ) ) - new_resource = icon_service.create( + + result = icon_service.create( resource_data=resource_data, icon=icon, data_key=resource_key, icon_key=icon_key, ) - request: httpx.Request = mock_route.calls[0].request - + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="icon_data"\r\n' b"Content-Type: application/json\r\n\r\n" @@ -1105,7 +1079,7 @@ def test_sync_create_with_icon_with_data(icon_service): b"Icon content\r\n" in request.content ) assert "multipart/form-data" in request.headers["Content-Type"] - assert new_resource.to_dict() == resource_data + assert result.to_dict() == resource_data def test_sync_update_with_icon_with_data(icon_service): @@ -1114,7 +1088,6 @@ def test_sync_update_with_icon_with_data(icon_service): resource_key = "icon_data" icon = ("icon.png", io.BytesIO(b"Updated icon content"), "image/png") icon_key = "icon" - with respx.mock: mock_route = respx.put(f"https://api.example.com/public/v1/dummy/icon/{resource_id}").mock( return_value=httpx.Response( @@ -1122,7 +1095,8 @@ def test_sync_update_with_icon_with_data(icon_service): json={"id": resource_id, "name": "Updated Icon Object"}, ) ) - updated_resource = icon_service.update( + + result = icon_service.update( resource_id, resource_data=resource_data, icon=icon, @@ -1130,8 +1104,7 @@ def test_sync_update_with_icon_with_data(icon_service): icon_key=icon_key, ) - request: httpx.Request = mock_route.calls[0].request - + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="icon_data"\r\n' b"Content-Type: application/json\r\n\r\n" @@ -1143,7 +1116,7 @@ def test_sync_update_with_icon_with_data(icon_service): b"Updated icon content\r\n" in request.content ) assert "multipart/form-data" in request.headers["Content-Type"] - assert updated_resource.to_dict() == { + assert result.to_dict() == { "id": resource_id, "name": "Updated Icon Object", } @@ -1159,16 +1132,16 @@ async def test_async_create_with_icon_no_data(async_icon_service): ) ) icon = ("icon.png", io.BytesIO(b"Icon content"), "image/png") - new_resource = await async_icon_service.create(resource_data=None, icon=icon) - request: httpx.Request = mock_route.calls[0].request + result = await async_icon_service.create(resource_data=None, icon=icon) + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="icon"; filename="icon.png"\r\n' b"Content-Type: image/png\r\n\r\n" b"Icon content\r\n" in request.content ) - assert new_resource.to_dict() == resource_data + assert result.to_dict() == resource_data def test_sync_create_with_icon_no_data(icon_service): @@ -1181,16 +1154,16 @@ def test_sync_create_with_icon_no_data(icon_service): ) ) icon = ("icon.png", io.BytesIO(b"Icon content"), "image/png") - new_resource = icon_service.create(resource_data=None, icon=icon) - request: httpx.Request = mock_route.calls[0].request + result = icon_service.create(resource_data=None, icon=icon) + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="icon"; filename="icon.png"\r\n' b"Content-Type: image/png\r\n\r\n" b"Icon content\r\n" in request.content ) - assert new_resource.to_dict() == resource_data + assert result.to_dict() == resource_data async def test_async_create_with_icon_with_data(async_icon_service): @@ -1203,16 +1176,16 @@ async def test_async_create_with_icon_with_data(async_icon_service): ) ) icon = ("icon.png", io.BytesIO(b"Icon content"), "image/png") - new_resource = await async_icon_service.create(resource_data=None, icon=icon) - request: httpx.Request = mock_route.calls[0].request + result = await async_icon_service.create(resource_data=None, icon=icon) + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="icon"; filename="icon.png"\r\n' b"Content-Type: image/png\r\n\r\n" b"Icon content\r\n" in request.content ) - assert new_resource.to_dict() == resource_data + assert result.to_dict() == resource_data async def test_async_update_with_icon_with_data(async_icon_service): @@ -1229,7 +1202,8 @@ async def test_async_update_with_icon_with_data(async_icon_service): json={"id": resource_id, "name": "Updated Icon Object"}, ) ) - updated_resource = await async_icon_service.update( + + result = await async_icon_service.update( resource_id, resource_data=resource_data, icon=icon, @@ -1237,8 +1211,7 @@ async def test_async_update_with_icon_with_data(async_icon_service): icon_key=icon_key, ) - request: httpx.Request = mock_route.calls[0].request - + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="icon_data"\r\n' b"Content-Type: application/json\r\n\r\n" @@ -1250,7 +1223,7 @@ async def test_async_update_with_icon_with_data(async_icon_service): b"Updated icon content\r\n" in request.content ) assert "multipart/form-data" in request.headers["Content-Type"] - assert updated_resource.to_dict() == { + assert result.to_dict() == { "id": resource_id, "name": "Updated Icon Object", } diff --git a/tests/unit/http/test_query_state.py b/tests/unit/http/test_query_state.py index c03c02c8..98e131cf 100644 --- a/tests/unit/http/test_query_state.py +++ b/tests/unit/http/test_query_state.py @@ -9,13 +9,13 @@ def query_state(): def test_filter_init(filter_status_active): - query_state = QueryState( + result = QueryState( rql=filter_status_active, select=["agreement", "-product"], order_by=["-created", "name"] ) - assert query_state.filter == filter_status_active - assert query_state.select == ["agreement", "-product"] - assert query_state.order_by == ["-created", "name"] + assert result.filter == filter_status_active + assert result.select == ["agreement", "-product"] + assert result.order_by == ["-created", "name"] def test_build_url(filter_status_active): @@ -25,9 +25,9 @@ def test_build_url(filter_status_active): order_by=["-created", "name"], ) - query_string = query_state.build() + result = query_state.build() - assert query_string == ( + assert result == ( "order=-created,name" "&select=-audit,product.agreements,-product.agreements.product" "&eq(status,active)" @@ -35,15 +35,15 @@ def test_build_url(filter_status_active): def test_empty_build(query_state): - query_string = query_state.build() + result = query_state.build() - assert not query_string + assert not result def test_build_with_params(filter_status_active): query_state = QueryState(rql=filter_status_active, order_by=["created"], select=["name"]) query_params = {"limit": "10"} - query_string = query_state.build(query_params) + result = query_state.build(query_params) - assert query_string == "limit=10&order=created&select=name&eq(status,active)" + assert result == "limit=10&order=created&select=name&eq(status,active)" diff --git a/tests/unit/models/collection/test_collection_init.py b/tests/unit/models/collection/test_collection_init.py index 9aa1f1c3..481fcfef 100644 --- a/tests/unit/models/collection/test_collection_init.py +++ b/tests/unit/models/collection/test_collection_init.py @@ -1,11 +1,11 @@ -def test_generic_collection_empty(empty_collection): +def test_generic_collection_empty(empty_collection): # noqa: AAA01 assert empty_collection.meta is None assert len(empty_collection) == 0 assert list(empty_collection) == [] assert not empty_collection -def test_generic_collection_with_data(collection, response_collection_data): +def test_generic_collection_with_data(collection): # noqa: AAA01 assert len(collection) == 3 assert bool(collection) is True for resource in collection.to_list(): diff --git a/tests/unit/models/collection/test_collection_iteration.py b/tests/unit/models/collection/test_collection_iteration.py index df8c43bb..55e427ae 100644 --- a/tests/unit/models/collection/test_collection_iteration.py +++ b/tests/unit/models/collection/test_collection_iteration.py @@ -2,17 +2,17 @@ def test_iteration(collection): - resources = list(collection) + result = list(collection) - assert len(resources) == 3 + assert len(result) == 3 def test_iteration_next(collection, response_collection_data): - iterator = iter(collection) - assert next(iterator).to_dict() == response_collection_data[0] - assert next(iterator).to_dict() == response_collection_data[1] - assert next(iterator).to_dict() == response_collection_data[2] + result = iter(collection) + assert next(result).to_dict() == response_collection_data[0] + assert next(result).to_dict() == response_collection_data[1] + assert next(result).to_dict() == response_collection_data[2] # Check that iterator is exhausted with pytest.raises(StopIteration): - next(iterator) + next(result) diff --git a/tests/unit/models/collection/test_collection_list.py b/tests/unit/models/collection/test_collection_list.py index ff0ea5f3..558fae56 100644 --- a/tests/unit/models/collection/test_collection_list.py +++ b/tests/unit/models/collection/test_collection_list.py @@ -1,7 +1,7 @@ import pytest -def test_getitem_access(collection, response_collection_data): +def test_getitem_access(collection, response_collection_data): # noqa: AAA01 assert collection[0].to_dict() == response_collection_data[0] assert collection[1].to_dict() == response_collection_data[1] assert collection[2].to_dict() == response_collection_data[2] @@ -12,25 +12,25 @@ def test_getitem_out_of_bounds(collection): collection[10] -def test_length(empty_collection, collection): +def test_length(empty_collection, collection): # noqa: AAA01 assert len(empty_collection) == 0 assert len(collection) == 3 -def test_bool_conversion(empty_collection, collection, response_collection_data): +def test_bool_conversion(empty_collection, collection): # noqa: AAA01 assert bool(empty_collection) is False assert bool(collection) is True def test_to_list_method(collection, response_collection_data): - resources = collection.to_list() + result = collection.to_list() - assert resources == response_collection_data - assert isinstance(resources, list) + assert result == response_collection_data + assert isinstance(result, list) def test_empty_collection_to_list(empty_collection): - resources = empty_collection.to_list() + result = empty_collection.to_list() - assert resources == [] - assert isinstance(resources, list) + assert result == [] + assert isinstance(result, list) diff --git a/tests/unit/models/meta/test_meta.py b/tests/unit/models/meta/test_meta.py index 0e8c2aad..2f914fcf 100644 --- a/tests/unit/models/meta/test_meta.py +++ b/tests/unit/models/meta/test_meta.py @@ -22,10 +22,10 @@ def invalid_response_fixture(): def test_meta_from_response(responses_fixture): - meta = Meta.from_response(responses_fixture) + result = Meta.from_response(responses_fixture) - assert isinstance(meta.pagination, Pagination) - assert meta.pagination == Pagination(limit=25, offset=50, total=300) + assert isinstance(result.pagination, Pagination) + assert result.pagination == Pagination(limit=25, offset=50, total=300) def test_invalid_meta_from_response(invalid_response_fixture): diff --git a/tests/unit/models/meta/test_pagination.py b/tests/unit/models/meta/test_pagination.py index cf670e2a..15b0ba86 100644 --- a/tests/unit/models/meta/test_pagination.py +++ b/tests/unit/models/meta/test_pagination.py @@ -4,24 +4,23 @@ def test_default_page(): # noqa: WPS218 - pagination = Pagination() - - assert pagination.limit == 0 - assert pagination.offset == 0 - assert pagination.total == 0 + result = Pagination() - assert pagination.has_next() is False - assert pagination.num_page() == 0 - assert pagination.total_pages() == 0 - assert pagination.next_offset() == 0 + assert result.limit == 0 + assert result.offset == 0 + assert result.total == 0 + assert result.has_next() is False + assert result.num_page() == 0 + assert result.total_pages() == 0 + assert result.next_offset() == 0 def test_pagination_initialization(): - pagination = Pagination(limit=10, offset=0, total=100) + result = Pagination(limit=10, offset=0, total=100) - assert pagination.limit == 10 - assert pagination.offset == 0 - assert pagination.total == 100 + assert result.limit == 10 + assert result.offset == 0 + assert result.total == 100 @pytest.mark.parametrize( @@ -37,9 +36,9 @@ def test_has_next(mocker, num_page, total_pages, expected_has_next): mocker.patch.object(pagination, "num_page", return_value=num_page) mocker.patch.object(pagination, "total_pages", return_value=total_pages) - has_next = pagination.has_next() + result = pagination.has_next() - assert has_next == expected_has_next + assert result == expected_has_next @pytest.mark.parametrize( @@ -55,7 +54,9 @@ def test_has_next(mocker, num_page, total_pages, expected_has_next): def test_num_page(limit, offset, expected_page): pagination = Pagination(limit=limit, offset=offset, total=5) - assert pagination.num_page() == expected_page + result = pagination.num_page() + + assert result == expected_page @pytest.mark.parametrize( @@ -70,7 +71,9 @@ def test_num_page(limit, offset, expected_page): def test_total_pages(limit, total, expected_total_pages): pagination = Pagination(limit=limit, offset=0, total=total) - assert pagination.total_pages() == expected_total_pages + result = pagination.total_pages() + + assert result == expected_total_pages @pytest.mark.parametrize( @@ -84,4 +87,6 @@ def test_total_pages(limit, total, expected_total_pages): def test_next_offset(limit, offset, expected_next_offset): pagination = Pagination(limit=limit, offset=offset, total=3) - assert pagination.next_offset() == expected_next_offset + result = pagination.next_offset() + + assert result == expected_next_offset diff --git a/tests/unit/models/resource/test_resource.py b/tests/unit/models/resource/test_resource.py index 52ace063..0570d781 100644 --- a/tests/unit/models/resource/test_resource.py +++ b/tests/unit/models/resource/test_resource.py @@ -12,10 +12,10 @@ def meta_data(): def test_resource_empty(): - resource = Model() + result = Model() - assert resource.meta is None - assert resource.to_dict() == {} + assert result.meta is None + assert result.to_dict() == {} def test_from_response(meta_data): @@ -23,25 +23,24 @@ def test_from_response(meta_data): response = Response(200, json=record_data | {"$meta": meta_data}) expected_meta = Meta.from_response(response) - resource = Model.from_response(response) + result = Model.from_response(response) - assert resource.to_dict() == record_data - assert resource.meta == expected_meta + assert result.to_dict() == record_data + assert result.meta == expected_meta -def test_attribute_getter(mocker, meta_data): +def test_attribute_getter(meta_data): resource_data = {"id": 1, "name": {"given": "Albert", "family": "Einstein"}} response_data = resource_data | {"$meta": meta_data} - response = Response(200, json=response_data) - resource = Model.from_response(response) + result = Model.from_response(response) - assert resource.id == "1" - assert resource.name.given == "Albert" + assert result.id == "1" + assert result.name.given == "Albert" -def test_attribute_setter(): +def test_attribute_setter(): # noqa: AAA01 resource_data = {"id": 1, "name": {"given": "Albert", "family": "Einstein"}} resource = Model(resource_data) @@ -54,35 +53,38 @@ def test_attribute_setter(): def test_wrong_data_type(): response = Response(200, json=1) + with pytest.raises(TypeError, match=r"Response data must be a dict."): Model.from_response(response) def test_id_property_with_string_id(): resource_data = {"id": "abc-123"} - resource = Model(resource_data) - assert resource.id == "abc-123" - assert isinstance(resource.id, str) + result = Model(resource_data) + + assert result.id == "abc-123" + assert isinstance(result.id, str) def test_id_property_with_numeric_id(): resource_data = {"id": 1024} - resource = Model(resource_data) - assert resource.id == "1024" - assert isinstance(resource.id, str) + result = Model(resource_data) + + assert result.id == "1024" + assert isinstance(result.id, str) def test_case_conversion(): resource_data = {"id": "abc-123", "FullName": "Alice Smith"} - resource = Model(resource_data) + result = Model(resource_data) - assert resource.full_name == "Alice Smith" - assert resource.to_dict() == resource_data + assert result.full_name == "Alice Smith" + assert result.to_dict() == resource_data with pytest.raises(AttributeError): - _ = resource.FullName # noqa: WPS122 + _ = result.FullName # noqa: WPS122 def test_deep_case_conversion(): @@ -91,17 +93,15 @@ def test_deep_case_conversion(): "id": "ABC-123", "contact": {"id": "ABC-345", "FullName": "Alice Smith", "StreetAddress": "123 Main St"}, } - resource = Model(resource_data) - resource.contact.StreetAddress = "123 Main St" + + resource.contact.StreetAddress = "123 Main St" # act assert resource.contact.full_name == "Alice Smith" assert resource.contact.street_address == "123 Main St" assert resource.to_dict() == expected_resource_data - with pytest.raises(AttributeError): _ = resource.contact.FullName # noqa: WPS122 - with pytest.raises(AttributeError): _ = resource.contact.StreetAddress # noqa: WPS122 @@ -109,10 +109,10 @@ def test_deep_case_conversion(): def test_repr(): resource_data = {"id": "abc-123", "FullName": "Alice Smith"} - resource = Model(resource_data) + result = Model(resource_data) - assert repr(resource) == "" - assert str(resource) == "" + assert repr(result) == "" + assert str(result) == "" def test_mapping(): @@ -122,10 +122,11 @@ class MappingModel(Model): # noqa: WPS431 "Full_Name": "name", } + # BL resource_data = {"id": "abc-123", "second_id": "resource-abc-123", "Full_Name": "Alice Smith"} - resource = MappingModel(resource_data) + result = MappingModel(resource_data) - assert resource.name == "Alice Smith" - assert resource.resource_id == "resource-abc-123" - assert resource.to_dict() == resource_data + assert result.name == "Alice Smith" + assert result.resource_id == "resource-abc-123" + assert result.to_dict() == resource_data diff --git a/tests/unit/models/resource/test_resource_custom_key.py b/tests/unit/models/resource/test_resource_custom_key.py index e8fc3e55..24142f5a 100644 --- a/tests/unit/models/resource/test_resource_custom_key.py +++ b/tests/unit/models/resource/test_resource_custom_key.py @@ -11,7 +11,7 @@ def test_custom_data_key(): record_data = {"id": 1, "amount": 100} response = Response(200, json={"charge": record_data}) - resource = ChargeResourceMock.from_response(response) + result = ChargeResourceMock.from_response(response) - assert resource.id == "1" - assert resource.amount == 100 + assert result.id == "1" + assert result.amount == 100 diff --git a/tests/unit/models/test_file_model.py b/tests/unit/models/test_file_model.py index 8ed23a9d..1465ac1a 100644 --- a/tests/unit/models/test_file_model.py +++ b/tests/unit/models/test_file_model.py @@ -11,17 +11,18 @@ def empty_file(): def test_download_file_init(): response = Response(200) - download_file = FileModel(response) - assert download_file.response == response + result = FileModel(response) + + assert result.response == response def test_filename(empty_file): empty_file.response.headers["content-disposition"] = 'attachment; filename="test.pdf"' - filename = empty_file.filename + result = empty_file.filename - assert filename == "test.pdf" + assert result == "test.pdf" def test_filename_with_utf8_format(empty_file): @@ -29,9 +30,9 @@ def test_filename_with_utf8_format(empty_file): "attachment; filename*=UTF-8''test%20file.pdf" ) - filename = empty_file.filename + result = empty_file.filename - assert filename == "test%20file.pdf" + assert result == "test%20file.pdf" def test_filename_without_quotes(): @@ -39,24 +40,26 @@ def test_filename_without_quotes(): response.headers["content-disposition"] = "attachment; filename=test.pdf" download_file = FileModel(response) - filename = download_file.filename + result = download_file.filename - assert filename == "test.pdf" + assert result == "test.pdf" def test_filename_case_insensitive(empty_file): empty_file.response.headers["content-disposition"] = 'ATTACHMENT; FILENAME="test.pdf"' - assert empty_file.filename == "test.pdf" + result = empty_file.filename == "test.pdf" + + assert result is True def test_filename_no_content_disposition(empty_file): - filename = empty_file.filename + result = empty_file.filename - assert filename is None + assert result is None -def test_filename_empty_content_disposition(empty_file): +def test_filename_empty_content_disposition(empty_file): # noqa: AAA01 empty_file.response.headers["content-disposition"] = "" assert empty_file.filename is None @@ -67,28 +70,31 @@ def test_filename_no_filename_in_header(): response.headers["content-disposition"] = "attachment" download_file = FileModel(response) - filename = download_file.filename + result = download_file.filename - assert filename is None + assert result is None def test_file_contents(): response = Response(200, content=b"test content") - download_file = FileModel(response) - assert download_file.file_contents == b"test content" + result = FileModel(response) + + assert result.file_contents == b"test content" def test_content_type(): response = Response(200) response.headers["content-type"] = "application/pdf" - download_file = FileModel(response) - assert download_file.content_type == "application/pdf" + result = FileModel(response) + + assert result.content_type == "application/pdf" def test_content_type_none(): response = Response(200) - download_file = FileModel(response) - assert not download_file.content_type + result = FileModel(response) + + assert not result.content_type diff --git a/tests/unit/resources/accounts/test_account.py b/tests/unit/resources/accounts/test_account.py index a16c2ee4..a12b6c80 100644 --- a/tests/unit/resources/accounts/test_account.py +++ b/tests/unit/resources/accounts/test_account.py @@ -37,14 +37,18 @@ def async_accounts_users_service(async_http_client): "method", ["get", "create", "update", "enable", "disable", "activate", "deactivate", "validate"] ) def test_mixins_present(account_service, method): - assert hasattr(account_service, method) + result = hasattr(account_service, method) + + assert result is True @pytest.mark.parametrize( "method", ["get", "create", "update", "enable", "disable", "activate", "deactivate", "validate"] ) def test_async_mixins_present(async_account_service, method): - assert hasattr(async_account_service, method) + result = hasattr(async_account_service, method) + + assert result is True @pytest.mark.parametrize( @@ -54,10 +58,10 @@ def test_async_mixins_present(async_account_service, method): ], ) def test_property_services(account_service, service_method, expected_service_class): - service = getattr(account_service, service_method)("ACC-0000-0001") + result = getattr(account_service, service_method)("ACC-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"account_id": "ACC-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"account_id": "ACC-0000-0001"} @pytest.mark.parametrize( @@ -67,10 +71,10 @@ def test_property_services(account_service, service_method, expected_service_cla ], ) def test_async_property_services(async_account_service, service_method, expected_service_class): - service = getattr(async_account_service, service_method)("ACC-0000-0001") + result = getattr(async_account_service, service_method)("ACC-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"account_id": "ACC-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"account_id": "ACC-0000-0001"} def test_account_create(account_service, tmp_path): # noqa: WPS210 @@ -78,23 +82,20 @@ def test_account_create(account_service, tmp_path): # noqa: WPS210 "id": "ACC-0000-0001", "name": "Test Account", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.post(account_service.path).mock( return_value=httpx.Response(httpx.codes.CREATED, json=account_data) ) - account = account_service.create(account_data, logo=logo_file) + result = account_service.create(account_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "POST" assert request.url.path == "/public/v1/accounts/accounts" - assert account.to_dict() == account_data + assert result.to_dict() == account_data def test_account_update(account_service, tmp_path): # noqa: WPS210 @@ -102,23 +103,20 @@ def test_account_update(account_service, tmp_path): # noqa: WPS210 account_data = { "name": "Updated Test Account", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.put(f"{account_service.path}/{account_id}").mock( return_value=httpx.Response(httpx.codes.OK, json={"id": account_id, **account_data}) ) - account = account_service.update(account_id, account_data, logo=logo_file) + result = account_service.update(account_id, account_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "PUT" assert request.url.path == f"/public/v1/accounts/accounts/{account_id}" - assert account.to_dict() == {"id": account_id, **account_data} + assert result.to_dict() == {"id": account_id, **account_data} async def test_async_account_create(async_account_service, tmp_path): # noqa: WPS210 @@ -126,23 +124,20 @@ async def test_async_account_create(async_account_service, tmp_path): # noqa: W "id": "ACC-0000-0001", "name": "Test Account", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.post(async_account_service.path).mock( return_value=httpx.Response(httpx.codes.CREATED, json=account_data) ) - account = await async_account_service.create(account_data, logo=logo_file) + result = await async_account_service.create(account_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "POST" assert request.url.path == "/public/v1/accounts/accounts" - assert account.to_dict() == account_data + assert result.to_dict() == account_data async def test_async_account_update(async_account_service, tmp_path): # noqa: WPS210 @@ -150,20 +145,17 @@ async def test_async_account_update(async_account_service, tmp_path): # noqa: W account_data = { "name": "Updated Test Account", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.put(f"{async_account_service.path}/{account_id}").mock( return_value=httpx.Response(httpx.codes.OK, json={"id": account_id, **account_data}) ) - account = await async_account_service.update(account_id, account_data, logo=logo_file) + result = await async_account_service.update(account_id, account_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "PUT" assert request.url.path == f"/public/v1/accounts/accounts/{account_id}" - assert account.to_dict() == {"id": account_id, **account_data} + assert result.to_dict() == {"id": account_id, **account_data} diff --git a/tests/unit/resources/accounts/test_account_user_groups.py b/tests/unit/resources/accounts/test_account_user_groups.py index 1ef59c87..6a8061cb 100644 --- a/tests/unit/resources/accounts/test_account_user_groups.py +++ b/tests/unit/resources/accounts/test_account_user_groups.py @@ -23,23 +23,29 @@ def async_account_user_groups_service(async_http_client): def test_endpoint(account_user_groups_service): - assert account_user_groups_service.path == ( + result = account_user_groups_service.path == ( "/public/v1/accounts/account-users/ACC-0000-0001/groups" ) + assert result is True + def test_async_endpoint(async_account_user_groups_service): - assert async_account_user_groups_service.path == ( + result = async_account_user_groups_service.path == ( "/public/v1/accounts/account-users/ACC-0000-0001/groups" ) + assert result is True + @pytest.mark.parametrize( "method", ["create", "update", "delete"], ) def test_mixins_present(account_user_groups_service, method): - assert hasattr(account_user_groups_service, method) + result = hasattr(account_user_groups_service, method) + + assert result is True @pytest.mark.parametrize( @@ -47,4 +53,6 @@ def test_mixins_present(account_user_groups_service, method): ["create", "update", "delete"], ) def test_async_mixins_present(async_account_user_groups_service, method): - assert hasattr(async_account_user_groups_service, method) + result = hasattr(async_account_user_groups_service, method) + + assert result is True diff --git a/tests/unit/resources/accounts/test_account_users.py b/tests/unit/resources/accounts/test_account_users.py index 5607d42f..998676f4 100644 --- a/tests/unit/resources/accounts/test_account_users.py +++ b/tests/unit/resources/accounts/test_account_users.py @@ -25,7 +25,9 @@ def async_account_users_service(http_client): ["get", "create", "accept_invite", "resend_invite", "send_new_invite"], ) def test_methods_present(account_users_service, method): - assert hasattr(account_users_service, method) + result = hasattr(account_users_service, method) + + assert result is True @pytest.mark.parametrize( @@ -33,7 +35,9 @@ def test_methods_present(account_users_service, method): ["get", "create", "accept_invite", "resend_invite", "send_new_invite"], ) def test_async_methods_present(async_account_users_service, method): - assert hasattr(async_account_users_service, method) + result = hasattr(async_account_users_service, method) + + assert result is True @pytest.mark.parametrize( @@ -43,10 +47,10 @@ def test_async_methods_present(async_account_users_service, method): ], ) def test_property_services(account_users_service, service_method, expected_service_class): - service = getattr(account_users_service, service_method)("ACC-0000-0001") + result = getattr(account_users_service, service_method)("ACC-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"account_user_id": "ACC-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"account_user_id": "ACC-0000-0001"} @pytest.mark.parametrize( @@ -58,7 +62,7 @@ def test_property_services(account_users_service, service_method, expected_servi def test_async_property_services( async_account_users_service, service_method, expected_service_class ): - service = getattr(async_account_users_service, service_method)("ACC-0000-0001") + result = getattr(async_account_users_service, service_method)("ACC-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"account_user_id": "ACC-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"account_user_id": "ACC-0000-0001"} diff --git a/tests/unit/resources/accounts/test_accounts.py b/tests/unit/resources/accounts/test_accounts.py index d935bab5..03148bfe 100644 --- a/tests/unit/resources/accounts/test_accounts.py +++ b/tests/unit/resources/accounts/test_accounts.py @@ -53,11 +53,10 @@ def async_accounts(async_http_client): ], ) def test_accounts_properties(accounts, property_name, expected_service_class): - """Test that Accounts properties return correct instances.""" - service = getattr(accounts, property_name) + result = getattr(accounts, property_name) - assert isinstance(service, expected_service_class) - assert service.http_client is accounts.http_client + assert isinstance(result, expected_service_class) + assert result.http_client is accounts.http_client @pytest.mark.parametrize( @@ -77,22 +76,21 @@ def test_accounts_properties(accounts, property_name, expected_service_class): ], ) def test_async_accounts_properties(async_accounts, property_name, expected_service_class): - """Test that AsyncAccounts properties return correct instances.""" - service = getattr(async_accounts, property_name) + result = getattr(async_accounts, property_name) - assert isinstance(service, expected_service_class) - assert service.http_client is async_accounts.http_client + assert isinstance(result, expected_service_class) + assert result.http_client is async_accounts.http_client def test_accounts_initialization(http_client): - accounts = Accounts(http_client=http_client) + result = Accounts(http_client=http_client) - assert accounts.http_client is http_client - assert isinstance(accounts, Accounts) + assert result.http_client is http_client + assert isinstance(result, Accounts) def test_async_accounts_initialization(async_http_client): - accounts = AsyncAccounts(http_client=async_http_client) + result = AsyncAccounts(http_client=async_http_client) - assert accounts.http_client is async_http_client - assert isinstance(accounts, AsyncAccounts) + assert result.http_client is async_http_client + assert isinstance(result, AsyncAccounts) diff --git a/tests/unit/resources/accounts/test_accounts_user_groups.py b/tests/unit/resources/accounts/test_accounts_user_groups.py index c13e85ed..5537eb9d 100644 --- a/tests/unit/resources/accounts/test_accounts_user_groups.py +++ b/tests/unit/resources/accounts/test_accounts_user_groups.py @@ -23,25 +23,31 @@ def async_accounts_user_groups_service(async_http_client): def test_endpoint(accounts_user_groups_service): - assert ( + result = ( accounts_user_groups_service.path == "/public/v1/accounts/ACC-0000-0001/users/USR-0000-0001/groups" ) + assert result is True + def test_async_endpoint(async_accounts_user_groups_service): - assert ( + result = ( async_accounts_user_groups_service.path == "/public/v1/accounts/ACC-0000-0001/users/USR-0000-0001/groups" ) + assert result is True + @pytest.mark.parametrize( "method", ["create", "update", "delete"], ) def test_mixins_present(accounts_user_groups_service, method): - assert hasattr(accounts_user_groups_service, method) + result = hasattr(accounts_user_groups_service, method) + + assert result is True @pytest.mark.parametrize( @@ -49,4 +55,6 @@ def test_mixins_present(accounts_user_groups_service, method): ["create", "update", "delete"], ) def test_async_mixins_present(async_accounts_user_groups_service, method): - assert hasattr(async_accounts_user_groups_service, method) + result = hasattr(async_accounts_user_groups_service, method) + + assert result is True diff --git a/tests/unit/resources/accounts/test_accounts_users.py b/tests/unit/resources/accounts/test_accounts_users.py index 0a78ba12..7a604139 100644 --- a/tests/unit/resources/accounts/test_accounts_users.py +++ b/tests/unit/resources/accounts/test_accounts_users.py @@ -25,11 +25,15 @@ def async_accounts_users_service(async_http_client): def test_endpoint(accounts_users_service): - assert accounts_users_service.path == "/public/v1/accounts/ACC-0000-0001/users" + result = accounts_users_service.path == "/public/v1/accounts/ACC-0000-0001/users" + + assert result is True def test_async_endpoint(async_accounts_users_service): - assert async_accounts_users_service.path == "/public/v1/accounts/ACC-0000-0001/users" + result = async_accounts_users_service.path == "/public/v1/accounts/ACC-0000-0001/users" + + assert result is True @pytest.mark.parametrize( @@ -37,7 +41,9 @@ def test_async_endpoint(async_accounts_users_service): ["get", "create", "update", "accept_invite", "resend_invite", "send_new_invite"], ) def test_methods_present(accounts_users_service, method): - assert hasattr(accounts_users_service, method) + result = hasattr(accounts_users_service, method) + + assert result is True @pytest.mark.parametrize( @@ -45,7 +51,9 @@ def test_methods_present(accounts_users_service, method): ["get", "create", "update", "accept_invite", "resend_invite", "send_new_invite"], ) def test_async_methods_present(async_accounts_users_service, method): - assert hasattr(async_accounts_users_service, method) + result = hasattr(async_accounts_users_service, method) + + assert result is True @pytest.mark.parametrize( @@ -53,10 +61,10 @@ def test_async_methods_present(async_accounts_users_service, method): [("groups", AccountsUserGroupsService)], ) def test_property_services(accounts_users_service, service_method, expected_service_class): - service = getattr(accounts_users_service, service_method)("USR-0000-0001") + result = getattr(accounts_users_service, service_method)("USR-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == { + assert isinstance(result, expected_service_class) + assert result.endpoint_params == { "account_id": "ACC-0000-0001", "user_id": "USR-0000-0001", } @@ -69,10 +77,10 @@ def test_property_services(accounts_users_service, service_method, expected_serv def test_async_property_services( async_accounts_users_service, service_method, expected_service_class ): - service = getattr(async_accounts_users_service, service_method)("USR-0000-0001") + result = getattr(async_accounts_users_service, service_method)("USR-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == { + assert isinstance(result, expected_service_class) + assert result.endpoint_params == { "account_id": "ACC-0000-0001", "user_id": "USR-0000-0001", } diff --git a/tests/unit/resources/accounts/test_api_tokens.py b/tests/unit/resources/accounts/test_api_tokens.py index 039de324..68904d08 100644 --- a/tests/unit/resources/accounts/test_api_tokens.py +++ b/tests/unit/resources/accounts/test_api_tokens.py @@ -21,7 +21,9 @@ def async_api_tokens_service(async_http_client): ["get", "create", "update", "delete", "enable", "disable"], ) def test_api_tokens_mixins_present(api_tokens_service, method): - assert hasattr(api_tokens_service, method) + result = hasattr(api_tokens_service, method) + + assert result is True @pytest.mark.parametrize( @@ -29,4 +31,6 @@ def test_api_tokens_mixins_present(api_tokens_service, method): ["get", "create", "update", "delete", "enable", "disable"], ) def test_async_api_tokens_mixins_present(async_api_tokens_service, method): - assert hasattr(async_api_tokens_service, method) + result = hasattr(async_api_tokens_service, method) + + assert result is True diff --git a/tests/unit/resources/accounts/test_buyers.py b/tests/unit/resources/accounts/test_buyers.py index a05dc723..e6fe8952 100644 --- a/tests/unit/resources/accounts/test_buyers.py +++ b/tests/unit/resources/accounts/test_buyers.py @@ -32,7 +32,9 @@ def async_buyers_service(async_http_client): ], ) def test_mixins_present(buyers_service, method): - assert hasattr(buyers_service, method) + result = hasattr(buyers_service, method) + + assert result is True @pytest.mark.parametrize( @@ -52,7 +54,9 @@ def test_mixins_present(buyers_service, method): ], ) def test_async_mixins_present(async_buyers_service, method): - assert hasattr(async_buyers_service, method) + result = hasattr(async_buyers_service, method) + + assert result is True @pytest.mark.parametrize( @@ -74,13 +78,13 @@ def test_buyers_resource_action(buyers_service, action, input_status): json=response_expected_data, ) ) - buyers_obj = getattr(buyers_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = getattr(buyers_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert buyers_obj.to_dict() == response_expected_data - assert isinstance(buyers_obj, Buyer) + assert result.to_dict() == response_expected_data + assert isinstance(result, Buyer) @pytest.mark.parametrize( @@ -99,13 +103,13 @@ def test_buyers_resouce_action_no_data(buyers_service, action, input_status): json=response_expected_data, ) ) - buyers_obj = getattr(buyers_service, action)("OBJ-0000-0001", None) - request = mock_route.calls[0].request + result = getattr(buyers_service, action)("OBJ-0000-0001", None) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert buyers_obj.to_dict() == response_expected_data - assert isinstance(buyers_obj, Buyer) + assert result.to_dict() == response_expected_data + assert isinstance(result, Buyer) @pytest.mark.parametrize( @@ -127,13 +131,13 @@ async def test_async_buyers_resource_action(async_buyers_service, action, input_ json=response_expected_data, ) ) - buyers_obj = await getattr(async_buyers_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = await getattr(async_buyers_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert buyers_obj.to_dict() == response_expected_data - assert isinstance(buyers_obj, Buyer) + assert result.to_dict() == response_expected_data + assert isinstance(result, Buyer) @pytest.mark.parametrize( @@ -152,13 +156,13 @@ async def test_async_buyers_resource_action_no_data(async_buyers_service, action json=response_expected_data, ) ) - buyers_obj = await getattr(async_buyers_service, action)("OBJ-0000-0001", None) - request = mock_route.calls[0].request + result = await getattr(async_buyers_service, action)("OBJ-0000-0001", None) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert buyers_obj.to_dict() == response_expected_data - assert isinstance(buyers_obj, Buyer) + assert result.to_dict() == response_expected_data + assert isinstance(result, Buyer) def test_buyers_create(buyers_service, tmp_path): # noqa: WPS210 @@ -166,23 +170,20 @@ def test_buyers_create(buyers_service, tmp_path): # noqa: WPS210 "id": "BUY-0000-0001", "name": "Test Buyer", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.post(buyers_service.path).mock( return_value=httpx.Response(httpx.codes.CREATED, json=buyer_data) ) - buyer = buyers_service.create(buyer_data, logo=logo_file) + result = buyers_service.create(buyer_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "POST" assert request.url.path == "/public/v1/accounts/buyers" - assert buyer.to_dict() == buyer_data + assert result.to_dict() == buyer_data def test_buyers_update(buyers_service, tmp_path): # noqa: WPS210 @@ -190,23 +191,20 @@ def test_buyers_update(buyers_service, tmp_path): # noqa: WPS210 buyer_data = { "name": "Updated Test Buyer", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.put(f"{buyers_service.path}/{buyer_id}").mock( return_value=httpx.Response(httpx.codes.OK, json={"id": buyer_id, **buyer_data}) ) - buyer = buyers_service.update(buyer_id, buyer_data, logo=logo_file) + result = buyers_service.update(buyer_id, buyer_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "PUT" assert request.url.path == f"/public/v1/accounts/buyers/{buyer_id}" - assert buyer.to_dict() == {"id": buyer_id, **buyer_data} + assert result.to_dict() == {"id": buyer_id, **buyer_data} async def test_async_buyers_create(async_buyers_service, tmp_path): # noqa: WPS210 @@ -214,23 +212,20 @@ async def test_async_buyers_create(async_buyers_service, tmp_path): # noqa: WPS "id": "BUY-0000-0001", "name": "Test Buyer", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.post(async_buyers_service.path).mock( return_value=httpx.Response(httpx.codes.CREATED, json=buyer_data) ) - buyer = await async_buyers_service.create(buyer_data, logo=logo_file) + result = await async_buyers_service.create(buyer_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "POST" assert request.url.path == "/public/v1/accounts/buyers" - assert buyer.to_dict() == buyer_data + assert result.to_dict() == buyer_data async def test_async_buyers_update(async_buyers_service, tmp_path): # noqa: WPS210 @@ -238,7 +233,6 @@ async def test_async_buyers_update(async_buyers_service, tmp_path): # noqa: WPS buyer_data = { "name": "Updated Test Buyer", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") @@ -247,11 +241,10 @@ async def test_async_buyers_update(async_buyers_service, tmp_path): # noqa: WPS return_value=httpx.Response(httpx.codes.OK, json={"id": buyer_id, **buyer_data}) ) - buyer = await async_buyers_service.update(buyer_id, buyer_data, logo=logo_file) + result = await async_buyers_service.update(buyer_id, buyer_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "PUT" assert request.url.path == f"/public/v1/accounts/buyers/{buyer_id}" - assert buyer.to_dict() == {"id": buyer_id, **buyer_data} + assert result.to_dict() == {"id": buyer_id, **buyer_data} diff --git a/tests/unit/resources/accounts/test_cloud_tenants.py b/tests/unit/resources/accounts/test_cloud_tenants.py index a9847174..72812a28 100644 --- a/tests/unit/resources/accounts/test_cloud_tenants.py +++ b/tests/unit/resources/accounts/test_cloud_tenants.py @@ -21,7 +21,9 @@ def async_cloud_tenants_service(async_http_client): ["get", "create", "update", "delete"], ) def test_cloud_tenants_mixins_present(cloud_tenants_service, method): - assert hasattr(cloud_tenants_service, method) + result = hasattr(cloud_tenants_service, method) + + assert result is True @pytest.mark.parametrize( @@ -29,4 +31,6 @@ def test_cloud_tenants_mixins_present(cloud_tenants_service, method): ["get", "create", "update", "delete"], ) def test_async_cloud_tenants_mixins_present(async_cloud_tenants_service, method): - assert hasattr(async_cloud_tenants_service, method) + result = hasattr(async_cloud_tenants_service, method) + + assert result is True diff --git a/tests/unit/resources/accounts/test_erp_links.py b/tests/unit/resources/accounts/test_erp_links.py index 658f9557..1567650f 100644 --- a/tests/unit/resources/accounts/test_erp_links.py +++ b/tests/unit/resources/accounts/test_erp_links.py @@ -18,7 +18,9 @@ def async_erp_links_service(async_http_client): ["get", "create", "update", "block", "unblock"], ) def test_mixins_present(erp_links_service, method): - assert hasattr(erp_links_service, method) + result = hasattr(erp_links_service, method) + + assert result is True @pytest.mark.parametrize( @@ -26,4 +28,6 @@ def test_mixins_present(erp_links_service, method): ["get", "create", "update", "block", "unblock"], ) def test_async_mixins_present(async_erp_links_service, method): - assert hasattr(async_erp_links_service, method) + result = hasattr(async_erp_links_service, method) + + assert result is True diff --git a/tests/unit/resources/accounts/test_licensees.py b/tests/unit/resources/accounts/test_licensees.py index 1a5574bb..b067daab 100644 --- a/tests/unit/resources/accounts/test_licensees.py +++ b/tests/unit/resources/accounts/test_licensees.py @@ -20,7 +20,9 @@ def async_licensees_service(async_http_client): ["get", "create", "delete", "update", "enable", "disable"], ) def test_licensees_mixins_present(licensees_service, method): - assert hasattr(licensees_service, method) + result = hasattr(licensees_service, method) + + assert result is True @pytest.mark.parametrize( @@ -28,7 +30,9 @@ def test_licensees_mixins_present(licensees_service, method): ["get", "create", "delete", "update", "enable", "disable"], ) def test_async_licensees_mixins_present(async_licensees_service, method): - assert hasattr(async_licensees_service, method) + result = hasattr(async_licensees_service, method) + + assert result is True def test_create_licensee(licensees_service, tmp_path): # noqa: WPS210 @@ -36,23 +40,20 @@ def test_create_licensee(licensees_service, tmp_path): # noqa: WPS210 "id": "LIC-0000-0001", "name": "Test E2E Licensee", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.post(licensees_service.path).mock( return_value=httpx.Response(httpx.codes.CREATED, json=licensee_data) ) - licensee = licensees_service.create(licensee_data, logo=logo_file) + result = licensees_service.create(licensee_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "POST" assert request.url.path == "/public/v1/accounts/licensees" - assert licensee.to_dict() == licensee_data + assert result.to_dict() == licensee_data def test_update_licensees(licensees_service, tmp_path): # noqa: WPS210 @@ -60,23 +61,20 @@ def test_update_licensees(licensees_service, tmp_path): # noqa: WPS210 licensee_data = { "name": "Updated Test licensee", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.put(f"{licensees_service.path}/{licensee_id}").mock( return_value=httpx.Response(httpx.codes.OK, json={"id": licensee_id, **licensee_data}) ) - licensee = licensees_service.update(licensee_id, licensee_data, logo=logo_file) + result = licensees_service.update(licensee_id, licensee_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "PUT" assert request.url.path == f"/public/v1/accounts/licensees/{licensee_id}" - assert licensee.to_dict() == {"id": licensee_id, **licensee_data} + assert result.to_dict() == {"id": licensee_id, **licensee_data} async def test_async_create_licensees(async_licensees_service, tmp_path): # noqa: WPS210 @@ -84,10 +82,8 @@ async def test_async_create_licensees(async_licensees_service, tmp_path): # noq "id": "BUY-0000-0001", "name": "Test licensee", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.post(async_licensees_service.path).mock( return_value=httpx.Response(httpx.codes.CREATED, json=licensee_data) @@ -96,7 +92,6 @@ async def test_async_create_licensees(async_licensees_service, tmp_path): # noq licensee = await async_licensees_service.create(licensee_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "POST" assert request.url.path == "/public/v1/accounts/licensees" @@ -108,10 +103,8 @@ async def test_async_update_licensees(async_licensees_service, tmp_path): # noq licensee_data = { "name": "Updated Test licensee", } - logo_path = tmp_path / "logo.png" logo_path.write_bytes(b"fake-logo-data") - with logo_path.open("rb") as logo_file, respx.mock: mock_route = respx.put(f"{async_licensees_service.path}/{licensee_id}").mock( return_value=httpx.Response(httpx.codes.OK, json={"id": licensee_id, **licensee_data}) @@ -120,7 +113,6 @@ async def test_async_update_licensees(async_licensees_service, tmp_path): # noq licensee = await async_licensees_service.update(licensee_id, licensee_data, logo=logo_file) request = mock_route.calls[0].request - assert mock_route.call_count == 1 assert request.method == "PUT" assert request.url.path == f"/public/v1/accounts/licensees/{licensee_id}" diff --git a/tests/unit/resources/accounts/test_mixins.py b/tests/unit/resources/accounts/test_mixins.py index d3c07946..eeabb6c7 100644 --- a/tests/unit/resources/accounts/test_mixins.py +++ b/tests/unit/resources/accounts/test_mixins.py @@ -178,14 +178,14 @@ def test_activatable_resource_actions(activatable_service, action, input_status) json=response_expected_data, ) ) - activatable_obj = getattr(activatable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(activatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert activatable_obj.to_dict() == response_expected_data - assert isinstance(activatable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -208,14 +208,14 @@ def test_activatable_resource_actions_no_data(activatable_service, action, input json=response_expected_data, ) ) - activatable_obj = getattr(activatable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(activatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert activatable_obj.to_dict() == response_expected_data - assert isinstance(activatable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -238,16 +238,14 @@ async def test_async_activatable_resource_actions(async_activatable_service, act json=response_expected_data, ) ) - activatable_obj = await getattr(async_activatable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_activatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert activatable_obj.to_dict() == response_expected_data - assert isinstance(activatable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -272,16 +270,14 @@ async def test_async_activatable_resource_actions_no_data( json=response_expected_data, ) ) - activatable_obj = await getattr(async_activatable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_activatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert activatable_obj.to_dict() == response_expected_data - assert isinstance(activatable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -304,14 +300,14 @@ def test_enablable_resource_actions(enablable_service, action, input_status): json=response_expected_data, ) ) - enablable_obj = getattr(enablable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(enablable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert enablable_obj.to_dict() == response_expected_data - assert isinstance(enablable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -334,14 +330,14 @@ def test_enablable_resource_actions_no_data(enablable_service, action, input_sta json=response_expected_data, ) ) - enablable_obj = getattr(enablable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(enablable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert enablable_obj.to_dict() == response_expected_data - assert isinstance(enablable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -364,16 +360,14 @@ async def test_async_enablable_resource_actions(async_enablable_service, action, json=response_expected_data, ) ) - enablable_obj = await getattr(async_enablable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_enablable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert enablable_obj.to_dict() == response_expected_data - assert isinstance(enablable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -398,16 +392,14 @@ async def test_async_enablable_resource_actions_no_data( json=response_expected_data, ) ) - enablable_obj = await getattr(async_enablable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_enablable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert enablable_obj.to_dict() == response_expected_data - assert isinstance(enablable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -426,14 +418,14 @@ def test_validate_resource_actions(validate_service, action, input_status): json=response_expected_data, ) ) - validate_obj = getattr(validate_service, action)("OBJ-0000-0001", input_status) + + result = getattr(validate_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert validate_obj.to_dict() == response_expected_data - assert isinstance(validate_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize(("action", "input_status"), [("validate", None)]) @@ -450,14 +442,14 @@ def test_validate_resource_actions_no_data(validate_service, action, input_statu json=response_expected_data, ) ) - validate_obj = getattr(validate_service, action)("OBJ-0000-0001", input_status) + + result = getattr(validate_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert validate_obj.to_dict() == response_expected_data - assert isinstance(validate_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -476,14 +468,14 @@ async def test_async_validate_resource_actions(async_validate_service, action, i json=response_expected_data, ) ) - validate_obj = await getattr(async_validate_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_validate_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert validate_obj.to_dict() == response_expected_data - assert isinstance(validate_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize(("action", "input_status"), [("validate", None)]) @@ -502,14 +494,14 @@ async def test_async_validate_resource_actions_no_data( json=response_expected_data, ) ) - validate_obj = await getattr(async_validate_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_validate_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert validate_obj.to_dict() == response_expected_data - assert isinstance(validate_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -532,14 +524,14 @@ def test_blockable_resource_actions(blockable_service, action, input_status): json=response_expected_data, ) ) - blockable_obj = getattr(blockable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(blockable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -562,14 +554,14 @@ def test_blockable_resource_actions_no_data(blockable_service, action, input_sta json=response_expected_data, ) ) - blockable_obj = getattr(blockable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(blockable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -592,16 +584,14 @@ async def test_async_blockable_resource_actions(async_blockable_service, action, json=response_expected_data, ) ) - blockable_obj = await getattr(async_blockable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_blockable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -626,16 +616,14 @@ async def test_async_blockable_resource_actions_no_data( json=response_expected_data, ) ) - blockable_obj = await getattr(async_blockable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_blockable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -660,14 +648,14 @@ def test_invitable_resource_actions(invitable_service, action, input_status): json=response_expected_data, ) ) - invitable_obj = getattr(invitable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(invitable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert invitable_obj.to_dict() == response_expected_data - assert isinstance(invitable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -692,14 +680,14 @@ def test_invitable_resource_actions_no_data(invitable_service, action, input_sta json=response_expected_data, ) ) - invitable_obj = getattr(invitable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(invitable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert invitable_obj.to_dict() == response_expected_data - assert isinstance(invitable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -724,16 +712,15 @@ async def test_async_invitable_resource_actions(async_invitable_service, action, json=response_expected_data, ) ) - invitable_obj = await getattr(async_invitable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_invitable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.content == request_expected_content - assert invitable_obj.to_dict() == response_expected_data - assert isinstance(invitable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -760,13 +747,11 @@ async def test_async_invitable_resource_actions_no_data( json=response_expected_data, ) ) - invitable_obj = await getattr(async_invitable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_invitable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert invitable_obj.to_dict() == response_expected_data - assert isinstance(invitable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) diff --git a/tests/unit/resources/accounts/test_modules.py b/tests/unit/resources/accounts/test_modules.py index dd36ff11..e77c052e 100644 --- a/tests/unit/resources/accounts/test_modules.py +++ b/tests/unit/resources/accounts/test_modules.py @@ -15,9 +15,13 @@ def async_module_service(http_client): @pytest.mark.parametrize("method", ["get"]) def test_modules_mixins_present(module_service, method): - assert hasattr(module_service, method) + result = hasattr(module_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get"]) def test_async_modules_mixins_present(async_module_service, method): - assert hasattr(async_module_service, method) + result = hasattr(async_module_service, method) + + assert result is True diff --git a/tests/unit/resources/accounts/test_sellers.py b/tests/unit/resources/accounts/test_sellers.py index 42e3ab92..a7ad4c05 100644 --- a/tests/unit/resources/accounts/test_sellers.py +++ b/tests/unit/resources/accounts/test_sellers.py @@ -20,7 +20,9 @@ def async_sellers_service(async_http_client): ["get", "create", "update", "delete", "activate", "deactivate", "disable"], ) def test_mixins_present(sellers_service, method): - assert hasattr(sellers_service, method) + result = hasattr(sellers_service, method) + + assert result is True @pytest.mark.parametrize( @@ -28,7 +30,9 @@ def test_mixins_present(sellers_service, method): ["get", "create", "update", "delete", "activate", "deactivate", "disable"], ) def test_async_mixins_present(async_sellers_service, method): - assert hasattr(async_sellers_service, method) + result = hasattr(async_sellers_service, method) + + assert result is True @pytest.mark.parametrize( @@ -46,13 +50,13 @@ def test_sellers_resource_action(sellers_service, action, input_status): json=response_expected_data, ) ) - sellers_obj = getattr(sellers_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = getattr(sellers_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert sellers_obj.to_dict() == response_expected_data - assert isinstance(sellers_obj, Seller) + assert result.to_dict() == response_expected_data + assert isinstance(result, Seller) @pytest.mark.parametrize(("action", "input_status"), [("disable", None)]) @@ -68,13 +72,13 @@ def test_sellers_resource_action_no_data(sellers_service, action, input_status): json=response_expected_data, ) ) - sellers_obj = getattr(sellers_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = getattr(sellers_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert sellers_obj.to_dict() == response_expected_data - assert isinstance(sellers_obj, Seller) + assert result.to_dict() == response_expected_data + assert isinstance(result, Seller) @pytest.mark.parametrize( @@ -92,13 +96,13 @@ async def test_async_sellers_resource_action(async_sellers_service, action, inpu json=response_expected_data, ) ) - sellers_obj = await getattr(async_sellers_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = await getattr(async_sellers_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert sellers_obj.to_dict() == response_expected_data - assert isinstance(sellers_obj, Seller) + assert result.to_dict() == response_expected_data + assert isinstance(result, Seller) @pytest.mark.parametrize(("action", "input_status"), [("disable", None)]) @@ -114,10 +118,10 @@ async def test_async_sellers_resource_action_no_data(async_sellers_service, acti json=response_expected_data, ) ) - sellers_obj = await getattr(async_sellers_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = await getattr(async_sellers_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert sellers_obj.to_dict() == response_expected_data - assert isinstance(sellers_obj, Seller) + assert result.to_dict() == response_expected_data + assert isinstance(result, Seller) diff --git a/tests/unit/resources/accounts/test_user_groups.py b/tests/unit/resources/accounts/test_user_groups.py index a45934e7..8f5fa217 100644 --- a/tests/unit/resources/accounts/test_user_groups.py +++ b/tests/unit/resources/accounts/test_user_groups.py @@ -21,7 +21,9 @@ def async_user_groups_service(http_client): ["get", "create", "update", "delete"], ) def test_mixins_present(user_groups_service, method): - assert hasattr(user_groups_service, method) + result = hasattr(user_groups_service, method) + + assert result is True @pytest.mark.parametrize( @@ -29,4 +31,6 @@ def test_mixins_present(user_groups_service, method): ["get", "create", "update", "delete"], ) def test_async_mixins_present(async_user_groups_service, method): - assert hasattr(async_user_groups_service, method) + result = hasattr(async_user_groups_service, method) + + assert result is True diff --git a/tests/unit/resources/accounts/test_users.py b/tests/unit/resources/accounts/test_users.py index 733960d2..5bdb8c2e 100644 --- a/tests/unit/resources/accounts/test_users.py +++ b/tests/unit/resources/accounts/test_users.py @@ -19,14 +19,18 @@ def async_users_service(async_http_client): "method", ["get", "update", "delete", "block", "unblock", "sso", "sso_check", "set_password"] ) def test_mixins_present(users_service, method): - assert hasattr(users_service, method) + result = hasattr(users_service, method) + + assert result is True @pytest.mark.parametrize( "method", ["get", "update", "delete", "block", "unblock", "sso", "sso_check", "set_password"] ) def test_async_mixins_present(async_users_service, method): - assert hasattr(async_users_service, method) + result = hasattr(async_users_service, method) + + assert result is True @pytest.mark.parametrize( @@ -49,13 +53,13 @@ def test_resource_actions(users_service, action, input_status): json=response_expected_data, ) ) - blockable_obj = getattr(users_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = getattr(users_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, User) + assert result.to_dict() == response_expected_data + assert isinstance(result, User) @pytest.mark.parametrize( @@ -78,13 +82,13 @@ def test_resource_actions_no_data(users_service, action, input_status): json=response_expected_data, ) ) - blockable_obj = getattr(users_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = getattr(users_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, User) + assert result.to_dict() == response_expected_data + assert isinstance(result, User) @pytest.mark.parametrize( @@ -107,13 +111,13 @@ async def test_async_resource_actions(async_users_service, action, input_status) json=response_expected_data, ) ) - blockable_obj = await getattr(async_users_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = await getattr(async_users_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, User) + assert result.to_dict() == response_expected_data + assert isinstance(result, User) @pytest.mark.parametrize( @@ -136,13 +140,13 @@ async def test_async_resource_actions_no_data(async_users_service, action, input json=response_expected_data, ) ) - blockable_obj = await getattr(async_users_service, action)("OBJ-0000-0001", input_status) - request = mock_route.calls[0].request + result = await getattr(async_users_service, action)("OBJ-0000-0001", input_status) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, User) + assert result.to_dict() == response_expected_data + assert isinstance(result, User) @pytest.mark.parametrize( @@ -165,13 +169,13 @@ def test_set_password_action(users_service, action, input_password): json=response_expected_data, ) ) - blockable_obj = getattr(users_service, action)("OBJ-0000-0001", input_password) - request = mock_route.calls[0].request + result = getattr(users_service, action)("OBJ-0000-0001", input_password) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, User) + assert result.to_dict() == response_expected_data + assert isinstance(result, User) @pytest.mark.parametrize( @@ -194,10 +198,10 @@ async def test_async_set_password_action(async_users_service, action, input_pass json=response_expected_data, ) ) - blockable_obj = await getattr(async_users_service, action)("OBJ-0000-0001", input_password) - request = mock_route.calls[0].request + result = await getattr(async_users_service, action)("OBJ-0000-0001", input_password) + request = mock_route.calls[0].request assert request.content == request_expected_content - assert blockable_obj.to_dict() == response_expected_data - assert isinstance(blockable_obj, User) + assert result.to_dict() == response_expected_data + assert isinstance(result, User) diff --git a/tests/unit/resources/audit/test_audit.py b/tests/unit/resources/audit/test_audit.py index 58d37723..6f9c63c4 100644 --- a/tests/unit/resources/audit/test_audit.py +++ b/tests/unit/resources/audit/test_audit.py @@ -23,11 +23,10 @@ def async_audit(async_http_client): ], ) def test_audit_properties(audit, property_name, expected_service_class): - """Test that Audit properties return correct instances.""" - service = getattr(audit, property_name) + result = getattr(audit, property_name) - assert isinstance(service, expected_service_class) - assert service.http_client is audit.http_client + assert isinstance(result, expected_service_class) + assert result.http_client is audit.http_client @pytest.mark.parametrize( @@ -38,22 +37,21 @@ def test_audit_properties(audit, property_name, expected_service_class): ], ) def test_async_audit_properties(async_audit, property_name, expected_service_class): - """Test that AsyncAudit properties return correct instances.""" - service = getattr(async_audit, property_name) + result = getattr(async_audit, property_name) - assert isinstance(service, expected_service_class) - assert service.http_client is async_audit.http_client + assert isinstance(result, expected_service_class) + assert result.http_client is async_audit.http_client def test_audit_initialization(http_client): - audit = Audit(http_client=http_client) + result = Audit(http_client=http_client) - assert audit.http_client is http_client - assert isinstance(audit, Audit) + assert result.http_client is http_client + assert isinstance(result, Audit) def test_async_audit_initialization(async_http_client): - async_audit = AsyncAudit(http_client=async_http_client) + result = AsyncAudit(http_client=async_http_client) - assert async_audit.http_client is async_http_client - assert isinstance(async_audit, AsyncAudit) + assert result.http_client is async_http_client + assert isinstance(result, AsyncAudit) diff --git a/tests/unit/resources/audit/test_event_types.py b/tests/unit/resources/audit/test_event_types.py index 1bb5bc1d..e01a3e49 100644 --- a/tests/unit/resources/audit/test_event_types.py +++ b/tests/unit/resources/audit/test_event_types.py @@ -15,9 +15,13 @@ def async_event_types_service(async_http_client): @pytest.mark.parametrize("method", ["get", "update"]) def test_mixins_present(event_types_service, method): - assert hasattr(event_types_service, method) + result = hasattr(event_types_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "update"]) def test_async_mixins_present(async_event_types_service, method): - assert hasattr(async_event_types_service, method) + result = hasattr(async_event_types_service, method) + + assert result is True diff --git a/tests/unit/resources/audit/test_records.py b/tests/unit/resources/audit/test_records.py index f820a26f..14c3c4a9 100644 --- a/tests/unit/resources/audit/test_records.py +++ b/tests/unit/resources/audit/test_records.py @@ -15,9 +15,13 @@ def async_records_service(async_http_client): @pytest.mark.parametrize("method", ["get", "create"]) def test_mixins_present(records_service, method): - assert hasattr(records_service, method) + result = hasattr(records_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create"]) def test_async_mixins_present(async_records_service, method): - assert hasattr(async_records_service, method) + result = hasattr(async_records_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_billing.py b/tests/unit/resources/billing/test_billing.py index 798580d7..b008d60d 100644 --- a/tests/unit/resources/billing/test_billing.py +++ b/tests/unit/resources/billing/test_billing.py @@ -42,11 +42,10 @@ def async_billing(async_http_client): ], ) def test_billing_properties(billing, property_name, expected_service_class): - """Test that Billing properties return correct instances.""" - service = getattr(billing, property_name) + result = getattr(billing, property_name) - assert isinstance(service, expected_service_class) - assert service.http_client is billing.http_client + assert isinstance(result, expected_service_class) + assert result.http_client is billing.http_client @pytest.mark.parametrize( @@ -62,22 +61,21 @@ def test_billing_properties(billing, property_name, expected_service_class): ], ) def test_async_billing_properties(async_billing, property_name, expected_service_class): - """Test that AsyncBilling properties return correct instances.""" - service = getattr(async_billing, property_name) + result = getattr(async_billing, property_name) - assert isinstance(service, expected_service_class) - assert service.http_client is async_billing.http_client + assert isinstance(result, expected_service_class) + assert result.http_client is async_billing.http_client def test_billing_initialization(http_client): - billing = Billing(http_client=http_client) + result = Billing(http_client=http_client) - assert billing.http_client is http_client - assert isinstance(billing, Billing) + assert result.http_client is http_client + assert isinstance(result, Billing) def test_async_billing_initialization(async_http_client): - async_billing = AsyncBilling(http_client=async_http_client) + result = AsyncBilling(http_client=async_http_client) - assert async_billing.http_client is async_http_client - assert isinstance(async_billing, AsyncBilling) + assert result.http_client is async_http_client + assert isinstance(result, AsyncBilling) diff --git a/tests/unit/resources/billing/test_credit_memo_attachments.py b/tests/unit/resources/billing/test_credit_memo_attachments.py index 063288bf..4c83f7cc 100644 --- a/tests/unit/resources/billing/test_credit_memo_attachments.py +++ b/tests/unit/resources/billing/test_credit_memo_attachments.py @@ -21,24 +21,32 @@ def async_credit_memo_attachments_service(async_http_client): def test_endpoint(credit_memo_attachments_service): - assert ( + result = ( credit_memo_attachments_service.path == "/public/v1/billing/credit-memos/CRM-0000-0001/attachments" ) + assert result is True + def test_async_endpoint(async_credit_memo_attachments_service): - assert ( + result = ( async_credit_memo_attachments_service.path == "/public/v1/billing/credit-memos/CRM-0000-0001/attachments" ) + assert result is True + @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_methods_present(credit_memo_attachments_service, method: str): - assert hasattr(credit_memo_attachments_service, method) + result = hasattr(credit_memo_attachments_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_methods_present(async_credit_memo_attachments_service, method: str): - assert hasattr(async_credit_memo_attachments_service, method) + result = hasattr(async_credit_memo_attachments_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_credit_memos.py b/tests/unit/resources/billing/test_credit_memos.py index b67b8766..a41a912d 100644 --- a/tests/unit/resources/billing/test_credit_memos.py +++ b/tests/unit/resources/billing/test_credit_memos.py @@ -25,7 +25,9 @@ def async_credit_memos_service(async_http_client): ["get", "create", "update"], ) def test_mixins_present(credit_memos_service, method): - assert hasattr(credit_memos_service, method) + result = hasattr(credit_memos_service, method) + + assert result is True @pytest.mark.parametrize( @@ -33,7 +35,9 @@ def test_mixins_present(credit_memos_service, method): ["get", "create", "update"], ) def test_async_mixins_present(async_credit_memos_service, method): - assert hasattr(async_credit_memos_service, method) + result = hasattr(async_credit_memos_service, method) + + assert result is True @pytest.mark.parametrize( @@ -43,10 +47,10 @@ def test_async_mixins_present(async_credit_memos_service, method): ], ) def test_property_services(credit_memos_service, service_method, expected_service_class): - service = getattr(credit_memos_service, service_method)("CRM-0000-0001") + result = getattr(credit_memos_service, service_method)("CRM-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"credit_memo_id": "CRM-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"credit_memo_id": "CRM-0000-0001"} @pytest.mark.parametrize( @@ -58,7 +62,7 @@ def test_property_services(credit_memos_service, service_method, expected_servic def test_async_property_services( async_credit_memos_service, service_method, expected_service_class ): - service = getattr(async_credit_memos_service, service_method)("CRM-0000-0001") + result = getattr(async_credit_memos_service, service_method)("CRM-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"credit_memo_id": "CRM-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"credit_memo_id": "CRM-0000-0001"} diff --git a/tests/unit/resources/billing/test_custom_ledger_attachments.py b/tests/unit/resources/billing/test_custom_ledger_attachments.py index b6fbba6d..ff30dadc 100644 --- a/tests/unit/resources/billing/test_custom_ledger_attachments.py +++ b/tests/unit/resources/billing/test_custom_ledger_attachments.py @@ -21,22 +21,30 @@ def async_custom_ledger_attachments_service(async_http_client): def test_endpoint(custom_ledger_attachments_service): - assert custom_ledger_attachments_service.path == ( + result = custom_ledger_attachments_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/attachments" ) + assert result is True + def test_async_endpoint(async_custom_ledger_attachments_service): - assert async_custom_ledger_attachments_service.path == ( + result = async_custom_ledger_attachments_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/attachments" ) + assert result is True + @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_methods_present(custom_ledger_attachments_service, method: str): - assert hasattr(custom_ledger_attachments_service, method) + result = hasattr(custom_ledger_attachments_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_methods_present(async_custom_ledger_attachments_service, method: str): - assert hasattr(async_custom_ledger_attachments_service, method) + result = hasattr(async_custom_ledger_attachments_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_custom_ledger_charges.py b/tests/unit/resources/billing/test_custom_ledger_charges.py index 626a09f2..27fd28fd 100644 --- a/tests/unit/resources/billing/test_custom_ledger_charges.py +++ b/tests/unit/resources/billing/test_custom_ledger_charges.py @@ -21,22 +21,30 @@ def async_custom_ledger_charges_service(async_http_client): def test_endpoint(custom_ledger_charges_service): - assert custom_ledger_charges_service.path == ( + result = custom_ledger_charges_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/charges" ) + assert result is True + def test_async_endpoint(async_custom_ledger_charges_service): - assert async_custom_ledger_charges_service.path == ( + result = async_custom_ledger_charges_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/charges" ) + assert result is True + @pytest.mark.parametrize("method", ["get"]) def test_methods_present(custom_ledger_charges_service, method): - assert hasattr(custom_ledger_charges_service, method) + result = hasattr(custom_ledger_charges_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get"]) def test_async_methods_present(async_custom_ledger_charges_service, method): - assert hasattr(async_custom_ledger_charges_service, method) + result = hasattr(async_custom_ledger_charges_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_custom_ledger_upload.py b/tests/unit/resources/billing/test_custom_ledger_upload.py index dacce499..9d0a7255 100644 --- a/tests/unit/resources/billing/test_custom_ledger_upload.py +++ b/tests/unit/resources/billing/test_custom_ledger_upload.py @@ -21,22 +21,30 @@ def async_custom_ledger_upload_service(http_client): def test_endpoint(custom_ledger_upload_service): - assert custom_ledger_upload_service.path == ( + result = custom_ledger_upload_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/upload" ) + assert result is True + def test_async_endpoint(async_custom_ledger_upload_service): - assert async_custom_ledger_upload_service.path == ( + result = async_custom_ledger_upload_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/upload" ) + assert result is True + @pytest.mark.parametrize("method", ["create"]) def test_mixins_present(custom_ledger_upload_service, method): - assert hasattr(custom_ledger_upload_service, method) + result = hasattr(custom_ledger_upload_service, method) + + assert result is True @pytest.mark.parametrize("method", ["create"]) def test_async_mixins_present(async_custom_ledger_upload_service, method): - assert hasattr(async_custom_ledger_upload_service, method) + result = hasattr(async_custom_ledger_upload_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_custom_ledgers.py b/tests/unit/resources/billing/test_custom_ledgers.py index ba56c772..e44b9443 100644 --- a/tests/unit/resources/billing/test_custom_ledgers.py +++ b/tests/unit/resources/billing/test_custom_ledgers.py @@ -30,12 +30,16 @@ def async_custom_ledgers_service(http_client): @pytest.mark.parametrize("method", ["get", "create", "update", "delete", "accept", "queue"]) def test_mixins_present(custom_ledgers_service, method): - assert hasattr(custom_ledgers_service, method) + result = hasattr(custom_ledgers_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete", "accept", "queue"]) def test_async_mixins_present(async_custom_ledgers_service, method): - assert hasattr(async_custom_ledgers_service, method) + result = hasattr(async_custom_ledgers_service, method) + + assert result is True @pytest.mark.parametrize( @@ -47,10 +51,10 @@ def test_async_mixins_present(async_custom_ledgers_service, method): ], ) def test_property_services(custom_ledgers_service, service_method, expected_service_class): - service = getattr(custom_ledgers_service, service_method)("LDG-0000-0001") + result = getattr(custom_ledgers_service, service_method)("LDG-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"custom_ledger_id": "LDG-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"custom_ledger_id": "LDG-0000-0001"} @pytest.mark.parametrize( @@ -64,7 +68,7 @@ def test_property_services(custom_ledgers_service, service_method, expected_serv def test_async_property_services( async_custom_ledgers_service, service_method, expected_service_class ): - service = getattr(async_custom_ledgers_service, service_method)("LDG-0000-0001") + result = getattr(async_custom_ledgers_service, service_method)("LDG-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"custom_ledger_id": "LDG-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"custom_ledger_id": "LDG-0000-0001"} diff --git a/tests/unit/resources/billing/test_invoice_attachments.py b/tests/unit/resources/billing/test_invoice_attachments.py index 0476b1da..3c0cd1f7 100644 --- a/tests/unit/resources/billing/test_invoice_attachments.py +++ b/tests/unit/resources/billing/test_invoice_attachments.py @@ -21,23 +21,31 @@ def async_invoice_attachments_service(async_http_client): def test_endpoint(invoice_attachments_service): - assert ( + result = ( invoice_attachments_service.path == "/public/v1/billing/invoices/INV-0000-0001/attachments" ) + assert result is True + def test_async_endpoint(async_invoice_attachments_service): - assert ( + result = ( async_invoice_attachments_service.path == "/public/v1/billing/invoices/INV-0000-0001/attachments" ) + assert result is True + @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_methods_present(invoice_attachments_service, method: str): - assert hasattr(invoice_attachments_service, method) + result = hasattr(invoice_attachments_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_methods_present(async_invoice_attachments_service, method: str): - assert hasattr(async_invoice_attachments_service, method) + result = hasattr(async_invoice_attachments_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_invoices.py b/tests/unit/resources/billing/test_invoices.py index 1ffbc8d5..eb78fce1 100644 --- a/tests/unit/resources/billing/test_invoices.py +++ b/tests/unit/resources/billing/test_invoices.py @@ -25,7 +25,9 @@ def async_invoices_service(async_http_client): ["get", "create", "update"], ) def test_methods_present(invoices_service, method): - assert hasattr(invoices_service, method) + result = hasattr(invoices_service, method) + + assert result is True @pytest.mark.parametrize( @@ -33,7 +35,9 @@ def test_methods_present(invoices_service, method): ["get", "create", "update"], ) def test_async_methods_present(async_invoices_service, method): - assert hasattr(async_invoices_service, method) + result = hasattr(async_invoices_service, method) + + assert result is True @pytest.mark.parametrize( @@ -43,10 +47,10 @@ def test_async_methods_present(async_invoices_service, method): ], ) def test_property_services(invoices_service, service_method, expected_service_class): - service = getattr(invoices_service, service_method)("INV-0000-0001") + result = getattr(invoices_service, service_method)("INV-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"invoice_id": "INV-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"invoice_id": "INV-0000-0001"} @pytest.mark.parametrize( @@ -56,7 +60,7 @@ def test_property_services(invoices_service, service_method, expected_service_cl ], ) def test_async_property_services(async_invoices_service, service_method, expected_service_class): - service = getattr(async_invoices_service, service_method)("INV-0000-0001") + result = getattr(async_invoices_service, service_method)("INV-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"invoice_id": "INV-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"invoice_id": "INV-0000-0001"} diff --git a/tests/unit/resources/billing/test_journal_attachments.py b/tests/unit/resources/billing/test_journal_attachments.py index 77811e9b..644afc27 100644 --- a/tests/unit/resources/billing/test_journal_attachments.py +++ b/tests/unit/resources/billing/test_journal_attachments.py @@ -21,23 +21,31 @@ def async_journal_attachments_service(async_http_client) -> AsyncJournalAttachme def test_endpoint(journal_attachments_service) -> None: - assert ( + result = ( journal_attachments_service.path == "/public/v1/billing/journals/JRN-0000-0001/attachments" ) + assert result is True + def test_async_endpoint(async_journal_attachments_service) -> None: - assert ( + result = ( async_journal_attachments_service.path == "/public/v1/billing/journals/JRN-0000-0001/attachments" ) + assert result is True + @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_methods_present(journal_attachments_service, method: str) -> None: - assert hasattr(journal_attachments_service, method) + result = hasattr(journal_attachments_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_methods_present(async_journal_attachments_service, method: str) -> None: - assert hasattr(async_journal_attachments_service, method) + result = hasattr(async_journal_attachments_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_journal_charges.py b/tests/unit/resources/billing/test_journal_charges.py index 5c1194bc..27a3067c 100644 --- a/tests/unit/resources/billing/test_journal_charges.py +++ b/tests/unit/resources/billing/test_journal_charges.py @@ -21,20 +21,28 @@ def async_journal_charges_service(async_http_client): def test_endpoint(journal_charges_service): - assert journal_charges_service.path == "/public/v1/billing/journals/JRN-0000-0001/charges" + result = journal_charges_service.path == "/public/v1/billing/journals/JRN-0000-0001/charges" + + assert result is True def test_async_endpoint(async_journal_charges_service): - assert async_journal_charges_service.path == ( + result = async_journal_charges_service.path == ( "/public/v1/billing/journals/JRN-0000-0001/charges" ) + assert result is True + @pytest.mark.parametrize("method", ["get"]) def test_methods_present(journal_charges_service, method): - assert hasattr(journal_charges_service, method) + result = hasattr(journal_charges_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get"]) def test_async_methods_present(async_journal_charges_service, method): - assert hasattr(async_journal_charges_service, method) + result = hasattr(async_journal_charges_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_journal_sellers.py b/tests/unit/resources/billing/test_journal_sellers.py index 0ea97703..8e5dd0a0 100644 --- a/tests/unit/resources/billing/test_journal_sellers.py +++ b/tests/unit/resources/billing/test_journal_sellers.py @@ -21,18 +21,28 @@ def async_journal_sellers_service(async_http_client): def test_endpoint(journal_sellers_service): - assert journal_sellers_service.path == "/public/v1/billing/journals/JRN-0000-0001/sellers" + result = journal_sellers_service.path == "/public/v1/billing/journals/JRN-0000-0001/sellers" + + assert result is True def test_async_endpoint(async_journal_sellers_service): - assert async_journal_sellers_service.path == "/public/v1/billing/journals/JRN-0000-0001/sellers" + result = ( + async_journal_sellers_service.path == "/public/v1/billing/journals/JRN-0000-0001/sellers" + ) + + assert result is True @pytest.mark.parametrize("method", ["get"]) def test_methods_present(journal_sellers_service, method): - assert hasattr(journal_sellers_service, method) + result = hasattr(journal_sellers_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get"]) def test_async_methods_present(async_journal_sellers_service, method): - assert hasattr(async_journal_sellers_service, method) + result = hasattr(async_journal_sellers_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_journal_upload.py b/tests/unit/resources/billing/test_journal_upload.py index 1c7be840..350d7354 100644 --- a/tests/unit/resources/billing/test_journal_upload.py +++ b/tests/unit/resources/billing/test_journal_upload.py @@ -21,18 +21,26 @@ def async_journal_upload_service(async_http_client): def test_endpoint(journal_upload_service) -> None: - assert journal_upload_service.path == "/public/v1/billing/journals/JRN-0000-0001/upload" + result = journal_upload_service.path == "/public/v1/billing/journals/JRN-0000-0001/upload" + + assert result is True def test_async_endpoint(async_journal_upload_service) -> None: - assert async_journal_upload_service.path == "/public/v1/billing/journals/JRN-0000-0001/upload" + result = async_journal_upload_service.path == "/public/v1/billing/journals/JRN-0000-0001/upload" + + assert result is True @pytest.mark.parametrize("method", ["create"]) def test_methods_present(journal_upload_service, method: str) -> None: - assert hasattr(journal_upload_service, method) + result = hasattr(journal_upload_service, method) + + assert result is True @pytest.mark.parametrize("method", ["create"]) def test_async_methods_present(async_journal_upload_service, method: str) -> None: - assert hasattr(async_journal_upload_service, method) + result = hasattr(async_journal_upload_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_journals.py b/tests/unit/resources/billing/test_journals.py index 658784ce..62b1ed1f 100644 --- a/tests/unit/resources/billing/test_journals.py +++ b/tests/unit/resources/billing/test_journals.py @@ -34,7 +34,9 @@ def async_journals_service(async_http_client): ["get", "create", "update", "delete", "regenerate", "submit", "enquiry", "accept"], ) def test_mixins_present(journals_service, method): - assert hasattr(journals_service, method) + result = hasattr(journals_service, method) + + assert result is True @pytest.mark.parametrize( @@ -42,7 +44,9 @@ def test_mixins_present(journals_service, method): ["get", "create", "update", "delete", "regenerate", "submit", "enquiry", "accept"], ) def test_async_mixins_present(async_journals_service, method): - assert hasattr(async_journals_service, method) + result = hasattr(async_journals_service, method) + + assert result is True @pytest.mark.parametrize( @@ -55,10 +59,10 @@ def test_async_mixins_present(async_journals_service, method): ], ) def test_property_services(journals_service, service_method, expected_service_class): - service = getattr(journals_service, service_method)("JRN-0000-0001") + result = getattr(journals_service, service_method)("JRN-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"journal_id": "JRN-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"journal_id": "JRN-0000-0001"} @pytest.mark.parametrize( @@ -71,7 +75,7 @@ def test_property_services(journals_service, service_method, expected_service_cl ], ) def test_async_property_services(async_journals_service, service_method, expected_service_class): - service = getattr(async_journals_service, service_method)("JRN-0000-0001") + result = getattr(async_journals_service, service_method)("JRN-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"journal_id": "JRN-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"journal_id": "JRN-0000-0001"} diff --git a/tests/unit/resources/billing/test_ledger_attachments.py b/tests/unit/resources/billing/test_ledger_attachments.py index f5ef2173..dbc7f8c4 100644 --- a/tests/unit/resources/billing/test_ledger_attachments.py +++ b/tests/unit/resources/billing/test_ledger_attachments.py @@ -21,21 +21,31 @@ def async_ledger_attachments_service(async_http_client) -> AsyncLedgerAttachment def test_endpoint(ledger_attachments_service) -> None: - assert ledger_attachments_service.path == "/public/v1/billing/ledgers/LED-0000-0001/attachments" + result = ( + ledger_attachments_service.path == "/public/v1/billing/ledgers/LED-0000-0001/attachments" + ) + + assert result is True def test_async_endpoint(async_ledger_attachments_service) -> None: - assert ( + result = ( async_ledger_attachments_service.path == "/public/v1/billing/ledgers/LED-0000-0001/attachments" ) + assert result is True + @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_methods_present(ledger_attachments_service, method: str) -> None: - assert hasattr(ledger_attachments_service, method) + result = hasattr(ledger_attachments_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_methods_present(async_ledger_attachments_service, method: str) -> None: - assert hasattr(async_ledger_attachments_service, method) + result = hasattr(async_ledger_attachments_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_ledger_charges.py b/tests/unit/resources/billing/test_ledger_charges.py index 116a41ad..7ad41813 100644 --- a/tests/unit/resources/billing/test_ledger_charges.py +++ b/tests/unit/resources/billing/test_ledger_charges.py @@ -21,18 +21,26 @@ def async_ledger_charges_service(async_http_client): def test_endpoint(ledger_charges_service): - assert ledger_charges_service.path == "/public/v1/billing/ledgers/LED-0000-0001/charges" + result = ledger_charges_service.path == "/public/v1/billing/ledgers/LED-0000-0001/charges" + + assert result is True def test_async_endpoint(async_ledger_charges_service): - assert async_ledger_charges_service.path == "/public/v1/billing/ledgers/LED-0000-0001/charges" + result = async_ledger_charges_service.path == "/public/v1/billing/ledgers/LED-0000-0001/charges" + + assert result is True @pytest.mark.parametrize("method", ["get"]) def test_methods_present(ledger_charges_service, method): - assert hasattr(ledger_charges_service, method) + result = hasattr(ledger_charges_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get"]) def test_async_methods_present(async_ledger_charges_service, method): - assert hasattr(async_ledger_charges_service, method) + result = hasattr(async_ledger_charges_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_ledgers.py b/tests/unit/resources/billing/test_ledgers.py index 358037c0..fe8edaf7 100644 --- a/tests/unit/resources/billing/test_ledgers.py +++ b/tests/unit/resources/billing/test_ledgers.py @@ -26,7 +26,9 @@ def async_ledgers_service(async_http_client): ["get", "create"], ) def test_mixins_present(ledgers_service, method): - assert hasattr(ledgers_service, method) + result = hasattr(ledgers_service, method) + + assert result is True @pytest.mark.parametrize( @@ -34,7 +36,9 @@ def test_mixins_present(ledgers_service, method): ["get", "create"], ) def test_async_mixins_present(async_ledgers_service, method): - assert hasattr(async_ledgers_service, method) + result = hasattr(async_ledgers_service, method) + + assert result is True @pytest.mark.parametrize( @@ -45,10 +49,10 @@ def test_async_mixins_present(async_ledgers_service, method): ], ) def test_property_services(ledgers_service, service_method, expected_service_class): - service = getattr(ledgers_service, service_method)("LED-0000-0001") + result = getattr(ledgers_service, service_method)("LED-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"ledger_id": "LED-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"ledger_id": "LED-0000-0001"} @pytest.mark.parametrize( @@ -59,7 +63,7 @@ def test_property_services(ledgers_service, service_method, expected_service_cla ], ) def test_async_property_services(async_ledgers_service, service_method, expected_service_class): - service = getattr(async_ledgers_service, service_method)("LED-0000-0001") + result = getattr(async_ledgers_service, service_method)("LED-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"ledger_id": "LED-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"ledger_id": "LED-0000-0001"} diff --git a/tests/unit/resources/billing/test_manual_overrides.py b/tests/unit/resources/billing/test_manual_overrides.py index 6f9ef264..77e06624 100644 --- a/tests/unit/resources/billing/test_manual_overrides.py +++ b/tests/unit/resources/billing/test_manual_overrides.py @@ -21,7 +21,9 @@ def async_manual_overrides_service(http_client): ["get", "create", "update"], ) def test_mixins_present(manual_overrides_service, method): - assert hasattr(manual_overrides_service, method) + result = hasattr(manual_overrides_service, method) + + assert result is True @pytest.mark.parametrize( @@ -29,4 +31,6 @@ def test_mixins_present(manual_overrides_service, method): ["get", "create", "update"], ) def test_async_mixins_present(async_manual_overrides_service, method): - assert hasattr(async_manual_overrides_service, method) + result = hasattr(async_manual_overrides_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_mixins.py b/tests/unit/resources/billing/test_mixins.py index c53abb8a..4a709130 100644 --- a/tests/unit/resources/billing/test_mixins.py +++ b/tests/unit/resources/billing/test_mixins.py @@ -151,14 +151,14 @@ def test_custom_resource_actions(regeneratable_service, action, input_status): json=response_expected_data, ) ) - journal = getattr(regeneratable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(regeneratable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert journal.to_dict() == response_expected_data - assert isinstance(journal, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -183,14 +183,14 @@ def test_custom_resource_actions_no_data(regeneratable_service, action, input_st json=response_expected_data, ) ) - journal = getattr(regeneratable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(regeneratable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert journal.to_dict() == response_expected_data - assert isinstance(journal, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -215,14 +215,14 @@ async def test_async_custom_resource_actions(async_regeneratable_service, action json=response_expected_data, ) ) - journal = await getattr(async_regeneratable_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_regeneratable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert journal.to_dict() == response_expected_data - assert isinstance(journal, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -249,14 +249,14 @@ async def test_async_custom_resource_actions_no_data( json=response_expected_data, ) ) - journal = await getattr(async_regeneratable_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_regeneratable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert journal.to_dict() == response_expected_data - assert isinstance(journal, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -280,14 +280,14 @@ def test_recalculate_resource_actions(recalculatable_service, action, input_stat json=response_expected_data, ) ) - recalc_obj = getattr(recalculatable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(recalculatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert recalc_obj.to_dict() == response_expected_data - assert isinstance(recalc_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -307,14 +307,14 @@ def test_recalculate_resource_actions_no_data(recalculatable_service, action, in json=response_expected_data, ) ) - recalc_obj = getattr(recalculatable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(recalculatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert recalc_obj.to_dict() == response_expected_data - assert isinstance(recalc_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -340,16 +340,14 @@ async def test_async_recalculate_resource_actions( json=response_expected_data, ) ) - recalc_obj = await getattr(async_recalculatable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_recalculatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert recalc_obj.to_dict() == response_expected_data - assert isinstance(recalc_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -371,16 +369,14 @@ async def test_async_recalculate_resource_actions_no_data( json=response_expected_data, ) ) - recalc_obj = await getattr(async_recalculatable_service, action)( - "OBJ-0000-0001", input_status - ) + + result = await getattr(async_recalculatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert recalc_obj.to_dict() == response_expected_data - assert isinstance(recalc_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -408,14 +404,14 @@ def test_issuable_resource_actions(issuable_service, action, input_status): json=response_expected_data, ) ) - issuable_obj = getattr(issuable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(issuable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert issuable_obj.to_dict() == response_expected_data - assert isinstance(issuable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -443,14 +439,14 @@ def test_issuable_resource_actions_no_data(issuable_service, action, input_statu json=response_expected_data, ) ) - issuable_obj = getattr(issuable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(issuable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert issuable_obj.to_dict() == response_expected_data - assert isinstance(issuable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -478,14 +474,14 @@ async def test_async_issuable_resource_actions(async_issuable_service, action, i json=response_expected_data, ) ) - issuable_obj = await getattr(async_issuable_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_issuable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert issuable_obj.to_dict() == response_expected_data - assert isinstance(issuable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -515,14 +511,14 @@ async def test_async_issuable_resource_actions_no_data( json=response_expected_data, ) ) - issuable_obj = await getattr(async_issuable_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_issuable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert issuable_obj.to_dict() == response_expected_data - assert isinstance(issuable_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -545,14 +541,14 @@ def test_acceptable_resource_actions(acceptable_service, action, input_status): json=response_expected_data, ) ) - accept_obj = getattr(acceptable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(acceptable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert accept_obj.to_dict() == response_expected_data - assert isinstance(accept_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -572,14 +568,14 @@ def test_acceptable_resource_actions_no_data(acceptable_service, action, input_s json=response_expected_data, ) ) - accept_obj = getattr(acceptable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(acceptable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert accept_obj.to_dict() == response_expected_data - assert isinstance(accept_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -602,14 +598,14 @@ async def test_async_acceptable_resource_actions(async_acceptable_service, actio json=response_expected_data, ) ) - accept_obj = await getattr(async_acceptable_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_acceptable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert accept_obj.to_dict() == response_expected_data - assert isinstance(accept_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -631,11 +627,11 @@ async def test_async_acceptable_resource_actions_no_data( json=response_expected_data, ) ) - accept_obj = await getattr(async_acceptable_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_acceptable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert accept_obj.to_dict() == response_expected_data - assert isinstance(accept_obj, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) diff --git a/tests/unit/resources/billing/test_statement_charges.py b/tests/unit/resources/billing/test_statement_charges.py index 676297a0..4e5a1c37 100644 --- a/tests/unit/resources/billing/test_statement_charges.py +++ b/tests/unit/resources/billing/test_statement_charges.py @@ -21,20 +21,30 @@ def async_statement_charges_service(async_http_client): def test_endpoint(statement_charges_service): - assert statement_charges_service.path == ("/public/v1/billing/statements/STM-0000-0001/charges") + result = statement_charges_service.path == ( + "/public/v1/billing/statements/STM-0000-0001/charges" + ) + + assert result is True def test_async_endpoint(async_statement_charges_service): - assert async_statement_charges_service.path == ( + result = async_statement_charges_service.path == ( "/public/v1/billing/statements/STM-0000-0001/charges" ) + assert result is True + @pytest.mark.parametrize("method", ["get"]) def test_methods_present(statement_charges_service, method): - assert hasattr(statement_charges_service, method) + result = hasattr(statement_charges_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get"]) def test_async_methods_present(async_statement_charges_service, method): - assert hasattr(async_statement_charges_service, method) + result = hasattr(async_statement_charges_service, method) + + assert result is True diff --git a/tests/unit/resources/billing/test_statements.py b/tests/unit/resources/billing/test_statements.py index 569d2b4e..dd9ab797 100644 --- a/tests/unit/resources/billing/test_statements.py +++ b/tests/unit/resources/billing/test_statements.py @@ -22,7 +22,9 @@ def async_statements_service(async_http_client): ["get", "update", "issue", "cancel", "error", "pending", "queue", "retry", "recalculate"], ) def test_mixins_present(statements_service, method): - assert hasattr(statements_service, method) + result = hasattr(statements_service, method) + + assert result is True @pytest.mark.parametrize( @@ -30,7 +32,9 @@ def test_mixins_present(statements_service, method): ["get", "update", "issue", "cancel", "error", "pending", "queue", "retry", "recalculate"], ) def test_async_mixins_present(async_statements_service, method): - assert hasattr(async_statements_service, method) + result = hasattr(async_statements_service, method) + + assert result is True @pytest.mark.parametrize( @@ -40,10 +44,10 @@ def test_async_mixins_present(async_statements_service, method): ], ) def test_property_services(statements_service, service_method, expected_service_class): - service = getattr(statements_service, service_method)("STM-0000-0001") + result = getattr(statements_service, service_method)("STM-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"statement_id": "STM-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"statement_id": "STM-0000-0001"} @pytest.mark.parametrize( @@ -53,7 +57,7 @@ def test_property_services(statements_service, service_method, expected_service_ ], ) def test_async_property_services(async_statements_service, service_method, expected_service_class): - service = getattr(async_statements_service, service_method)("STM-0000-0001") + result = getattr(async_statements_service, service_method)("STM-0000-0001") - assert isinstance(service, expected_service_class) - assert service.endpoint_params == {"statement_id": "STM-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"statement_id": "STM-0000-0001"} diff --git a/tests/unit/resources/catalog/test_authorizations.py b/tests/unit/resources/catalog/test_authorizations.py index e8fa0008..c425c87e 100644 --- a/tests/unit/resources/catalog/test_authorizations.py +++ b/tests/unit/resources/catalog/test_authorizations.py @@ -18,9 +18,13 @@ def async_authorizations_service(async_http_client): @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_mixins_present(authorizations_service, method): - assert hasattr(authorizations_service, method) + result = hasattr(authorizations_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_mixins_present(async_authorizations_service, method): - assert hasattr(async_authorizations_service, method) + result = hasattr(async_authorizations_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_catalog.py b/tests/unit/resources/catalog/test_catalog.py index 2ba2163e..2df550c7 100644 --- a/tests/unit/resources/catalog/test_catalog.py +++ b/tests/unit/resources/catalog/test_catalog.py @@ -45,11 +45,10 @@ def async_catalog(async_http_client): ], ) def test_catalog_properties(catalog, property_name, expected_service_class): - """Test that Catalog properties return correct instances.""" - service = getattr(catalog, property_name) + result = getattr(catalog, property_name) - assert isinstance(service, expected_service_class) - assert service.http_client is catalog.http_client + assert isinstance(result, expected_service_class) + assert result.http_client is catalog.http_client @pytest.mark.parametrize( @@ -65,24 +64,21 @@ def test_catalog_properties(catalog, property_name, expected_service_class): ], ) def test_async_catalog_properties(async_catalog, property_name, expected_service_class): - """Test that AsyncCatalog properties return correct instances.""" - service = getattr(async_catalog, property_name) + result = getattr(async_catalog, property_name) - assert isinstance(service, expected_service_class) - assert service.http_client is async_catalog.http_client + assert isinstance(result, expected_service_class) + assert result.http_client is async_catalog.http_client def test_catalog_initialization(http_client): - """Test that Catalog can be properly initialized with http_client.""" - catalog = Catalog(http_client=http_client) + result = Catalog(http_client=http_client) - assert catalog.http_client is http_client - assert isinstance(catalog, Catalog) + assert result.http_client is http_client + assert isinstance(result, Catalog) def test_async_catalog_initialization(async_http_client): - """Test that AsyncCatalog can be properly initialized with http_client.""" - async_catalog = AsyncCatalog(http_client=async_http_client) + result = AsyncCatalog(http_client=async_http_client) - assert async_catalog.http_client is async_http_client - assert isinstance(async_catalog, AsyncCatalog) + assert result.http_client is async_http_client + assert isinstance(result, AsyncCatalog) diff --git a/tests/unit/resources/catalog/test_items.py b/tests/unit/resources/catalog/test_items.py index cb5ed98c..d99b11c6 100644 --- a/tests/unit/resources/catalog/test_items.py +++ b/tests/unit/resources/catalog/test_items.py @@ -17,11 +17,15 @@ def async_items_service(async_http_client): "method", ["get", "create", "update", "delete", "review", "publish", "unpublish"] ) def test_mixins_present(items_service, method): - assert hasattr(items_service, method) + result = hasattr(items_service, method) + + assert result is True @pytest.mark.parametrize( "method", ["get", "create", "update", "delete", "review", "publish", "unpublish"] ) def test_async_mixins_present(async_items_service, method): - assert hasattr(async_items_service, method) + result = hasattr(async_items_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_listings.py b/tests/unit/resources/catalog/test_listings.py index 7c0d524c..2a5d8549 100644 --- a/tests/unit/resources/catalog/test_listings.py +++ b/tests/unit/resources/catalog/test_listings.py @@ -18,9 +18,13 @@ def async_listings_service(async_http_client): @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_mixins_present(listings_service, method): - assert hasattr(listings_service, method) + result = hasattr(listings_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_mixins_present(async_listings_service, method): - assert hasattr(async_listings_service, method) + result = hasattr(async_listings_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_mixins.py b/tests/unit/resources/catalog/test_mixins.py index 8790c063..a5137fe6 100644 --- a/tests/unit/resources/catalog/test_mixins.py +++ b/tests/unit/resources/catalog/test_mixins.py @@ -116,14 +116,14 @@ def test_custom_resource_actions(publishable_service, action, input_status): json=response_expected_data, ) ) - order = getattr(publishable_service, action)("PRD-123", input_status) + + result = getattr(publishable_service, action)("PRD-123", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert order.to_dict() == response_expected_data - assert isinstance(order, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -148,13 +148,13 @@ def test_custom_resource_actions_no_data(publishable_service, action, input_stat ) ) - order = getattr(publishable_service, action)("PRD-123") + result = getattr(publishable_service, action)("PRD-123") assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.content == request_expected_content - assert order.to_dict() == response_expected_data - assert isinstance(order, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -178,14 +178,14 @@ async def test_async_custom_resource_actions(async_publishable_service, action, json=response_expected_data, ) ) - order = await getattr(async_publishable_service, action)("PRD-123", input_status) + + result = await getattr(async_publishable_service, action)("PRD-123", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert order.to_dict() == response_expected_data - assert isinstance(order, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -212,13 +212,13 @@ async def test_async_custom_resource_actions_no_data( ) ) - order = await getattr(async_publishable_service, action)("PRD-123") + result = await getattr(async_publishable_service, action)("PRD-123") assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.content == request_expected_content - assert order.to_dict() == response_expected_data - assert isinstance(order, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -241,14 +241,14 @@ def test_custom_resource_activatable_actions(activatable_service, action, input_ json=response_expected_data, ) ) - attachment = getattr(activatable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(activatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert attachment.to_dict() == response_expected_data - assert isinstance(attachment, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -271,14 +271,14 @@ def test_custom_resource_activatable_actions_no_data(activatable_service, action json=response_expected_data, ) ) - attachment = getattr(activatable_service, action)("OBJ-0000-0001", input_status) + + result = getattr(activatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert attachment.to_dict() == response_expected_data - assert isinstance(attachment, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -303,14 +303,14 @@ async def test_async_custom_resource_activatable_actions( json=response_expected_data, ) ) - attachment = await getattr(async_activatable_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_activatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert attachment.to_dict() == response_expected_data - assert isinstance(attachment, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.mark.parametrize( @@ -335,14 +335,14 @@ async def test_async_custom_resource_activatable_actions_no_data( json=response_expected_data, ) ) - attachment = await getattr(async_activatable_service, action)("OBJ-0000-0001", input_status) + + result = await getattr(async_activatable_service, action)("OBJ-0000-0001", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert attachment.to_dict() == response_expected_data - assert isinstance(attachment, DummyModel) + assert result.to_dict() == response_expected_data + assert isinstance(result, DummyModel) @pytest.fixture @@ -370,17 +370,16 @@ def test_document_create_with_url(document_service): ) new_doc = document_service.create(resource_data=resource_data) - request = mock_route.calls[0].request + result = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="document"\r\n' b"Content-Type: application/json\r\n\r\n" b'{"name":"My Doc","description":"My Doc","url":"https://example.com/file.pdf"}\r\n' - in request.content + in result.content ) - - assert b'Content-Disposition: form-data; name="file"' not in request.content - assert "multipart/form-data" in request.headers["Content-Type"] + assert b'Content-Disposition: form-data; name="file"' not in result.content + assert "multipart/form-data" in result.headers["Content-Type"] assert new_doc.to_dict() == resource_data assert isinstance(new_doc, DummyModel) @@ -389,12 +388,12 @@ def test_document_create_with_file(document_service): # noqa: WPS210 resource_data = {"id": "DOC-125", "name": "Data And File"} response_data = resource_data file_tuple = ("manual.pdf", io.BytesIO(b"PDF DATA"), "application/pdf") - with respx.mock: mock_route = respx.post("https://api.example.com/public/v1/dummy/documents").mock( return_value=httpx.Response(status_code=httpx.codes.OK, json=response_data) ) - new_doc = document_service.create(resource_data=resource_data, file=file_tuple) + + result = document_service.create(resource_data=resource_data, file=file_tuple) request = mock_route.calls[0].request # JSON part @@ -410,8 +409,8 @@ def test_document_create_with_file(document_service): # noqa: WPS210 b"PDF DATA\r\n" in request.content ) assert "multipart/form-data" in request.headers["Content-Type"] - assert new_doc.to_dict() == response_data - assert isinstance(new_doc, DummyModel) + assert result.to_dict() == response_data + assert isinstance(result, DummyModel) async def test_async_document_create_with_url(async_document_service): @@ -427,47 +426,44 @@ async def test_async_document_create_with_url(async_document_service): json=resource_data, ) ) - new_doc = await async_document_service.create(resource_data=resource_data) - request = mock_route.calls[0].request + result = await async_document_service.create(resource_data=resource_data) + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="document"\r\n' b"Content-Type: application/json\r\n\r\n" b'{"name":"My Doc","description":"My Doc","url":"https://example.com/file.pdf"}\r\n' in request.content ) - assert b'Content-Disposition: form-data; name="file"' not in request.content assert "multipart/form-data" in request.headers["Content-Type"] - assert new_doc.to_dict() == resource_data - assert isinstance(new_doc, DummyModel) + assert result.to_dict() == resource_data + assert isinstance(result, DummyModel) async def test_async_document_create_with_file(async_document_service): # noqa: WPS210 resource_data = {"id": "DOC-125", "name": "Data And File"} response_data = resource_data file_tuple = ("manual.pdf", io.BytesIO(b"PDF DATA"), "application/pdf") - with respx.mock: mock_route = respx.post("https://api.example.com/public/v1/dummy/documents").mock( return_value=httpx.Response(status_code=httpx.codes.OK, json=response_data) ) - new_doc = await async_document_service.create(resource_data, file_tuple) - request = mock_route.calls[0].request + result = await async_document_service.create(resource_data, file_tuple) + request = mock_route.calls[0].request assert ( b'Content-Disposition: form-data; name="document"\r\n' b"Content-Type: application/json\r\n\r\n" b'{"id":"DOC-125","name":"Data And File"}\r\n' in request.content ) - assert ( b'Content-Disposition: form-data; name="file"; filename="manual.pdf"\r\n' b"Content-Type: application/pdf\r\n\r\n" b"PDF DATA\r\n" in request.content ) assert "multipart/form-data" in request.headers["Content-Type"] - assert new_doc.to_dict() == response_data - assert isinstance(new_doc, DummyModel) + assert result.to_dict() == response_data + assert isinstance(result, DummyModel) diff --git a/tests/unit/resources/catalog/test_price_list_items.py b/tests/unit/resources/catalog/test_price_list_items.py index 6e3262d9..3e7480f8 100644 --- a/tests/unit/resources/catalog/test_price_list_items.py +++ b/tests/unit/resources/catalog/test_price_list_items.py @@ -22,21 +22,29 @@ def async_price_list_items_service(async_http_client): @pytest.fixture def test_endpoint(price_list_items_service): - assert price_list_items_service.path == "/public/v1/catalog/price-lists/ITM-0000-0001/items" + result = price_list_items_service.path == "/public/v1/catalog/price-lists/ITM-0000-0001/items" + + assert result is True @pytest.fixture def async_test_endpoint(async_price_list_items_service): - assert async_price_list_items_service.path == ( + result = async_price_list_items_service.path == ( "/public/v1/catalog/price-lists/ITM-0000-0001/items" ) + assert result is True + @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_methods_present(price_list_items_service, method): - assert hasattr(price_list_items_service, method) + result = hasattr(price_list_items_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_async_methods_present(async_price_list_items_service, method): - assert hasattr(async_price_list_items_service, method) + result = hasattr(async_price_list_items_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_price_lists.py b/tests/unit/resources/catalog/test_price_lists.py index 081f8948..161d3541 100644 --- a/tests/unit/resources/catalog/test_price_lists.py +++ b/tests/unit/resources/catalog/test_price_lists.py @@ -22,12 +22,16 @@ def async_price_lists_service(http_client): @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_mixins_present(price_lists_service, method): - assert hasattr(price_lists_service, method) + result = hasattr(price_lists_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_mixins_present(async_price_lists_service, method): - assert hasattr(async_price_lists_service, method) + result = hasattr(async_price_lists_service, method) + + assert result is True @pytest.mark.parametrize( @@ -37,10 +41,10 @@ def test_async_mixins_present(async_price_lists_service, method): ], ) def test_property_services(price_lists_service, service_method, expected_model_class): - property_service = getattr(price_lists_service, service_method)("ITM-0000-0001") + result = getattr(price_lists_service, service_method)("ITM-0000-0001") - assert isinstance(property_service, expected_model_class) - assert property_service.endpoint_params == {"price_list_id": "ITM-0000-0001"} + assert isinstance(result, expected_model_class) + assert result.endpoint_params == {"price_list_id": "ITM-0000-0001"} @pytest.mark.parametrize( @@ -50,7 +54,7 @@ def test_property_services(price_lists_service, service_method, expected_model_c ], ) def test_async_property_services(async_price_lists_service, service_method, expected_model_class): - property_service = getattr(async_price_lists_service, service_method)("ITM-0000-0001") + result = getattr(async_price_lists_service, service_method)("ITM-0000-0001") - assert isinstance(property_service, expected_model_class) - assert property_service.endpoint_params == {"price_list_id": "ITM-0000-0001"} + assert isinstance(result, expected_model_class) + assert result.endpoint_params == {"price_list_id": "ITM-0000-0001"} diff --git a/tests/unit/resources/catalog/test_pricing_policies.py b/tests/unit/resources/catalog/test_pricing_policies.py index 69c2ae86..e8661f04 100644 --- a/tests/unit/resources/catalog/test_pricing_policies.py +++ b/tests/unit/resources/catalog/test_pricing_policies.py @@ -38,11 +38,11 @@ def test_activate(pricing_policies_service): ) ) - pricing_policy_activated = pricing_policies_service.activate( + result = pricing_policies_service.activate( "PRP-0000-0001", {"name": "Active Pricing Policy"} ) - assert pricing_policy_activated.to_dict() == pricing_policy_expected + assert result.to_dict() == pricing_policy_expected async def test_async_activate(async_pricing_policies_service): @@ -61,11 +61,11 @@ async def test_async_activate(async_pricing_policies_service): ) ) - pricing_policy_activated = await async_pricing_policies_service.activate( + result = await async_pricing_policies_service.activate( "PRP-0000-0001", {"name": "Active Pricing Policy"} ) - assert pricing_policy_activated.to_dict() == pricing_policy_expected + assert result.to_dict() == pricing_policy_expected def test_disable(pricing_policies_service): @@ -84,11 +84,11 @@ def test_disable(pricing_policies_service): ) ) - pricing_policy_disabled = pricing_policies_service.disable( + result = pricing_policies_service.disable( "PRP-0000-0001", {"name": "Inactive Pricing Policy"} ) - assert pricing_policy_disabled.to_dict() == pricing_policy_expected + assert result.to_dict() == pricing_policy_expected async def test_async_disable(async_pricing_policies_service): @@ -107,11 +107,11 @@ async def test_async_disable(async_pricing_policies_service): ) ) - pricing_policy_disabled = await async_pricing_policies_service.disable( + result = await async_pricing_policies_service.disable( "PRP-0000-0001", {"name": "Inactive Pricing Policy"} ) - assert pricing_policy_disabled.to_dict() == pricing_policy_expected + assert result.to_dict() == pricing_policy_expected @pytest.mark.parametrize( @@ -121,10 +121,10 @@ async def test_async_disable(async_pricing_policies_service): ], ) def test_property_services(pricing_policies_service, service_method, expected_service_class): - property_service = getattr(pricing_policies_service, service_method)("PRP-0000-0001") + result = getattr(pricing_policies_service, service_method)("PRP-0000-0001") - assert isinstance(property_service, expected_service_class) - assert property_service.endpoint_params == {"pricing_policy_id": "PRP-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"pricing_policy_id": "PRP-0000-0001"} @pytest.mark.parametrize( @@ -136,10 +136,10 @@ def test_property_services(pricing_policies_service, service_method, expected_se def test_async_property_services( async_pricing_policies_service, service_method, expected_service_class ): - property_service = getattr(async_pricing_policies_service, service_method)("PRP-0000-0001") + result = getattr(async_pricing_policies_service, service_method)("PRP-0000-0001") - assert isinstance(property_service, expected_service_class) - assert property_service.endpoint_params == {"pricing_policy_id": "PRP-0000-0001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"pricing_policy_id": "PRP-0000-0001"} @pytest.mark.parametrize( @@ -147,7 +147,9 @@ def test_async_property_services( ["get", "create", "update", "delete", "activate", "disable"], ) def test_mixins_present(pricing_policies_service, method): - assert hasattr(pricing_policies_service, method) + result = hasattr(pricing_policies_service, method) + + assert result is True @pytest.mark.parametrize( @@ -155,4 +157,6 @@ def test_mixins_present(pricing_policies_service, method): ["get", "create", "update", "delete", "activate", "disable"], ) def test_async_mixins_present(async_pricing_policies_service, method): - assert hasattr(async_pricing_policies_service, method) + result = hasattr(async_pricing_policies_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_pricing_policy_attachments.py b/tests/unit/resources/catalog/test_pricing_policy_attachments.py index 30b137f2..a8bf3874 100644 --- a/tests/unit/resources/catalog/test_pricing_policy_attachments.py +++ b/tests/unit/resources/catalog/test_pricing_policy_attachments.py @@ -23,28 +23,36 @@ def async_pricing_policy_attachments_service( def test_endpoint(pricing_policy_attachments_service) -> None: - assert ( + result = ( pricing_policy_attachments_service.path == "/public/v1/catalog/pricing-policies/PRP-0000-0001/attachments" ) + assert result is True + def test_async_endpoint(async_pricing_policy_attachments_service) -> None: - assert ( + result = ( async_pricing_policy_attachments_service.path == "/public/v1/catalog/pricing-policies/PRP-0000-0001/attachments" ) + assert result is True + @pytest.mark.parametrize( "method", ["get", "create", "delete", "update", "download", "activate", "deactivate"] ) def test_methods_present(pricing_policy_attachments_service, method: str) -> None: - assert hasattr(pricing_policy_attachments_service, method) + result = hasattr(pricing_policy_attachments_service, method) + + assert result is True @pytest.mark.parametrize( "method", ["get", "create", "delete", "update", "download", "activate", "deactivate"] ) def test_async_methods_present(async_pricing_policy_attachments_service, method: str) -> None: - assert hasattr(async_pricing_policy_attachments_service, method) + result = hasattr(async_pricing_policy_attachments_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_product_term_variants.py b/tests/unit/resources/catalog/test_product_term_variants.py index 429d7a54..f4ac4e6b 100644 --- a/tests/unit/resources/catalog/test_product_term_variants.py +++ b/tests/unit/resources/catalog/test_product_term_variants.py @@ -24,21 +24,29 @@ def async_term_variant_service(async_http_client: Any) -> AsyncTermVariantServic def test_endpoint(term_variant_service: TermVariantService) -> None: - assert term_variant_service.path == "/public/v1/catalog/products/PRD-001/terms/TRM-001/variants" + result = ( + term_variant_service.path == "/public/v1/catalog/products/PRD-001/terms/TRM-001/variants" + ) + + assert result is True def test_async_endpoint(async_term_variant_service: AsyncTermVariantService) -> None: - assert ( + result = ( async_term_variant_service.path == "/public/v1/catalog/products/PRD-001/terms/TRM-001/variants" ) + assert result is True + @pytest.mark.parametrize( "method", ["get", "create", "delete", "update", "download", "review", "publish", "unpublish"] ) def test_methods_present(term_variant_service: TermVariantService, method: str) -> None: - assert hasattr(term_variant_service, method) + result = hasattr(term_variant_service, method) + + assert result is True @pytest.mark.parametrize( @@ -47,4 +55,6 @@ def test_methods_present(term_variant_service: TermVariantService, method: str) def test_async_methods_present( async_term_variant_service: AsyncTermVariantService, method: str ) -> None: - assert hasattr(async_term_variant_service, method) + result = hasattr(async_term_variant_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_product_terms.py b/tests/unit/resources/catalog/test_product_terms.py index 57d5c419..28722c09 100644 --- a/tests/unit/resources/catalog/test_product_terms.py +++ b/tests/unit/resources/catalog/test_product_terms.py @@ -25,38 +25,46 @@ def async_term_service(async_http_client: Any) -> AsyncTermService: def test_endpoint(term_service: TermService) -> None: - assert term_service.path == "/public/v1/catalog/products/PRD-001/terms" + result = term_service.path == "/public/v1/catalog/products/PRD-001/terms" + + assert result is True def test_async_endpoint(async_term_service: AsyncTermService) -> None: - assert async_term_service.path == "/public/v1/catalog/products/PRD-001/terms" + result = async_term_service.path == "/public/v1/catalog/products/PRD-001/terms" + + assert result is True @pytest.mark.parametrize( "method", ["get", "create", "delete", "update", "review", "publish", "unpublish"] ) def test_methods_present(term_service: TermService, method: str) -> None: - assert hasattr(term_service, method) + result = hasattr(term_service, method) + + assert result is True @pytest.mark.parametrize( "method", ["get", "create", "delete", "update", "review", "publish", "unpublish"] ) def test_async_methods_present(async_term_service: AsyncTermService, method: str) -> None: - assert hasattr(async_term_service, method) + result = hasattr(async_term_service, method) + + assert result is True def test_variants_property(term_service: TermService) -> None: - """Test that variants property returns TermVariantService.""" - variants = term_service.variants("TCS-001") - assert isinstance(variants, TermVariantService) - assert variants.http_client == term_service.http_client - assert variants.endpoint_params == {"product_id": "PRD-001", "term_id": "TCS-001"} + result = term_service.variants("TCS-001") + + assert isinstance(result, TermVariantService) + assert result.http_client == term_service.http_client + assert result.endpoint_params == {"product_id": "PRD-001", "term_id": "TCS-001"} def test_async_variants_property(async_term_service: AsyncTermService) -> None: - """Test that variants property returns AsyncTermVariantService.""" - variants = async_term_service.variants("TCS-001") - assert isinstance(variants, AsyncTermVariantService) - assert variants.http_client == async_term_service.http_client - assert variants.endpoint_params == {"product_id": "PRD-001", "term_id": "TCS-001"} + result = async_term_service.variants("TCS-001") + + assert isinstance(result, AsyncTermVariantService) + assert result.http_client == async_term_service.http_client + assert result.endpoint_params == {"product_id": "PRD-001", "term_id": "TCS-001"} diff --git a/tests/unit/resources/catalog/test_products.py b/tests/unit/resources/catalog/test_products.py index 8b0bd5f3..5dea300e 100644 --- a/tests/unit/resources/catalog/test_products.py +++ b/tests/unit/resources/catalog/test_products.py @@ -48,7 +48,9 @@ def async_products_service(async_http_client): ["get", "create", "update", "delete", "review", "publish", "unpublish", "update_settings"], ) def test_mixins_present(products_service, method): - assert hasattr(products_service, method) + result = hasattr(products_service, method) + + assert result is True @pytest.mark.parametrize( @@ -56,7 +58,9 @@ def test_mixins_present(products_service, method): ["get", "create", "update", "delete", "review", "publish", "unpublish", "update_settings"], ) def test_async_mixins_present(async_products_service, method): - assert hasattr(async_products_service, method) + result = hasattr(async_products_service, method) + + assert result is True @pytest.mark.parametrize( @@ -72,10 +76,10 @@ def test_async_mixins_present(async_products_service, method): ], ) def test_property_services(products_service, service_method, expected_service_class): - property_service = getattr(products_service, service_method)("PRD-001") + result = getattr(products_service, service_method)("PRD-001") - assert isinstance(property_service, expected_service_class) - assert property_service.endpoint_params == {"product_id": "PRD-001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"product_id": "PRD-001"} @pytest.mark.parametrize( @@ -91,34 +95,31 @@ def test_property_services(products_service, service_method, expected_service_cl ], ) def test_async_property_services(async_products_service, service_method, expected_service_class): - property_service = getattr(async_products_service, service_method)("PRD-001") + result = getattr(async_products_service, service_method)("PRD-001") - assert isinstance(property_service, expected_service_class) - assert property_service.endpoint_params == {"product_id": "PRD-001"} + assert isinstance(result, expected_service_class) + assert result.endpoint_params == {"product_id": "PRD-001"} def test_update_settings(products_service): - """Test updating product settings.""" product_id = "PRD-001" settings_data = {"visibility": "public", "searchable": True, "featured": False} expected_response = {"id": product_id, "name": "Test Product", "settings": settings_data} - with respx.mock: mock_route = respx.put( f"https://api.example.com/public/v1/catalog/products/{product_id}/settings" ).mock(return_value=httpx.Response(httpx.codes.OK, json=expected_response)) - product = products_service.update_settings(product_id, settings_data) + result = products_service.update_settings(product_id, settings_data) assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.method == "PUT" assert request.url.path == f"/public/v1/catalog/products/{product_id}/settings" - assert product.to_dict() == expected_response + assert result.to_dict() == expected_response async def test_async_update_settings(async_products_service): - """Test updating product settings asynchronously.""" product_id = "PRD-002" settings_data = {"visibility": "private", "searchable": False, "featured": True} expected_response = {"id": product_id, "name": "Test Product Async", "settings": settings_data} @@ -128,20 +129,18 @@ async def test_async_update_settings(async_products_service): f"https://api.example.com/public/v1/catalog/products/{product_id}/settings" ).mock(return_value=httpx.Response(httpx.codes.OK, json=expected_response)) - product = await async_products_service.update_settings(product_id, settings_data) + result = await async_products_service.update_settings(product_id, settings_data) assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.method == "PUT" assert request.url.path == f"/public/v1/catalog/products/{product_id}/settings" - assert product.to_dict() == expected_response + assert result.to_dict() == expected_response def test_product_create(products_service, tmp_path): - """Test creating a product (sync).""" product_data = {"name": "New Product", "category": "Books"} expected_response = {"id": "PRD-123", "name": "New Product", "category": "Books"} - icon_path = tmp_path / "icon.png" icon_path.write_bytes(b"fake image data") with icon_path.open("rb") as icon_file, respx.mock: @@ -149,20 +148,18 @@ def test_product_create(products_service, tmp_path): return_value=httpx.Response(httpx.codes.CREATED, json=expected_response) ) - product = products_service.create(product_data, icon=icon_file) + result = products_service.create(product_data, icon=icon_file) assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.method == "POST" assert request.url.path == "/public/v1/catalog/products" - assert product.to_dict() == expected_response + assert result.to_dict() == expected_response async def test_async_product_create(async_products_service, tmp_path): - """Test creating a product (async).""" product_data = {"name": "Async Product", "category": "Music"} expected_response = {"id": "PRD-456", "name": "Async Product", "category": "Music"} - # Create a temporary icon file icon_path = tmp_path / "icon.png" icon_path.write_bytes(b"fake image data") @@ -171,21 +168,19 @@ async def test_async_product_create(async_products_service, tmp_path): return_value=httpx.Response(httpx.codes.CREATED, json=expected_response) ) - product = await async_products_service.create(product_data, icon=icon_file) + result = await async_products_service.create(product_data, icon=icon_file) assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.method == "POST" assert request.url.path == "/public/v1/catalog/products" - assert product.to_dict() == expected_response + assert result.to_dict() == expected_response def test_sync_product_update(products_service, tmp_path): - """Test updating a product (sync).""" product_id = "PRD-123" update_data = {"name": "Updated Product", "category": "Electronics"} expected_response = {"id": product_id, "name": "Updated Product", "category": "Electronics"} - icon_path = tmp_path / "icon.png" icon_path.write_bytes(b"fake updated image data") with icon_path.open("rb") as icon_file, respx.mock: @@ -193,25 +188,19 @@ def test_sync_product_update(products_service, tmp_path): f"https://api.example.com/public/v1/catalog/products/{product_id}" ).mock(return_value=httpx.Response(httpx.codes.OK, json=expected_response)) - product = products_service.update( - product_id, - update_data, - icon=icon_file, - ) + result = products_service.update(product_id, update_data, icon=icon_file) assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.method == "PUT" assert request.url.path == f"/public/v1/catalog/products/{product_id}" - assert product.to_dict() == expected_response + assert result.to_dict() == expected_response async def test_async_product_update(async_products_service, tmp_path): - """Test updating a product (async).""" product_id = "PRD-456" update_data = {"name": "Async Updated Product", "category": "Gadgets"} expected_response = {"id": product_id, "name": "Async Updated Product", "category": "Gadgets"} - icon_path = tmp_path / "icon.png" icon_path.write_bytes(b"fake async updated image data") with icon_path.open("rb") as icon_file, respx.mock: @@ -219,14 +208,10 @@ async def test_async_product_update(async_products_service, tmp_path): f"https://api.example.com/public/v1/catalog/products/{product_id}" ).mock(return_value=httpx.Response(httpx.codes.OK, json=expected_response)) - product = await async_products_service.update( - product_id, - update_data, - icon=icon_file, - ) + result = await async_products_service.update(product_id, update_data, icon=icon_file) assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.method == "PUT" assert request.url.path == f"/public/v1/catalog/products/{product_id}" - assert product.to_dict() == expected_response + assert result.to_dict() == expected_response diff --git a/tests/unit/resources/catalog/test_products_documents.py b/tests/unit/resources/catalog/test_products_documents.py index 7d0900b2..740a625d 100644 --- a/tests/unit/resources/catalog/test_products_documents.py +++ b/tests/unit/resources/catalog/test_products_documents.py @@ -19,22 +19,30 @@ def async_document_service(async_http_client) -> AsyncDocumentService: def test_endpoint(document_service) -> None: - assert document_service.path == "/public/v1/catalog/products/PRD-001/documents" + result = document_service.path == "/public/v1/catalog/products/PRD-001/documents" + + assert result is True def test_async_endpoint(async_document_service) -> None: - assert async_document_service.path == "/public/v1/catalog/products/PRD-001/documents" + result = async_document_service.path == "/public/v1/catalog/products/PRD-001/documents" + + assert result is True @pytest.mark.parametrize( "method", ["get", "create", "delete", "update", "download", "review", "publish", "unpublish"] ) def test_methods_present(document_service, method: str) -> None: - assert hasattr(document_service, method) + result = hasattr(document_service, method) + + assert result is True @pytest.mark.parametrize( "method", ["get", "create", "delete", "update", "download", "review", "publish", "unpublish"] ) def test_async_methods_present(async_document_service, method: str) -> None: - assert hasattr(async_document_service, method) + result = hasattr(async_document_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_products_item_groups.py b/tests/unit/resources/catalog/test_products_item_groups.py index 05a72b14..547b9440 100644 --- a/tests/unit/resources/catalog/test_products_item_groups.py +++ b/tests/unit/resources/catalog/test_products_item_groups.py @@ -19,18 +19,26 @@ def async_item_groups_service(async_http_client): def test_endpoint(item_groups_service): - assert item_groups_service.path == "/public/v1/catalog/products/PRD-001/item-groups" + result = item_groups_service.path == "/public/v1/catalog/products/PRD-001/item-groups" + + assert result is True def test_async_endpoint(async_item_groups_service): - assert async_item_groups_service.path == "/public/v1/catalog/products/PRD-001/item-groups" + result = async_item_groups_service.path == "/public/v1/catalog/products/PRD-001/item-groups" + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_methods_present(item_groups_service, method): - assert hasattr(item_groups_service, method) + result = hasattr(item_groups_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_async_methods_present(async_item_groups_service, method): - assert hasattr(async_item_groups_service, method) + result = hasattr(async_item_groups_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_products_media.py b/tests/unit/resources/catalog/test_products_media.py index f82f00c0..a9afb9dc 100644 --- a/tests/unit/resources/catalog/test_products_media.py +++ b/tests/unit/resources/catalog/test_products_media.py @@ -19,22 +19,30 @@ def async_media_service(async_http_client) -> AsyncMediaService: def test_endpoint(media_service) -> None: - assert media_service.path == "/public/v1/catalog/products/PRD-001/media" + result = media_service.path == "/public/v1/catalog/products/PRD-001/media" + + assert result is True def test_async_endpoint(async_media_service) -> None: - assert async_media_service.path == "/public/v1/catalog/products/PRD-001/media" + result = async_media_service.path == "/public/v1/catalog/products/PRD-001/media" + + assert result is True @pytest.mark.parametrize( "method", ["get", "create", "delete", "update", "download", "review", "publish", "unpublish"] ) def test_methods_present(media_service, method: str) -> None: - assert hasattr(media_service, method) + result = hasattr(media_service, method) + + assert result is True @pytest.mark.parametrize( "method", ["get", "create", "delete", "update", "download", "review", "publish", "unpublish"] ) def test_async_methods_present(async_media_service, method: str) -> None: - assert hasattr(async_media_service, method) + result = hasattr(async_media_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_products_parameter_groups.py b/tests/unit/resources/catalog/test_products_parameter_groups.py index 0369dae9..a3008e65 100644 --- a/tests/unit/resources/catalog/test_products_parameter_groups.py +++ b/tests/unit/resources/catalog/test_products_parameter_groups.py @@ -21,21 +21,29 @@ def async_parameter_groups_service(async_http_client): def test_endpoint(parameter_groups_service): - assert parameter_groups_service.path == "/public/v1/catalog/products/PRD-001/parameter-groups" + result = parameter_groups_service.path == "/public/v1/catalog/products/PRD-001/parameter-groups" + + assert result is True def test_async_endpoint(async_parameter_groups_service): - assert ( + result = ( async_parameter_groups_service.path == "/public/v1/catalog/products/PRD-001/parameter-groups" ) + assert result is True + @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_methods_present(parameter_groups_service, method): - assert hasattr(parameter_groups_service, method) + result = hasattr(parameter_groups_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_async_methods_present(async_parameter_groups_service, method): - assert hasattr(async_parameter_groups_service, method) + result = hasattr(async_parameter_groups_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_products_parameters.py b/tests/unit/resources/catalog/test_products_parameters.py index 407dac82..fb669d64 100644 --- a/tests/unit/resources/catalog/test_products_parameters.py +++ b/tests/unit/resources/catalog/test_products_parameters.py @@ -19,18 +19,26 @@ def async_parameters_service(async_http_client): def test_endpoint(parameters_service): - assert parameters_service.path == "/public/v1/catalog/products/PRD-001/parameters" + result = parameters_service.path == "/public/v1/catalog/products/PRD-001/parameters" + + assert result is True def test_async_endpoint(async_parameters_service): - assert async_parameters_service.path == "/public/v1/catalog/products/PRD-001/parameters" + result = async_parameters_service.path == "/public/v1/catalog/products/PRD-001/parameters" + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_methods_present(parameters_service, method): - assert hasattr(parameters_service, method) + result = hasattr(parameters_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_async_methods_present(async_parameters_service, method): - assert hasattr(async_parameters_service, method) + result = hasattr(async_parameters_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_products_templates.py b/tests/unit/resources/catalog/test_products_templates.py index a19309f7..9c2443f8 100644 --- a/tests/unit/resources/catalog/test_products_templates.py +++ b/tests/unit/resources/catalog/test_products_templates.py @@ -19,18 +19,26 @@ def async_templates_service(async_http_client): def test_endpoint(templates_service): - assert templates_service.path == "/public/v1/catalog/products/PRD-001/templates" + result = templates_service.path == "/public/v1/catalog/products/PRD-001/templates" + + assert result is True def test_async_endpoint(async_templates_service): - assert async_templates_service.path == "/public/v1/catalog/products/PRD-001/templates" + result = async_templates_service.path == "/public/v1/catalog/products/PRD-001/templates" + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "update", "fetch_page", "iterate"]) def test_methods_present(templates_service, method): - assert hasattr(templates_service, method) + result = hasattr(templates_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "update", "fetch_page", "iterate"]) def test_async_methods_present(async_templates_service, method): - assert hasattr(async_templates_service, method) + result = hasattr(async_templates_service, method) + + assert result is True diff --git a/tests/unit/resources/catalog/test_units_of_measure.py b/tests/unit/resources/catalog/test_units_of_measure.py index 5eb54582..572d1fa6 100644 --- a/tests/unit/resources/catalog/test_units_of_measure.py +++ b/tests/unit/resources/catalog/test_units_of_measure.py @@ -18,9 +18,13 @@ def async_units_of_measure_service(async_http_client): @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_mixins_present(units_of_measure_service, method): - assert hasattr(units_of_measure_service, method) + result = hasattr(units_of_measure_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_mixins_present(async_units_of_measure_service, method): - assert hasattr(async_units_of_measure_service, method) + result = hasattr(async_units_of_measure_service, method) + + assert result is True diff --git a/tests/unit/resources/commerce/test_agreements.py b/tests/unit/resources/commerce/test_agreements.py index 0d4726f0..d0ff100e 100644 --- a/tests/unit/resources/commerce/test_agreements.py +++ b/tests/unit/resources/commerce/test_agreements.py @@ -21,9 +21,9 @@ async def test_async_template(async_http_client): ) ) - template = await async_agreements_service.template("AGR-123") + result = await async_agreements_service.template("AGR-123") - assert template == template_content + assert result == template_content def test_template(http_client): @@ -39,38 +39,44 @@ def test_template(http_client): ) ) - markdown_template = agreements_service.template("AGR-123") + result = agreements_service.template("AGR-123") assert mock_route.called assert mock_route.call_count == 1 - assert markdown_template == "# Order Template\n\nThis is a markdown template." + assert result == "# Order Template\n\nThis is a markdown template." def test_attachments_service(http_client): agreements_service = AgreementsService(http_client=http_client) - attachments = agreements_service.attachments("AGR-123") + result = agreements_service.attachments("AGR-123") - assert isinstance(attachments, AgreementsAttachmentService) - assert attachments.endpoint_params == {"agreement_id": "AGR-123"} + assert isinstance(result, AgreementsAttachmentService) + assert result.endpoint_params == {"agreement_id": "AGR-123"} def test_async_attachments_service(http_client): agreements_service = AsyncAgreementsService(http_client=http_client) - attachments = agreements_service.attachments("AGR-123") + result = agreements_service.attachments("AGR-123") - assert isinstance(attachments, AsyncAgreementsAttachmentService) - assert attachments.endpoint_params == {"agreement_id": "AGR-123"} + assert isinstance(result, AsyncAgreementsAttachmentService) + assert result.endpoint_params == {"agreement_id": "AGR-123"} @pytest.mark.parametrize("method", ["create", "update", "get"]) def test_mixins_present(http_client, method): service = AgreementsService(http_client=http_client) - assert hasattr(service, method) + + result = hasattr(service, method) + + assert result is True @pytest.mark.parametrize("method", ["create", "update", "get"]) def test_async_mixins_present(async_http_client, method): service = AgreementsService(http_client=async_http_client) - assert hasattr(service, method) + + result = hasattr(service, method) + + assert result is True diff --git a/tests/unit/resources/commerce/test_agreements_attachments.py b/tests/unit/resources/commerce/test_agreements_attachments.py index f2f28554..20975975 100644 --- a/tests/unit/resources/commerce/test_agreements_attachments.py +++ b/tests/unit/resources/commerce/test_agreements_attachments.py @@ -21,18 +21,26 @@ def async_attachment_service(async_http_client) -> AsyncAgreementsAttachmentServ def test_endpoint(attachment_service) -> None: - assert attachment_service.path == "/public/v1/commerce/agreements/AGR-123/attachments" + result = attachment_service.path == "/public/v1/commerce/agreements/AGR-123/attachments" + + assert result is True def test_async_endpoint(async_attachment_service) -> None: - assert async_attachment_service.path == "/public/v1/commerce/agreements/AGR-123/attachments" + result = async_attachment_service.path == "/public/v1/commerce/agreements/AGR-123/attachments" + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "download"]) def test_methods_present(attachment_service, method: str) -> None: - assert hasattr(attachment_service, method) + result = hasattr(attachment_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "download"]) def test_async_methods_present(async_attachment_service, method: str) -> None: - assert hasattr(async_attachment_service, method) + result = hasattr(async_attachment_service, method) + + assert result is True diff --git a/tests/unit/resources/commerce/test_commerce.py b/tests/unit/resources/commerce/test_commerce.py index 873c1828..efaadd51 100644 --- a/tests/unit/resources/commerce/test_commerce.py +++ b/tests/unit/resources/commerce/test_commerce.py @@ -11,28 +11,27 @@ def test_commerce_init(http_client): - commerce = Commerce(http_client=http_client) + result = Commerce(http_client=http_client) - assert isinstance(commerce, Commerce) - assert commerce.http_client is http_client + assert isinstance(result, Commerce) + assert result.http_client is http_client def test_commerce_orders_multiple_calls(http_client): - commerce = Commerce(http_client=http_client) - - orders_service = commerce.orders - order_service_additional = commerce.orders + result = Commerce(http_client=http_client) + orders_service = result.orders + order_service_additional = result.orders assert orders_service is not order_service_additional assert isinstance(orders_service, OrdersService) assert isinstance(order_service_additional, OrdersService) def test_async_commerce_init(async_http_client: AsyncHTTPClient): - commerce = AsyncCommerce(http_client=async_http_client) + result = AsyncCommerce(http_client=async_http_client) - assert isinstance(commerce, AsyncCommerce) - assert commerce.http_client is async_http_client + assert isinstance(result, AsyncCommerce) + assert result.http_client is async_http_client @pytest.mark.parametrize( @@ -46,9 +45,9 @@ def test_async_commerce_init(async_http_client: AsyncHTTPClient): def test_commerce_properties(http_client, attr_name, expected): commerce = Commerce(http_client=http_client) - service = getattr(commerce, attr_name) + result = getattr(commerce, attr_name) - assert isinstance(service, expected) + assert isinstance(result, expected) @pytest.mark.parametrize( @@ -62,6 +61,6 @@ def test_commerce_properties(http_client, attr_name, expected): def test_async_commerce_properties(http_client, attr_name, expected): commerce = AsyncCommerce(http_client=http_client) - service = getattr(commerce, attr_name) + result = getattr(commerce, attr_name) - assert isinstance(service, expected) + assert isinstance(result, expected) diff --git a/tests/unit/resources/commerce/test_order_subcription.py b/tests/unit/resources/commerce/test_order_subcription.py index 8ef19ea4..7f1d8935 100644 --- a/tests/unit/resources/commerce/test_order_subcription.py +++ b/tests/unit/resources/commerce/test_order_subcription.py @@ -22,17 +22,25 @@ def async_subscription_service(async_http_client): @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_mixins_present(subscription_service, method): - assert hasattr(subscription_service, method) + result = hasattr(subscription_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_async_mixins_present(async_subscription_service, method): - assert hasattr(async_subscription_service, method) + result = hasattr(async_subscription_service, method) + + assert result is True def test_endpoint(subscription_service): - assert subscription_service.path == "/public/v1/commerce/orders/ORD-123/subscriptions" + result = subscription_service.path == "/public/v1/commerce/orders/ORD-123/subscriptions" + + assert result is True def test_async_endpoint(async_subscription_service): - assert async_subscription_service.path == "/public/v1/commerce/orders/ORD-123/subscriptions" + result = async_subscription_service.path == "/public/v1/commerce/orders/ORD-123/subscriptions" + + assert result is True diff --git a/tests/unit/resources/commerce/test_orders.py b/tests/unit/resources/commerce/test_orders.py index 4132210d..1a7c8308 100644 --- a/tests/unit/resources/commerce/test_orders.py +++ b/tests/unit/resources/commerce/test_orders.py @@ -42,14 +42,14 @@ def test_custom_resource_actions(orders_service, action, input_status): json=response_expected_data, ) ) - order = getattr(orders_service, action)("ORD-123", input_status) + + result = getattr(orders_service, action)("ORD-123", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert order.to_dict() == response_expected_data - assert isinstance(order, Order) + assert result.to_dict() == response_expected_data + assert isinstance(result, Order) @pytest.mark.parametrize( @@ -76,13 +76,13 @@ def test_custom_resource_actions_no_data(orders_service, action, input_status): ) ) - order = getattr(orders_service, action)("ORD-123") + result = getattr(orders_service, action)("ORD-123") assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.content == request_expected_content - assert order.to_dict() == response_expected_data - assert isinstance(order, Order) + assert result.to_dict() == response_expected_data + assert isinstance(result, Order) def test_notify(orders_service): @@ -98,7 +98,7 @@ def test_notify(orders_service): ) user_data = {"email": "user@example.com", "name": "John Doe"} - orders_service.notify("ORD-123", user_data) + orders_service.notify("ORD-123", user_data) # act assert mock_route.call_count == 1 request = mock_route.calls[0].request @@ -117,11 +117,11 @@ def test_template(orders_service): ) ) - markdown_template = orders_service.template("ORD-123") + result = orders_service.template("ORD-123") assert mock_route.called assert mock_route.call_count == 1 - assert markdown_template == "# Order Template\n\nThis is a markdown template." + assert result == "# Order Template\n\nThis is a markdown template." @pytest.mark.parametrize( @@ -147,14 +147,14 @@ async def test_async_custom_resource_actions(async_orders_service, action, input json=response_expected_data, ) ) - order = await getattr(async_orders_service, action)("ORD-123", input_status) + + result = await getattr(async_orders_service, action)("ORD-123", input_status) assert mock_route.call_count == 1 request = mock_route.calls[0].request - assert request.content == request_expected_content - assert order.to_dict() == response_expected_data - assert isinstance(order, Order) + assert result.to_dict() == response_expected_data + assert isinstance(result, Order) @pytest.mark.parametrize( @@ -180,13 +180,14 @@ async def test_async_custom_resource_actions_nodata(async_orders_service, action json=response_expected_data, ) ) - order = await getattr(async_orders_service, action)("ORD-123") + + result = await getattr(async_orders_service, action)("ORD-123") assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.content == request_expected_content - assert order.to_dict() == response_expected_data - assert isinstance(order, Order) + assert result.to_dict() == response_expected_data + assert isinstance(result, Order) async def test_async_notify(async_orders_service): @@ -202,7 +203,7 @@ async def test_async_notify(async_orders_service): ) user_data = {"email": "user@example.com", "name": "John Doe"} - await async_orders_service.notify("ORD-123", user_data) + await async_orders_service.notify("ORD-123", user_data) # act assert mock_route.call_count == 1 request = mock_route.calls[0].request @@ -220,34 +221,38 @@ async def test_async_template(async_orders_service): ) ) - template = await async_orders_service.template("ORD-123") + result = await async_orders_service.template("ORD-123") - assert template == template_content + assert result == template_content def test_subscription_service(http_client): orders_service = OrdersService(http_client=http_client) - subscriptions = orders_service.subscriptions("ORD-123") + result = orders_service.subscriptions("ORD-123") - assert isinstance(subscriptions, OrderSubscriptionsService) - assert subscriptions.endpoint_params == {"order_id": "ORD-123"} + assert isinstance(result, OrderSubscriptionsService) + assert result.endpoint_params == {"order_id": "ORD-123"} def test_async_subscription_service(async_http_client): orders_service = AsyncOrdersService(http_client=async_http_client) - subscriptions = orders_service.subscriptions("ORD-123") + result = orders_service.subscriptions("ORD-123") - assert isinstance(subscriptions, AsyncOrderSubscriptionsService) - assert subscriptions.endpoint_params == {"order_id": "ORD-123"} + assert isinstance(result, AsyncOrderSubscriptionsService) + assert result.endpoint_params == {"order_id": "ORD-123"} @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_mixins_present(orders_service, method): - assert hasattr(orders_service, method) + result = hasattr(orders_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) def test_async_mixins_present(async_orders_service, method): - assert hasattr(async_orders_service, method) + result = hasattr(async_orders_service, method) + + assert result is True diff --git a/tests/unit/resources/commerce/test_subscriptions.py b/tests/unit/resources/commerce/test_subscriptions.py index c4c73030..54202c58 100644 --- a/tests/unit/resources/commerce/test_subscriptions.py +++ b/tests/unit/resources/commerce/test_subscriptions.py @@ -20,12 +20,16 @@ def async_subscriptions_service(async_http_client): @pytest.mark.parametrize("method", ["get", "create", "delete"]) def test_methods_present(subscriptions_service, method): - assert hasattr(subscriptions_service, method) + result = hasattr(subscriptions_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "delete"]) def test_async_methods_present(async_subscriptions_service, method): - assert hasattr(async_subscriptions_service, method) + result = hasattr(async_subscriptions_service, method) + + assert result is True async def test_async_terminate(async_subscriptions_service): @@ -75,11 +79,9 @@ def test_terminate(subscriptions_service): ) ) - subscription_updated = subscriptions_service.terminate( - "SUB-123", {"name": "Terminated SUB-123"} - ) + result = subscriptions_service.terminate("SUB-123", {"name": "Terminated SUB-123"}) - assert subscription_updated.to_dict() == subscription_expected + assert result.to_dict() == subscription_expected def test_render(subscriptions_service): @@ -93,6 +95,6 @@ def test_render(subscriptions_service): ) ) - template = subscriptions_service.render("SUB-123") + result = subscriptions_service.render("SUB-123") - assert template == template_content + assert result == template_content diff --git a/tests/unit/resources/notifications/test_batches.py b/tests/unit/resources/notifications/test_batches.py index 810376dd..a58da31e 100644 --- a/tests/unit/resources/notifications/test_batches.py +++ b/tests/unit/resources/notifications/test_batches.py @@ -22,12 +22,16 @@ def async_batches_service(async_http_client): @pytest.mark.parametrize("method", ["get", "create", "iterate", "get_batch_attachment"]) def test_sync_batches_service_methods(batches_service, method): - assert hasattr(batches_service, method) + result = hasattr(batches_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "create", "iterate", "get_batch_attachment"]) def test_async_batches_service_methods(async_batches_service, method): - assert hasattr(async_batches_service, method) + result = hasattr(async_batches_service, method) + + assert result is True def test_sync_get_batch_attachment(batches_service): @@ -47,12 +51,13 @@ def test_sync_get_batch_attachment(batches_service): content=attachment_content, ) ) - downloaded_file = batches_service.get_batch_attachment("BAT-123", "ATT-456") + + result = batches_service.get_batch_attachment("BAT-123", "ATT-456") assert mock_route.call_count == 1 - assert downloaded_file.file_contents == attachment_content - assert downloaded_file.content_type == "application/octet-stream" - assert downloaded_file.filename == "batch_attachment.pdf" + assert result.file_contents == attachment_content + assert result.content_type == "application/octet-stream" + assert result.filename == "batch_attachment.pdf" @pytest.mark.asyncio @@ -73,12 +78,13 @@ async def test_async_get_batch_attachment(async_batches_service): content=attachment_content, ) ) - downloaded_file = await async_batches_service.get_batch_attachment("BAT-123", "ATT-456") + + result = await async_batches_service.get_batch_attachment("BAT-123", "ATT-456") assert mock_route.call_count == 1 - assert downloaded_file.file_contents == attachment_content - assert downloaded_file.content_type == "application/octet-stream" - assert downloaded_file.filename == "batch_attachment.pdf" + assert result.file_contents == attachment_content + assert result.content_type == "application/octet-stream" + assert result.filename == "batch_attachment.pdf" def test_sync_batches_create_with_data(batches_service): @@ -91,12 +97,14 @@ def test_sync_batches_create_with_data(batches_service): ) ) files = {"attachment": ("test.pdf", io.BytesIO(b"PDF content"), "application/pdf")} - new_batch = batches_service.create(batch_data, files=files) + + result = batches_service.create(batch_data, files=files) + request = mock_route.calls[0].request assert b'Content-Disposition: form-data; name="_attachment_data"' in request.content assert mock_route.call_count == 1 - assert new_batch.id == "BAT-133" - assert new_batch.name == "Test Batch" + assert result.id == "BAT-133" + assert result.name == "Test Batch" @pytest.mark.asyncio @@ -110,9 +118,11 @@ async def test_async_batches_create_with_data(async_batches_service): ) ) files = {"attachment": ("test.pdf", io.BytesIO(b"PDF content"), "application/pdf")} - new_batch = await async_batches_service.create(batch_data, files=files) + + result = await async_batches_service.create(batch_data, files=files) + request = mock_route.calls[0].request assert b'Content-Disposition: form-data; name="_attachment_data"' in request.content assert mock_route.call_count == 1 - assert new_batch.id == "BAT-133" - assert new_batch.name == "Test Batch" + assert result.id == "BAT-133" + assert result.name == "Test Batch" diff --git a/tests/unit/resources/notifications/test_categories.py b/tests/unit/resources/notifications/test_categories.py index 58bc9ed7..4633d3f1 100644 --- a/tests/unit/resources/notifications/test_categories.py +++ b/tests/unit/resources/notifications/test_categories.py @@ -38,10 +38,11 @@ def test_custom_category_actions(categories_service, action, input_status): json=response_expected_data, ) ) - category = getattr(categories_service, action)("CAT-123", input_status) + + result = getattr(categories_service, action)("CAT-123", input_status) assert mock_route.call_count == 1 - assert category.to_dict() == response_expected_data + assert result.to_dict() == response_expected_data request = mock_route.calls[0].request assert request.content == request_expected_content @@ -66,9 +67,10 @@ async def test_async_custom_category_actions(async_categories_service, action, i json=response_expected_data, ) ) - category = await getattr(async_categories_service, action)("CAT-123", input_status) - assert category.to_dict() == response_expected_data + result = await getattr(async_categories_service, action)("CAT-123", input_status) + + assert result.to_dict() == response_expected_data assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.content == request_expected_content diff --git a/tests/unit/resources/notifications/test_contacts.py b/tests/unit/resources/notifications/test_contacts.py index 1549caa7..f5906c0e 100644 --- a/tests/unit/resources/notifications/test_contacts.py +++ b/tests/unit/resources/notifications/test_contacts.py @@ -38,10 +38,11 @@ def test_custom_contact_actions(contacts_service, action, input_status): json=response_expected_data, ) ) - contact = getattr(contacts_service, action)("CON-123", input_status) + + result = getattr(contacts_service, action)("CON-123", input_status) assert mock_route.call_count == 1 - assert contact.to_dict() == response_expected_data + assert result.to_dict() == response_expected_data request = mock_route.calls[0].request assert request.content == request_expected_content @@ -66,9 +67,10 @@ async def test_async_custom_contact_actions(async_contacts_service, action, inpu json=response_expected_data, ) ) - contact = await getattr(async_contacts_service, action)("CON-123", input_status) - assert contact.to_dict() == response_expected_data + result = await getattr(async_contacts_service, action)("CON-123", input_status) + + assert result.to_dict() == response_expected_data assert mock_route.call_count == 1 request = mock_route.calls[0].request assert request.content == request_expected_content diff --git a/tests/unit/resources/notifications/test_messages.py b/tests/unit/resources/notifications/test_messages.py index 64aaa717..1d622382 100644 --- a/tests/unit/resources/notifications/test_messages.py +++ b/tests/unit/resources/notifications/test_messages.py @@ -17,18 +17,26 @@ def async_messages_service(async_http_client): def test_messages_service_instance(messages_service): - assert isinstance(messages_service, MessagesService) + result = isinstance(messages_service, MessagesService) + + assert result is True def test_async_messages_service_instance(async_messages_service): - assert isinstance(async_messages_service, AsyncMessagesService) + result = isinstance(async_messages_service, AsyncMessagesService) + + assert result is True @pytest.mark.parametrize("method", ["get", "iterate"]) def test_sync_messages_service_methods(messages_service, method): - assert hasattr(messages_service, method) + result = hasattr(messages_service, method) + + assert result is True @pytest.mark.parametrize("method", ["get", "iterate"]) def test_async_messages_service_methods(async_messages_service, method): - assert hasattr(async_messages_service, method) + result = hasattr(async_messages_service, method) + + assert result is True diff --git a/tests/unit/resources/notifications/test_notifications.py b/tests/unit/resources/notifications/test_notifications.py index 16344157..cdf3270b 100644 --- a/tests/unit/resources/notifications/test_notifications.py +++ b/tests/unit/resources/notifications/test_notifications.py @@ -16,17 +16,17 @@ def test_notifications_init(http_client): - commerce = Notifications(http_client=http_client) + result = Notifications(http_client=http_client) - assert isinstance(commerce, Notifications) - assert commerce.http_client is http_client + assert isinstance(result, Notifications) + assert result.http_client is http_client def test_async_notifications_init(async_http_client): - notifications = AsyncNotifications(http_client=async_http_client) + result = AsyncNotifications(http_client=async_http_client) - assert isinstance(notifications, AsyncNotifications) - assert notifications.http_client is async_http_client + assert isinstance(result, AsyncNotifications) + assert result.http_client is async_http_client @pytest.mark.parametrize( @@ -42,9 +42,9 @@ def test_async_notifications_init(async_http_client): def test_notifications_properties(http_client, attr_name, expected): notifications = Notifications(http_client=http_client) - service = getattr(notifications, attr_name) + result = getattr(notifications, attr_name) - assert isinstance(service, expected) + assert isinstance(result, expected) @pytest.mark.parametrize( @@ -60,24 +60,28 @@ def test_notifications_properties(http_client, attr_name, expected): def test_async_notifications_properties(http_client, attr_name, expected): notifications = AsyncNotifications(http_client=http_client) - service = getattr(notifications, attr_name) + result = getattr(notifications, attr_name) - assert isinstance(service, expected) + assert isinstance(result, expected) def test_notifications_accounts(http_client): notifications = Notifications(http_client=http_client) account_id = "ACC-123" category_id = "CAT-456" - service = notifications.accounts(account_id, category_id) - assert isinstance(service, AccountsService) - assert service.endpoint_params == {"account_id": account_id, "category_id": category_id} + + result = notifications.accounts(account_id, category_id) + + assert isinstance(result, AccountsService) + assert result.endpoint_params == {"account_id": account_id, "category_id": category_id} def test_async_notifications_accounts(async_http_client): notifications = AsyncNotifications(http_client=async_http_client) account_id = "ACC-123" category_id = "CAT-456" - service = notifications.accounts(account_id, category_id) - assert isinstance(service, AsyncAccountsService) - assert service.endpoint_params == {"account_id": account_id, "category_id": category_id} + + result = notifications.accounts(account_id, category_id) + + assert isinstance(result, AsyncAccountsService) + assert result.endpoint_params == {"account_id": account_id, "category_id": category_id} diff --git a/tests/unit/resources/notifications/test_subscribers.py b/tests/unit/resources/notifications/test_subscribers.py index faaec941..b99bbdcc 100644 --- a/tests/unit/resources/notifications/test_subscribers.py +++ b/tests/unit/resources/notifications/test_subscribers.py @@ -18,9 +18,13 @@ def async_subscribers_service(async_http_client): @pytest.mark.parametrize("method", ["create", "update", "delete", "get", "iterate"]) def test_mixins_present(subscribers_service, method): - assert hasattr(subscribers_service, method) + result = hasattr(subscribers_service, method) + + assert result is True @pytest.mark.parametrize("method", ["create", "update", "delete", "get", "iterate"]) def test_async_mixins_present(async_subscribers_service, method): - assert hasattr(async_subscribers_service, method) + result = hasattr(async_subscribers_service, method) + + assert result is True diff --git a/tests/unit/rql/query_builder/test_create_rql.py b/tests/unit/rql/query_builder/test_create_rql.py index b290cb4c..08f6e9cd 100644 --- a/tests/unit/rql/query_builder/test_create_rql.py +++ b/tests/unit/rql/query_builder/test_create_rql.py @@ -2,78 +2,72 @@ def test_create(): - query = RQLQuery() + result = RQLQuery() - assert query.op == RQLQuery.OP_EXPRESSION - assert query.children == [] - assert query.negated is False + assert result.op == RQLQuery.OP_EXPRESSION + assert result.children == [] + assert result.negated is False def test_create_with_field(): query = RQLQuery("field") - query.eq("value") + query.eq("value") # act assert query.op == RQLQuery.OP_EXPRESSION assert str(query) == "eq(field,value)" def test_create_single_kwarg(): - query = RQLQuery(id="ID") + result = RQLQuery(id="ID") - assert query.op == RQLQuery.OP_EXPRESSION - assert str(query) == "eq(id,ID)" - assert query.children == [] - assert query.negated is False + assert result.op == RQLQuery.OP_EXPRESSION + assert str(result) == "eq(id,ID)" + assert result.children == [] + assert result.negated is False def test_create_multiple_kwargs(): # noqa: WPS218 - query = RQLQuery(id="ID", status__in=("a", "b"), ok=True) - - assert query.op == RQLQuery.OP_AND - assert str(query) == "and(eq(id,ID),in(status,(a,b)),eq(ok,true))" - assert len(query.children) == 3 - assert query.children[0].op == RQLQuery.OP_EXPRESSION - assert query.children[0].children == [] - assert str(query.children[0]) == "eq(id,ID)" - assert query.children[1].op == RQLQuery.OP_EXPRESSION - assert query.children[1].children == [] - assert str(query.children[1]) == "in(status,(a,b))" - assert query.children[2].op == RQLQuery.OP_EXPRESSION - assert query.children[2].children == [] - assert str(query.children[2]) == "eq(ok,true)" + result = RQLQuery(id="ID", status__in=("a", "b"), ok=True) + + assert result.op == RQLQuery.OP_AND + assert str(result) == "and(eq(id,ID),in(status,(a,b)),eq(ok,true))" + assert len(result.children) == 3 + assert result.children[0].op == RQLQuery.OP_EXPRESSION + assert result.children[0].children == [] + assert str(result.children[0]) == "eq(id,ID)" + assert result.children[1].op == RQLQuery.OP_EXPRESSION + assert result.children[1].children == [] + assert str(result.children[1]) == "in(status,(a,b))" + assert result.children[2].op == RQLQuery.OP_EXPRESSION + assert result.children[2].children == [] + assert str(result.children[2]) == "eq(ok,true)" def test_new_empty(): - query = RQLQuery.new() + result = RQLQuery.new() - assert query.op == RQLQuery.OP_EXPRESSION - assert query.children == [] - assert query.negated is False + assert result.op == RQLQuery.OP_EXPRESSION + assert result.children == [] + assert result.negated is False def test_new_with_parameters(): project_rql = RQLQuery.new("project=rql") status_not_done = RQLQuery.new("status=done", negated=True) - query = RQLQuery.new( - op=RQLQuery.OP_AND, - children=[project_rql, status_not_done], - ) + result = RQLQuery.new(op=RQLQuery.OP_AND, children=[project_rql, status_not_done]) - assert str(query) == "and(project=rql,not(status=done))" + assert str(result) == "and(project=rql,not(status=done))" def test_new_with_set(): project_rql = RQLQuery.new("project=rql") status_not_done = RQLQuery.new("status=done", negated=True) - query = RQLQuery.new( - op=RQLQuery.OP_AND, - children={project_rql, status_not_done}, - ) + result = RQLQuery.new(op=RQLQuery.OP_AND, children={project_rql, status_not_done}) - assert isinstance(query.children, list) - assert len(query.children) == 2 - assert project_rql in query.children - assert status_not_done in query.children + assert isinstance(result.children, list) + assert len(result.children) == 2 + assert project_rql in result.children + assert status_not_done in result.children diff --git a/tests/unit/rql/query_builder/test_multiple_ops.py b/tests/unit/rql/query_builder/test_multiple_ops.py index e7e09def..c724773c 100644 --- a/tests/unit/rql/query_builder/test_multiple_ops.py +++ b/tests/unit/rql/query_builder/test_multiple_ops.py @@ -1,7 +1,7 @@ from mpt_api_client.rql import RQLQuery -def test_and_or(): # noqa: WPS218 WPS473 +def test_and_or(): # noqa: WPS218 WPS473 AAA01 r1 = RQLQuery(id="ID") r2 = RQLQuery(field="value") @@ -30,7 +30,7 @@ def test_and_or(): # noqa: WPS218 WPS473 assert str(r5) == "or(and(eq(id,ID),eq(field,value)),not(eq(other,value2)))" -def test_and_merge(): # noqa: WPS210 +def test_and_merge(): # noqa: WPS210 AAA01 r1 = RQLQuery(id="ID") r2 = RQLQuery(name="name") diff --git a/tests/unit/rql/query_builder/test_rql.py b/tests/unit/rql/query_builder/test_rql.py index 5a97ab6f..5e393a18 100644 --- a/tests/unit/rql/query_builder/test_rql.py +++ b/tests/unit/rql/query_builder/test_rql.py @@ -1,7 +1,7 @@ from mpt_api_client.rql import RQLQuery -def test_repr(): +def test_repr(): # noqa: AAA01 products = ["PRD-1", "PRD-2"] product_ids = ",".join(products) expression_query = RQLQuery(product__id__in=products) @@ -11,7 +11,7 @@ def test_repr(): assert repr(or_expression) == "" -def test_len(): +def test_len(): # noqa: AAA01 empty_query = RQLQuery() simple_query = RQLQuery(id="ID") complex_query = RQLQuery(id="ID", status__in=("a", "b")) @@ -21,13 +21,13 @@ def test_len(): assert len(complex_query) == 2 -def test_bool(): +def test_bool(): # noqa: AAA01 assert bool(RQLQuery()) is False assert bool(RQLQuery(id="ID")) is True assert bool(RQLQuery(id="ID", status__in=("a", "b"))) is True -def test_str(): +def test_str(): # noqa: AAA01 assert str(RQLQuery(id="ID")) == "eq(id,ID)" assert str(~RQLQuery(id="ID")) == "not(eq(id,ID))" assert str(~RQLQuery(id="ID", field="value")) == "not(and(eq(id,ID),eq(field,value)))" @@ -37,15 +37,14 @@ def test_str(): def test_hash(): query_set = set() - rql = RQLQuery(id="ID", field="value") - - query_set.add(rql) - query_set.add(rql) + result = RQLQuery(id="ID", field="value") + query_set.add(result) + query_set.add(result) assert len(query_set) == 1 -def test_empty(): +def test_empty(): # noqa: AAA01 assert RQLQuery("value").empty() == RQLQuery("value").empty() assert str(RQLQuery("value1").empty()) == "eq(value1,empty())" assert str(RQLQuery("value2").not_empty()) == "ne(value2,empty())" diff --git a/tests/unit/rql/query_builder/test_rql_all_any.py b/tests/unit/rql/query_builder/test_rql_all_any.py index 9c8c67a0..ae0ea6a6 100644 --- a/tests/unit/rql/query_builder/test_rql_all_any.py +++ b/tests/unit/rql/query_builder/test_rql_all_any.py @@ -4,11 +4,14 @@ def test_all(): query = RQLQuery(saleDetails__orderQty__gt=1).all() - rql = str(query) - assert rql == "all(gt(saleDetails.orderQty,1))" + result = str(query) + + assert result == "all(gt(saleDetails.orderQty,1))" def test_any(): query = RQLQuery(saleDetails__orderQty__gt=1).any() - rql = str(query) - assert rql == "any(gt(saleDetails.orderQty,1))" + + result = str(query) + + assert result == "any(gt(saleDetails.orderQty,1))" diff --git a/tests/unit/rql/query_builder/test_rql_and.py b/tests/unit/rql/query_builder/test_rql_and.py index d9445a18..31204bc2 100644 --- a/tests/unit/rql/query_builder/test_rql_and.py +++ b/tests/unit/rql/query_builder/test_rql_and.py @@ -17,48 +17,48 @@ def test_and_both_empty(): r1 = RQLQuery() r2 = RQLQuery() - r3 = r1 & r2 + result = r1 & r2 - assert r3 == r1 - assert r3 == r2 + assert result == r1 + assert result == r2 def test_and_duplicates(): r1 = RQLQuery(id="ID") r2 = RQLQuery(id="ID") - r3 = r1 & r2 + result = r1 & r2 - assert r3 == r1 - assert r3 == r2 + assert result == r1 + assert result == r2 def test_and_different(): r1 = RQLQuery(id="ID") r2 = RQLQuery(name="name") - r3 = r1 & r2 + result = r1 & r2 - assert r3 != r1 - assert r3 != r2 - assert r3.op == RQLQuery.OP_AND - assert r1 in r3.children - assert r2 in r3.children + assert result != r1 + assert result != r2 + assert result.op == RQLQuery.OP_AND + assert r1 in result.children + assert r2 in result.children def test_and_with_empty(): - rql = RQLQuery(id="ID") + result = RQLQuery(id="ID") - assert rql & RQLQuery() == rql - assert RQLQuery() & rql == rql + assert result & RQLQuery() == result + assert RQLQuery() & result == result def test_and_triple(): r1 = RQLQuery(id="ID") r2 = RQLQuery(field="value") - r3 = r1 & r2 & r2 + result = r1 & r2 & r2 - assert len(r3) == 2 - assert r3.op == RQLQuery.OP_AND - assert [r1, r2] == r3.children + assert len(result) == 2 + assert result.op == RQLQuery.OP_AND + assert [r1, r2] == result.children diff --git a/tests/unit/rql/query_builder/test_rql_dot_path.py b/tests/unit/rql/query_builder/test_rql_dot_path.py index 89b4ff6c..a32c819a 100644 --- a/tests/unit/rql/query_builder/test_rql_dot_path.py +++ b/tests/unit/rql/query_builder/test_rql_dot_path.py @@ -11,28 +11,30 @@ def test_dotted_path_comp(op): class Test: # noqa: WPS431 pass # noqa: WPS604 WPS420 + # BL test = Test() today = dt.datetime.now(dt.UTC).date() now = dt.datetime.now(dt.UTC) - today_expected_result = f"{op}(asset.id,{today.isoformat()})" now_expected_result = f"{op}(asset.id,{now.isoformat()})" - assert str(getattr(RQLQuery().asset.id, op)(today)) == today_expected_result - assert str(getattr(RQLQuery().asset.id, op)(now)) == now_expected_result with pytest.raises(TypeError): getattr(RQLQuery().asset.id, op)(test) + assert str(getattr(RQLQuery().asset.id, op)(today)) == today_expected_result + assert str(getattr(RQLQuery().asset.id, op)(now)) == now_expected_result + @pytest.mark.parametrize("op", ["eq", "ne", "gt", "ge", "le", "lt"]) def test_dotted_path_comp_bool_and_str(op): - attribute_op_match = getattr(RQLQuery().asset.id, op) - assert str(attribute_op_match("value")) == f"{op}(asset.id,value)" - assert str(attribute_op_match(True)) == f"{op}(asset.id,true)" # noqa: FBT003 - assert str(attribute_op_match(False)) == f"{op}(asset.id,false)" # noqa: FBT003 + result = getattr(RQLQuery().asset.id, op) + assert str(result("value")) == f"{op}(asset.id,value)" + assert str(result(True)) == f"{op}(asset.id,true)" # noqa: FBT003 + assert str(result(False)) == f"{op}(asset.id,false)" # noqa: FBT003 -@pytest.mark.parametrize("op", ["eq", "ne", "gt", "ge", "le", "lt"]) + +@pytest.mark.parametrize("op", ["eq", "ne", "gt", "ge", "le", "lt"]) # noqa: AAA01 def test_dotted_path_comp_numerics(op): decimal_object = Decimal("32983.328238273") attribute_op_match = getattr(RQLQuery().asset.id, op) @@ -48,11 +50,12 @@ def test_dotted_path_comp_numerics(op): @pytest.mark.parametrize("op", ["like", "ilike"]) def test_dotted_path_search(op): - attribute_op_match = getattr(RQLQuery().asset.id, op) - assert str(attribute_op_match("value")) == f"{op}(asset.id,value)" - assert str(attribute_op_match("*value")) == f"{op}(asset.id,*value)" - assert str(attribute_op_match("value*")) == f"{op}(asset.id,value*)" - assert str(attribute_op_match("*value*")) == f"{op}(asset.id,*value*)" + result = getattr(RQLQuery().asset.id, op) + + assert str(result("value")) == f"{op}(asset.id,value)" + assert str(result("*value")) == f"{op}(asset.id,*value)" + assert str(result("value*")) == f"{op}(asset.id,value*)" + assert str(result("*value*")) == f"{op}(asset.id,*value*)" @pytest.mark.parametrize( @@ -63,15 +66,16 @@ def test_dotted_path_search(op): ("out", "out"), ], ) -def test_dotted_path_list(method, op): +def test_dotted_path_list(method, op): # noqa: AAA01 rexpr_set = getattr(RQLQuery().asset.id, method)(("first", "second")) rexpr_list = getattr(RQLQuery().asset.id, method)(["first", "second"]) - assert str(rexpr_set) == f"{op}(asset.id,(first,second))" - assert str(rexpr_list) == f"{op}(asset.id,(first,second))" with pytest.raises(TypeError): getattr(RQLQuery().asset.id, method)("Test") + assert str(rexpr_set) == f"{op}(asset.id,(first,second))" + assert str(rexpr_list) == f"{op}(asset.id,(first,second))" + @pytest.mark.parametrize( ("expr", "expression_param", "expected_op"), @@ -85,9 +89,10 @@ def test_dotted_path_list(method, op): def test_dotted_path_bool(expr, expression_param, expected_op): expected_result = f"{expected_op}(asset.id,{expr}())" attribute = getattr(RQLQuery().asset.id, expr) - result_dotted_path = str(attribute(expression_param)) - assert result_dotted_path == expected_result + result = str(attribute(expression_param)) + + assert result == expected_result def test_dotted_path_already_evaluated(): diff --git a/tests/unit/rql/query_builder/test_rql_eq.py b/tests/unit/rql/query_builder/test_rql_eq.py index 42bea867..9b8e18f5 100644 --- a/tests/unit/rql/query_builder/test_rql_eq.py +++ b/tests/unit/rql/query_builder/test_rql_eq.py @@ -7,39 +7,51 @@ def test_eq_object(): r1 = RQLQuery(id="ID") r2 = Decimal("32983.328238273") - assert r1 != r2 + result = r1 != r2 + + assert result is True def test_eq_empty(): r1 = RQLQuery() r2 = RQLQuery() - assert r1 == r2 + result = r1 == r2 + + assert result is True def test_eq_id(): r1 = RQLQuery(id="ID") r2 = RQLQuery(id="ID") - assert r1 == r2 + result = r1 == r2 + + assert result is True def test_eq_id_negated(): r1 = ~RQLQuery(id="ID") r2 = ~RQLQuery(id="ID") - assert r1 == r2 + result = r1 == r2 + + assert result is True def test_eq_status_in(): r1 = RQLQuery(id="ID", status__in=("a", "b")) r2 = RQLQuery(id="ID", status__in=("a", "b")) - assert r1 == r2 + result = r1 == r2 + + assert result is True def test_not_eq_status_in(): r1 = RQLQuery() r2 = RQLQuery(id="ID", status__in=("a", "b")) - assert r1 != r2 + result = r1 != r2 + + assert result is True diff --git a/tests/unit/rql/query_builder/test_rql_from_str.py b/tests/unit/rql/query_builder/test_rql_from_str.py index 29a76db8..bc704831 100644 --- a/tests/unit/rql/query_builder/test_rql_from_str.py +++ b/tests/unit/rql/query_builder/test_rql_from_str.py @@ -4,6 +4,6 @@ def test_rql_from_str(): str_query = "eq(id,ID)" - rql = RQLQuery.from_string(str_query) + result = RQLQuery.from_string(str_query) - assert str(rql) == str_query + assert str(result) == str_query diff --git a/tests/unit/rql/query_builder/test_rql_in.py b/tests/unit/rql/query_builder/test_rql_in.py index 438e993a..196fb6d6 100644 --- a/tests/unit/rql/query_builder/test_rql_in.py +++ b/tests/unit/rql/query_builder/test_rql_in.py @@ -5,12 +5,15 @@ def test_in_and_namespaces(): q1 = RQLQuery().n("agreement").n("product").n("id").in_(["PRD-1", "PRD-2"]) # noqa: WPS221 q2 = RQLQuery().agreement.product.id.in_(["PRD-1", "PRD-2"]) - assert str(q1) == str(q2) + result = str(q1) == str(q2) + + assert result is True def test_in(): products = ["PRD-1", "PRD-2"] product_ids = ",".join(products) - query = RQLQuery(product__id__in=products) - assert str(query) == f"in(product.id,({product_ids}))" + result = RQLQuery(product__id__in=products) + + assert str(result) == f"in(product.id,({product_ids}))" diff --git a/tests/unit/rql/query_builder/test_rql_or.py b/tests/unit/rql/query_builder/test_rql_or.py index 1dcaee7b..29fe4ffb 100644 --- a/tests/unit/rql/query_builder/test_rql_or.py +++ b/tests/unit/rql/query_builder/test_rql_or.py @@ -9,10 +9,10 @@ def test_or_empty(): r1 = RQLQuery() r2 = RQLQuery() - r3 = r1 | r2 + result = r1 | r2 - assert r3 == r1 - assert r3 == r2 + assert result == r1 + assert result == r2 def test_or_types(): @@ -27,55 +27,53 @@ def test_or_equals(): r1 = RQLQuery(id="ID") r2 = RQLQuery(id="ID") - r3 = r1 | r2 + result = r1 | r2 - assert r3 == r1 - assert r3 == r2 + assert result == r1 + assert result == r2 def test_or_not_equals(): r1 = RQLQuery(id="ID") r2 = RQLQuery(name="name") - r3 = r1 | r2 + result = r1 | r2 - assert r3 != r1 - assert r3 != r2 - - assert r3.op == RQLQuery.OP_OR - assert r1 in r3.children - assert r2 in r3.children + assert result != r1 + assert result != r2 + assert result.op == RQLQuery.OP_OR + assert r1 in result.children + assert r2 in result.children def test_or_with_empty(): - rql = RQLQuery(id="ID") + result = RQLQuery(id="ID") - assert rql | RQLQuery() == rql - assert RQLQuery() | rql == rql + assert result | RQLQuery() == result + assert RQLQuery() | result == result def test_or_merge(): # noqa: WPS210 r1 = RQLQuery(id="ID") r2 = RQLQuery(name="name") - r3 = RQLQuery(field="value") r4 = RQLQuery(field__in=("v1", "v2")) - or1 = r1 | r2 or2 = r3 | r4 - or3 = or1 | or2 - assert or3.op == RQLQuery.OP_OR - assert len(or3.children) == 4 - assert [r1, r2, r3, r4] == or3.children + result = or1 | or2 + + assert result.op == RQLQuery.OP_OR + assert len(result.children) == 4 + assert [r1, r2, r3, r4] == result.children def test_or_merge_duplicates(): r1 = RQLQuery(id="ID") r2 = RQLQuery(field="value") - r3 = r1 | r2 | r2 + result = r1 | r2 | r2 - assert len(r3) == 2 - assert r3.op == RQLQuery.OP_OR - assert [r1, r2] == r3.children + assert len(result) == 2 + assert result.op == RQLQuery.OP_OR + assert [r1, r2] == result.children diff --git a/tests/unit/rql/query_builder/test_rql_parse_kwargs.py b/tests/unit/rql/query_builder/test_rql_parse_kwargs.py index 08e5aeb4..b6160eb6 100644 --- a/tests/unit/rql/query_builder/test_rql_parse_kwargs.py +++ b/tests/unit/rql/query_builder/test_rql_parse_kwargs.py @@ -15,27 +15,31 @@ def mock_product_id_for_expression(): def test_improper_op(mock_product_id_for_expression): products_expr = {"product__id__inn": mock_product_id_for_expression} - query = parse_kwargs(products_expr) - assert str(query) == f"['eq(product.id.inn,{mock_product_id_for_expression})']" + result = parse_kwargs(products_expr) + + assert str(result) == f"['eq(product.id.inn,{mock_product_id_for_expression})']" def test_parse_eq(mock_product_id_for_expression): products_expr = {"product__id__eq": mock_product_id_for_expression} - query = parse_kwargs(products_expr) - assert str(query) == f"['eq(product.id,{mock_product_id_for_expression})']" + result = parse_kwargs(products_expr) + + assert str(result) == f"['eq(product.id,{mock_product_id_for_expression})']" def test_parse_like(mock_product_id_for_expression): products_expr = {"product__id__like": mock_product_id_for_expression} - query = parse_kwargs(products_expr) - assert str(query) == f"['like(product.id,{mock_product_id_for_expression})']" + result = parse_kwargs(products_expr) + + assert str(result) == f"['like(product.id,{mock_product_id_for_expression})']" def test_parse_null_op(mock_product_id_for_expression): products_expr = {"product__id__null": mock_product_id_for_expression} - query = parse_kwargs(products_expr) - assert str(query) == "['ne(product.id,null())']" + result = parse_kwargs(products_expr) + + assert str(result) == "['ne(product.id,null())']" diff --git a/tests/unit/test_constants.py b/tests/unit/test_constants.py index 387ed128..60e54fbc 100644 --- a/tests/unit/test_constants.py +++ b/tests/unit/test_constants.py @@ -2,4 +2,6 @@ def test_expected_constants(): - assert APPLICATION_JSON == "application/json" + result = APPLICATION_JSON + + assert result == "application/json" diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py index 235728e9..8cadd388 100644 --- a/tests/unit/test_exceptions.py +++ b/tests/unit/test_exceptions.py @@ -10,11 +10,11 @@ def test_http_error(): - exception = MPTHttpError(status_code=400, message="Bad request", body="Content") + result = MPTHttpError(status_code=400, message="Bad request", body="Content") - assert exception.status_code == 400 - assert exception.body == "Content" - assert str(exception) == "HTTP 400: Bad request" + assert result.status_code == 400 + assert result.body == "Content" + assert str(result) == "HTTP 400: Bad request" def test_http_error_not_found_from_mpt(): # noqa: WPS218 @@ -28,16 +28,16 @@ def test_http_error_not_found_from_mpt(): # noqa: WPS218 "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404" ) - exception = MPTAPIError(status_code=status_code, message=message, payload=payload) + result = MPTAPIError(status_code=status_code, message=message, payload=payload) - assert exception.status_code == status_code - assert exception.payload == payload - assert exception.status == api_status_code - assert exception.title == "Resource not found" - assert exception.detail == message - assert exception.trace_id is None - assert exception.errors is None - assert str(exception) == f"404 Resource not found - {message} (no-trace-id)" + assert result.status_code == status_code + assert result.payload == payload + assert result.status == api_status_code + assert result.title == "Resource not found" + assert result.detail == message + assert result.trace_id is None + assert result.errors is None + assert str(result) == f"404 Resource not found - {message} (no-trace-id)" def test_api_error(): # noqa: WPS218 @@ -48,15 +48,16 @@ def test_api_error(): # noqa: WPS218 "traceId": "abc123", "errors": "Some error details", } - exception = MPTAPIError(status_code=400, message="Bad Request", payload=payload) - assert exception.status_code == 400 - assert exception.payload == payload - assert exception.status == "400" - assert exception.title == "Bad Request" - assert exception.detail == "Invalid input" - assert exception.trace_id == "abc123" - assert exception.errors == "Some error details" + result = MPTAPIError(status_code=400, message="Bad Request", payload=payload) + + assert result.status_code == 400 + assert result.payload == payload + assert result.status == "400" + assert result.title == "Bad Request" + assert result.detail == "Invalid input" + assert result.trace_id == "abc123" + assert result.errors == "Some error details" def test_api_error_str_and_repr(): @@ -67,10 +68,11 @@ def test_api_error_str_and_repr(): "traceId": "abc123", "errors": "Some error details", } - exception = MPTAPIError(status_code=400, message="Bad request", payload=payload) - assert str(exception) == '400 Bad Request - Invalid input (abc123)\n"Some error details"' - assert repr(exception) == ( + result = MPTAPIError(status_code=400, message="Bad request", payload=payload) + + assert str(result) == '400 Bad Request - Invalid input (abc123)\n"Some error details"' + assert repr(result) == ( "{'status': '400', 'title': 'Bad Request', 'detail': 'Invalid input', " "'traceId': 'abc123', 'errors': 'Some error details'}" ) @@ -84,9 +86,9 @@ def test_api_error_str_no_errors(): "traceId": "abc123", } - exception = MPTAPIError(status_code=400, message="Bad request", payload=payload) + result = MPTAPIError(status_code=400, message="Bad request", payload=payload) - assert str(exception) == "400 Bad Request - Invalid input (abc123)" + assert str(result) == "400 Bad Request - Invalid input (abc123)" def test_transform_http_status_exception_api(): @@ -105,11 +107,11 @@ def test_transform_http_status_exception_api(): ) exc = HTTPStatusError("error", request=response.request, response=response) - err = transform_http_status_exception(exc) + result = transform_http_status_exception(exc) - assert isinstance(err, MPTAPIError) - assert err.status_code == 400 - assert err.payload == payload + assert isinstance(result, MPTAPIError) + assert result.status_code == 400 + assert result.payload == payload def test_transform_http_status_exception(): @@ -121,9 +123,9 @@ def test_transform_http_status_exception(): ) exc = HTTPStatusError("Error message", request=response.request, response=response) - err = transform_http_status_exception(exc) + result = transform_http_status_exception(exc) - assert isinstance(err, MPTHttpError) - assert err.status_code == 500 - assert err.body == "Internal Server Error" - assert str(err) == "HTTP 500: Error message" + assert isinstance(result, MPTHttpError) + assert result.status_code == 500 + assert result.body == "Internal Server Error" + assert str(result) == "HTTP 500: Error message" diff --git a/tests/unit/test_mpt_client.py b/tests/unit/test_mpt_client.py index 03dabee2..25af1fef 100644 --- a/tests/unit/test_mpt_client.py +++ b/tests/unit/test_mpt_client.py @@ -36,19 +36,21 @@ def get_mpt_client(): ) def test_mpt_client(resource_name: str, expected_type: type) -> None: mpt = MPTClient.from_config(base_url=API_URL, api_token=API_TOKEN) - resource = getattr(mpt, resource_name) + + result = getattr(mpt, resource_name) + assert isinstance(mpt, MPTClient) - assert isinstance(resource, expected_type) + assert isinstance(result, expected_type) def test_mpt_client_env(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("MPT_URL", API_URL) monkeypatch.setenv("MPT_TOKEN", API_TOKEN) - mpt = MPTClient() + result = MPTClient() - assert isinstance(mpt, MPTClient) - assert isinstance(mpt.http_client, HTTPClient) + assert isinstance(result, MPTClient) + assert isinstance(result.http_client, HTTPClient) @pytest.mark.parametrize( @@ -64,17 +66,18 @@ def test_mpt_client_env(monkeypatch: pytest.MonkeyPatch) -> None: ) def test_async_mpt_client(resource_name: str, expected_type: type) -> None: mpt = AsyncMPTClient.from_config(base_url=API_URL, api_token=API_TOKEN) - resource = getattr(mpt, resource_name) + + result = getattr(mpt, resource_name) assert isinstance(mpt, AsyncMPTClient) - assert isinstance(resource, expected_type) + assert isinstance(result, expected_type) def test_async_mpt_client_env(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("MPT_URL", API_URL) monkeypatch.setenv("MPT_TOKEN", API_TOKEN) - mpt = AsyncMPTClient() + result = AsyncMPTClient() - assert isinstance(mpt, AsyncMPTClient) - assert isinstance(mpt.http_client, AsyncHTTPClient) + assert isinstance(result, AsyncMPTClient) + assert isinstance(result.http_client, AsyncHTTPClient) diff --git a/uv.lock b/uv.lock index 331344cb..0e67ab32 100644 --- a/uv.lock +++ b/uv.lock @@ -358,6 +358,30 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/9f/56/13ab06b4f93ca7cac71078fbe37fcea175d3216f31f85c3168a6bbd0bb9a/flake8-7.3.0-py2.py3-none-any.whl", hash = "sha256:b9696257b9ce8beb888cdbe31cf885c90d31928fe202be0889a7cdafad32f01e", size = 57922, upload-time = "2025-06-20T19:31:34.425Z" }, ] +[[package]] +name = "flake8-aaa" +version = "0.17.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "asttokens" }, + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/d2/a6/02187797410d8d9ff9ee17840004cc3e975f8b4f75d9431bed32d7311c3d/flake8_aaa-0.17.2.tar.gz", hash = "sha256:03940a53775da4ff044eb32df9893f740654acf4fe32d04a0ad9a2da29d96b77", size = 20123, upload-time = "2025-10-25T21:58:44.651Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7c/57/dba63d7b53ae35e80a6642064dfcd57da03210f8bae2ca810579013dfd57/flake8_aaa-0.17.2-py3-none-any.whl", hash = "sha256:f73237282b4ed2403902c5806b94dfa61538b471271c68bef5c84c0325c48033", size = 20690, upload-time = "2025-10-25T21:58:43.227Z" }, +] + +[[package]] +name = "flake8-pyproject" +version = "1.2.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8" }, +] +wheels = [ + { url = "https://files.pythonhosted.org/packages/5f/1d/635e86f9f3a96b7ea9e9f19b5efe17a987e765c39ca496e4a893bb999112/flake8_pyproject-1.2.3-py3-none-any.whl", hash = "sha256:6249fe53545205af5e76837644dc80b4c10037e73a0e5db87ff562d75fb5bd4a", size = 4756, upload-time = "2023-03-21T20:51:38.911Z" }, +] + [[package]] name = "freezegun" version = "1.5.3" @@ -614,6 +638,8 @@ dependencies = [ [package.dev-dependencies] dev = [ { name = "dependency-injector" }, + { name = "flake8-aaa" }, + { name = "flake8-pyproject" }, { name = "freezegun" }, { name = "ipdb" }, { name = "ipython" }, @@ -644,6 +670,8 @@ requires-dist = [ [package.metadata.requires-dev] dev = [ { name = "dependency-injector", specifier = ">=4.48.2" }, + { name = "flake8-aaa", specifier = ">=0.17.2" }, + { name = "flake8-pyproject", specifier = ">=1.2.3" }, { name = "freezegun", specifier = "==1.5.*" }, { name = "ipdb", specifier = "==0.13.*" }, { name = "ipython", specifier = "==9.*" },