Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

docs(samples): add retail search service samples #133

Merged
merged 18 commits into from
Jan 28, 2022

Conversation

t-karasova
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@t-karasova t-karasova requested a review from a team as a code owner January 24, 2022 16:58
@product-auto-label product-auto-label bot added api: retail Issues related to the googleapis/python-retail API. samples Issues that are directly related to samples. labels Jan 24, 2022
@snippet-bot
Copy link

snippet-bot bot commented Jan 24, 2022

Here is the summary of changes.

You are about to add 7 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@t-karasova
Copy link
Contributor Author

@kweinmeister , @chenlei1216
Hi Karl, Lei
I have created this pull request to add the code samples for Interactive Tutorials for Retail API.
You have already seen and approved them in #122, I am going to close that (122) as it is too big and the further review is difficult.

The code samples are moved to the folder "samples/interactive-tutorials" to separate them from the code samples, which are used for displaying in the static documentation pages.
It was decided, that Our tutorials + code samples will be shown only by clicking the button "Guide me" in the Retail documentation page and will be opened in the Cloud Shell IDE.

In this PR I have created the code samples for Retail Search service and tests.

I have modified .kokoro configs to read the secrets from "retail-samples-secrets" secret manager.

For the tests we use our own Cloud project with preset catalog data. And I would like to ask you how should I add the service account token to our project to authorize tests?

Thank you

@kweinmeister kweinmeister added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 26, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 26, 2022
print("---search response---")
print(search_response_first_page)

# PASTE CALL WITH NEXT PAGE TOKEN HERE:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add code samples how to get the next page token?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We provide the code here, in the tutorial https://github.com/t-karasova/python-retail/blob/readme/samples/interactive-tutorials/tutorials/retail_api_v2_pagination_python.neos.md, and we ask user to copy it and paste under the specific comment in the code. we did it to increase the user engagement into the learning process.

Copy link
Contributor Author

@t-karasova t-karasova Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code is the following:

    search_request_next_page = get_search_request("Hoodie", page_size, offset, next_page_token)
    search_response_next_page = SearchServiceClient().search(search_request_next_page)
    print("---next page search results---")
    print(search_response_next_page)

@parthea parthea added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Jan 27, 2022
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 27, 2022
@parthea parthea self-requested a review January 27, 2022 12:30
@parthea parthea added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Jan 27, 2022
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 27, 2022
@parthea
Copy link
Contributor

parthea commented Jan 27, 2022

Current failure for python 3.7 samples : pytest: error: unrecognized arguments: -n=auto

******************** TESTING PROJECTS ********************
------------------------------------------------------------
- testing samples/interactive-tutorials/search
------------------------------------------------------------
nox > Running session py-3.7
nox > Creating virtual environment (virtualenv) using python3.7 in .nox/py-3-7
nox > python -m pip install -r requirements.txt
nox > python -m pip install -r requirements-test.txt
nox > python -m pip install -e /workspace
nox > pytest --junitxml=sponge_log.xml
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: -n=auto
  inifile: None
  rootdir: /workspace

nox > Command pytest --junitxml=sponge_log.xml failed with exit code 4
nox > Session py-3.7 failed.

 Testing failed: Nox returned a non-zero exit code. 

@parthea parthea added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Jan 27, 2022
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 27, 2022
@parthea parthea added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 27, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 28, 2022
Copy link
Contributor

@parthea parthea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added minor observations

samples/interactive-tutorials/README.md Outdated Show resolved Hide resolved
samples/interactive-tutorials/LICENSE Outdated Show resolved Hide resolved
samples/interactive-tutorials/README.md Outdated Show resolved Hide resolved
samples/interactive-tutorials/README.md Outdated Show resolved Hide resolved
samples/interactive-tutorials/README.md Show resolved Hide resolved
@parthea
Copy link
Contributor

parthea commented Jan 28, 2022

The tests appear to be running now. There are 2 unit test failures:

=========================== short test summary info ============================
FAILED search_with_filtering_test.py::test_search_with_filtering - AssertionE...
FAILED search_with_query_expansion_spec_test.py::test_search_with_query_expansion_spec
========================= 2 failed, 12 passed in 6.14s =========================
=================================== FAILURES ===================================
__________________________ test_search_with_filtering __________________________

    def test_search_with_filtering():
        response = search()

        assert len(response.results) == 10
        product_title = response.results[0].product.title
>       assert re.match(".*Tee.*Black", product_title)
E       AssertionError: assert None
E        +  where None = <function match at 0x7f4bae37c710>('.*Tee.*Black', 'Google Black Cloud Tee')
E        +    where <function match at 0x7f4bae37c710> = re.match

search_with_filtering_test.py:39: AssertionError
____________________ test_search_with_query_expansion_spec _____________________

    def test_search_with_query_expansion_spec():
        response = search()

