From 5cf69d8ec73be12281ec14431eed3c386c5ffe7e Mon Sep 17 00:00:00 2001 From: Phillip Shiu Date: Tue, 19 Dec 2023 19:53:50 -0500 Subject: [PATCH 1/4] fix: support GET methods for ProductProjectionsBackend.search() Commercetools' /product-projections/search endpoint allows both GET and POST methods: https://docs.commercetools.com/api/projects/products-search#product-projection-search labd/commercetools-python-sdk uses a GET method when using /product-projections/search: https://github.com/labd/commercetools-python-sdk/blob/3bd9fd1d94c8640c28f0fc82cdd4796a6dc6e97c/src/commercetools/services/product_projections.py#L294 However, its testing package only recognizes POST methods for /product-projections/search. This commit adds GET as a supported method so the testing package will mock product projection searches from the services package of this repository. --- src/commercetools/testing/product_projections.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commercetools/testing/product_projections.py b/src/commercetools/testing/product_projections.py index 2105da1f..a33a0caf 100644 --- a/src/commercetools/testing/product_projections.py +++ b/src/commercetools/testing/product_projections.py @@ -19,6 +19,7 @@ class ProductProjectionsBackend(ServiceBackend): def urls(self): return [ ("^$", "GET", self.query), + ("^search", "GET", self.search), ("^search", "POST", self.search), ("^key=(?P[^/]+)$", "GET", self.get_by_key), ("^(?P[^/]+)$", "GET", self.get_by_id), From 4c3ecfdfc264027260e270507a083c198f694e20 Mon Sep 17 00:00:00 2001 From: Phillip Shiu Date: Tue, 19 Dec 2023 20:02:17 -0500 Subject: [PATCH 2/4] fix: use _ProductProjectionSearchSchema for ProductProjectionsBackend.search() _ProductProjectionSearchSchema is defined here: https://github.com/labd/commercetools-python-sdk/blob/3bd9fd1d94c8640c28f0fc82cdd4796a6dc6e97c/src/commercetools/services/product_projections.py#L32C7-L32C37 It generally matches the valid parameters of Commercetools' /product-projections/search endpoint: https://docs.commercetools.com/api/projects/products-search#query-parameters commercetools.services.ProductProjectionService.search() uses _ProductProjectionSearchSchema: https://github.com/labd/commercetools-python-sdk/blob/3bd9fd1d94c8640c28f0fc82cdd4796a6dc6e97c/src/commercetools/services/product_projections.py#L292 However, commercetools.testing.ProductProjectionsBackend.search() uses _ProductProjectionQuerySchema instead of _ProductProjectionSearchSchema. This commit changes the schema used by commercetools.testing.ProductProjectionsBackend.search() so that marshmellow will validate search() requests against the correct schema. --- src/commercetools/testing/product_projections.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/commercetools/testing/product_projections.py b/src/commercetools/testing/product_projections.py index a33a0caf..166ec135 100644 --- a/src/commercetools/testing/product_projections.py +++ b/src/commercetools/testing/product_projections.py @@ -6,7 +6,10 @@ ProductProjectionSchema, ProductSchema, ) -from commercetools.services.product_projections import _ProductProjectionQuerySchema +from commercetools.services.product_projections import ( + _ProductProjectionQuerySchema, + _ProductProjectionSearchSchema, +) from commercetools.testing import utils from commercetools.testing.abstract import ServiceBackend from commercetools.testing.utils import create_commercetools_response @@ -54,7 +57,7 @@ def query(self, request): return create_commercetools_response(request, text=content) def search(self, request): - params = utils.parse_request_params(_ProductProjectionQuerySchema, request) + params = utils.parse_request_params(_ProductProjectionSearchSchema, request) limit = params.get("limit") From b8b326079c0ad46d3d8a6154d9bb4b08330c39c8 Mon Sep 17 00:00:00 2001 From: Phillip Shiu Date: Thu, 21 Dec 2023 09:46:11 -0500 Subject: [PATCH 3/4] build: make upload-artifact names unique A GitHub Action matrix lets you run a workflow multiple times using different parameters: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs The matrix of the python-test.yml's GitHub Action is uploading a coverage file per python-version in the matrix. This is no longer allowed by actions/upload-artifact. See its README: https://github.com/actions/upload-artifact/blob/cf8714cfeaba5687a442b9bcb85b29e23f468dfa/README.md#not-uploading-to-the-same-artifact Fixes errors like: ``` Run actions/upload-artifact@master With the provided path, there will be 1 file uploaded Artifact name is valid! Root directory input is valid! Error: Failed to CreateArtifact: Received non-retryable error: Failed request: (409) Conflict: an artifact with this name already exists on the workflow run ``` The example above from: https://github.com/edx/commercetools-python-sdk/actions/runs/7289547220/job/19864387471?pr=1_ --- .github/workflows/python-test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 61905bbd..802028c4 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -54,7 +54,7 @@ jobs: - uses: actions/upload-artifact@master with: - name: coverage-data + name: coverage-data-${{ matrix.python-version }} path: .coverage-data/ coverage: @@ -64,8 +64,9 @@ jobs: - uses: actions/checkout@v3 - uses: actions/download-artifact@master with: - name: coverage-data + pattern: coverage-data-* path: . + merge-multiple: true - name: Set up Python 3.10 uses: actions/setup-python@v4 From 88766bf08686add61bc13b59f41cb02e70392c63 Mon Sep 17 00:00:00 2001 From: Phillip Shiu Date: Thu, 21 Dec 2023 14:48:34 -0500 Subject: [PATCH 4/4] fix: don't mind how many folders are between .tox and .site-packages From GitHub Actions: ``` Run tox -e coverage-report coverage-report: install_deps> python -I -m pip install 'coverage[toml]' coverage-report: freeze> python -m pip freeze --all coverage-report: coverage==7.3.4,pip==23.3.1,setuptools==69.0.2,tomli==2.0.1,wheel==0.42.0 coverage-report: commands[0]> coverage combine Combined data file .coverage.fv-az1116-506.1828.XNaBMOPx coverage-report: commands[1]> coverage xml No source for code: '/home/runner/work/commercetools-python-sdk/commercetools-python-sdk/.tox/py310/lib/python3.10/site-packages/commercetools/__init__.py'. coverage-report: exit 1 (0.19 seconds) /home/runner/work/commercetools-python-sdk/commercetools-python-sdk> coverage xml pid=1847 coverage-report: FAIL code 1 (2.56=setup[2.25]+cmd[0.12,0.19] seconds) evaluation failed :( (3.03 seconds) Error: Process completed with exit code 1. ``` This commit hypothesizes that coverage.py is unable to find the source file because the `*` glob may not cover the `py310/lib/python3.10/` in between the directories `.tox/` and `site-packages/`. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d083849f..3d61200a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ["setuptools>=40.6.0", "wheel"] build-backend = "setuptools.build_meta" [tool.coverage.paths] -source = ["src", ".tox/*/site-packages"] +source = ["src", ".tox/**/site-packages"] [tool.isort] line_length = 88