fix: mocking errors for /product-projections/search#146
Open
fix: mocking errors for /product-projections/search#146
Conversation
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.
….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.
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_
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/`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! Don't know if this project accepts PRs, but in case it does:
Description
On tests of commercetools-python-sdk SDK calls to Product Projection Search, we see error:
In the first 2 commits, this PR attempts to correct the schema and urls used in
commercetools.testing.product_projections'sProductProjectionsBackend.search()to squash this error.In the last 2 commits, this PR proposes minor changes to the coverage GitHub Action job to squash bugs from the breaking changes in tooling dependencies, such as one in actions/upload-artifact@3 to actions/upload-artifact@4 of not being able to upload artifacts with the same name.
Additional Information
See commit messages for detailed explanation of changes.
Full error logs that prompted change are below. (But see commit messages first.)
Output of error resolved by a5b5f27
Note in the full logs below how this mocker matches to to
get_by_id()instead ofsearch():Full logs, starting with where
search()is called:Output of error resolved by 59c7623
Note in full logs below that now call is to
search():but
_ProductProjectionQuerySchemais used instead of_ProductProjectionSearchSchema:Full logs:
Testing Information
We tested these changes by verifying that the test errors in edx/commerce-coordinator#135 (see this comment) turned green on our locals when manually loading this branch of the SDK in our code.
We verified format/tests/coverage jobs ran successfully in edx#1.