>       assert len(response.results) == 10
E       assert 1 == 10
E        +  where 1 = len([id: "GGOEGAYJ136014"\nproduct {\n  name: "projects/<REDACTED>/locations/global/catalogs/default_catalog/branches/0/p... 300\n    width: 400\n  }\n  color_info {\n    color_families: "Gray"\n    colors: "Light gray"\n    colors: "Silver"\n  }\n}\n])
E        +    where [id: "GGOEGAYJ136014"\nproduct {\n  name: "projects/<REDACTED>/locations/global/catalogs/default_catalog/branches/0/p... 300\n    width: 400\n  }\n  color_info {\n    color_families: "Gray"\n    colors: "Light gray"\n    colors: "Silver"\n  }\n}\n] = SearchPager<results {\n  id: "GGOEGAYJ136014"\n  product {\n    name: "projects/<REDACTED>/locations/global/catalogs/<REDACTED>"\n>.results

search_with_query_expansion_spec_test.py:39: AssertionError

@kweinmeister kweinmeister added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:run Add this label to force Kokoro to re-run the tests. labels Jan 28, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 28, 2022
@parthea parthea added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Jan 28, 2022
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 28, 2022
@kweinmeister kweinmeister added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 28, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 28, 2022
@parthea parthea added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. and removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. labels Jan 28, 2022
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jan 28, 2022
@parthea parthea merged commit 3b5f938 into googleapis:main Jan 28, 2022
t-karasova pushed a commit to t-karasova/python-retail that referenced this pull request Feb 9, 2022
* feat: Retail Interactive Tutorials. Search service code samples

* use default project for testing purposes

* add pytest-xdist as a requirement for testing

* fail on missing environment variable

* for testing purposes

* for testing purposes

* for testing purposes

* updated according to the review comments

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* try out GOOGLE_CLOUD_PROJECT_NUMBER instead of PROJECT_NUMBER

* add BUCKET_NAME as an environment variable

* adjust filepath so tests can run

* tests are fixed

* Update samples/interactive-tutorials/README.md

Co-authored-by: Anthonios Partheniou <[email protected]>

* README file is updated

* fix typo in pip install command

Co-authored-by: Karl Weinmeister <[email protected]>
Co-authored-by: Anthonios Partheniou <[email protected]>
Co-authored-by: t-karasova <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
t-karasova pushed a commit to t-karasova/python-retail that referenced this pull request Feb 9, 2022
* feat: Retail Interactive Tutorials. Search service code samples

* use default project for testing purposes

* add pytest-xdist as a requirement for testing

* fail on missing environment variable

* for testing purposes

* for testing purposes

* for testing purposes

* updated according to the review comments

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* try out GOOGLE_CLOUD_PROJECT_NUMBER instead of PROJECT_NUMBER

* add BUCKET_NAME as an environment variable

* adjust filepath so tests can run

* tests are fixed

* Update samples/interactive-tutorials/README.md

Co-authored-by: Anthonios Partheniou <[email protected]>

* README file is updated

* fix typo in pip install command

Co-authored-by: Karl Weinmeister <[email protected]>
Co-authored-by: Anthonios Partheniou <[email protected]>
Co-authored-by: t-karasova <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
t-karasova pushed a commit to tetiana-karasova/python-retail that referenced this pull request Feb 10, 2022
* feat: Retail Interactive Tutorials. Search service code samples

* use default project for testing purposes

* add pytest-xdist as a requirement for testing

* fail on missing environment variable

* for testing purposes

* for testing purposes

* for testing purposes

* updated according to the review comments

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* try out GOOGLE_CLOUD_PROJECT_NUMBER instead of PROJECT_NUMBER

* add BUCKET_NAME as an environment variable

* adjust filepath so tests can run

* tests are fixed

* Update samples/interactive-tutorials/README.md

Co-authored-by: Anthonios Partheniou <[email protected]>

* README file is updated

* fix typo in pip install command

Co-authored-by: Karl Weinmeister <[email protected]>
Co-authored-by: Anthonios Partheniou <[email protected]>
Co-authored-by: t-karasova <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
t-karasova pushed a commit to tetiana-karasova/python-retail that referenced this pull request Feb 10, 2022
* feat: Retail Interactive Tutorials. Search service code samples

* use default project for testing purposes

* add pytest-xdist as a requirement for testing

* fail on missing environment variable

* for testing purposes

* for testing purposes

* for testing purposes

* updated according to the review comments

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* try out GOOGLE_CLOUD_PROJECT_NUMBER instead of PROJECT_NUMBER

* add BUCKET_NAME as an environment variable

* adjust filepath so tests can run

* tests are fixed

* Update samples/interactive-tutorials/README.md

Co-authored-by: Anthonios Partheniou <[email protected]>

* README file is updated

* fix typo in pip install command

Co-authored-by: Karl Weinmeister <[email protected]>
Co-authored-by: Anthonios Partheniou <[email protected]>
Co-authored-by: t-karasova <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: retail Issues related to the googleapis/python-retail API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants