Skip to content

Commit 38af4e5

Browse files
authored
fix: Update Request Metadata to include user id (GoogleCloudPlatform#10490)
## Update search sample Fixes Added the Request metadata to include the user id Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google. ## Checklist - [x] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md) - [x] README is updated to include [all relevant information](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#readme-file) - [x] **Tests** pass: `nox -s py-3.9` (see [Test Environment Setup](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [x] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/.github/CODEOWNERS) with the codeowners for this sample - [ ] This sample adds a new **Product API**, and I updated the [Blunderbuss issue/PR auto-assigner](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/.github/blunderbuss.yml) with the codeowners for this sample - [x] Please **merge** this PR for me once it is approved
1 parent 30c71f2 commit 38af4e5

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

contentwarehouse/snippets/create_get_delete_document_schema_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def test_create_document_schema(request: pytest.fixture) -> None:
3636

3737
assert "display_name" in response
3838

39-
document_schema_id = response.name.split('/')[-1]
39+
document_schema_id = response.name.split("/")[-1]
4040

4141
request.config.cache.set("document_schema_id", document_schema_id)
4242

4343

44-
@pytest.mark.dependency(name="get", depends=['create'])
44+
@pytest.mark.dependency(name="get", depends=["create"])
4545
def test_get_document_schema(request: pytest.fixture) -> None:
4646
project_number = test_utilities.get_project_number(project_id)
4747

@@ -56,7 +56,7 @@ def test_get_document_schema(request: pytest.fixture) -> None:
5656
assert "display_name" in response
5757

5858

59-
@pytest.mark.dependency(name="delete", depends=['get'])
59+
@pytest.mark.dependency(name="delete", depends=["get"])
6060
def test_delete_document_schema(request: pytest.fixture) -> None:
6161
project_number = test_utilities.get_project_number(project_id)
6262

contentwarehouse/snippets/search_documents_sample.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
# project_number = 'YOUR_PROJECT_NUMBER'
2323
# location = 'YOUR_PROJECT_LOCATION' # Format is 'us' or 'eu'
2424
# document_query_text = 'YOUR_DOCUMENT_QUERY'
25+
# user_id = 'user:YOUR_SERVICE_ACCOUNT_ID' # Format is "user:xxxx@example.com"
2526

2627

2728
def search_documents_sample(
28-
project_number: str,
29-
location: str,
30-
document_query_text: str,
29+
project_number: str, location: str, document_query_text: str, user_id: str
3130
) -> None:
3231
# Create a client
3332
client = contentwarehouse.DocumentServiceClient()
@@ -53,9 +52,14 @@ def search_documents_sample(
5352
histogram_query='count("DocumentSchemaId")'
5453
)
5554

55+
request_metadata = contentwarehouse.RequestMetadata(
56+
user_info=contentwarehouse.UserInfo(id=user_id)
57+
)
58+
5659
# Define request
5760
request = contentwarehouse.SearchDocumentsRequest(
5861
parent=parent,
62+
request_metadata=request_metadata,
5963
document_query=document_query,
6064
histogram_queries=[histogram_query],
6165
)

contentwarehouse/snippets/search_documents_sample_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
2323
location = "us" # Format is 'us' or 'eu'
2424
document_query_text = "document"
25+
user_id = "user:xxxx@example.com"
2526

2627

2728
def test_search_documents(capsys: pytest.CaptureFixture) -> None:
@@ -30,6 +31,7 @@ def test_search_documents(capsys: pytest.CaptureFixture) -> None:
3031
project_number=project_number,
3132
location=location,
3233
document_query_text=document_query_text,
34+
user_id=user_id,
3335
)
3436
out, _ = capsys.readouterr()
3537

0 commit comments

Comments
 (0)