diff --git a/jobs/v4beta1/conftest.py b/jobs/v4beta1/conftest.py
new file mode 100644
index 000000000000..169a401bcfb8
--- /dev/null
+++ b/jobs/v4beta1/conftest.py
@@ -0,0 +1,87 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import uuid
+
+from google.api_core.exceptions import NotFound
+
+import pytest
+
+import job_search_create_company
+import job_search_create_job
+import job_search_create_tenant
+import job_search_delete_company
+import job_search_delete_job
+import job_search_delete_tenant
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+@pytest.fixture(scope="module")
+def tenant():
+ tenant_ext_unique_id = "TEST_TENANT_{}".format(uuid.uuid4())
+ # create a temporary tenant
+ tenant_name = job_search_create_tenant.create_tenant(
+ PROJECT_ID, tenant_ext_unique_id
+ )
+
+ # extract company id
+ tenant_id = tenant_name.split("/")[-1]
+
+ yield tenant_id
+
+ try:
+ job_search_delete_tenant.delete_tenant(PROJECT_ID, tenant_id)
+ except NotFound as e:
+ print("Ignoring NotFound upon cleanup, details: {}".format(e))
+
+
+@pytest.fixture(scope="module")
+def company(tenant):
+ company_ext_id = "COMPANY_EXT_ID_{}".format(uuid.uuid4())
+
+ # create a temporary company
+ company_name = job_search_create_company.create_company(
+ PROJECT_ID, tenant, "Test Company Name", company_ext_id
+ )
+
+ # extract company id
+ company_id = company_name.split("/")[-1]
+
+ yield company_id
+
+ try:
+ job_search_delete_company.delete_company(PROJECT_ID, tenant, company_id)
+ except NotFound as e:
+ print("Ignoring NotFound upon cleanup, details: {}".format(e))
+
+
+@pytest.fixture(scope="module")
+def job(tenant, company):
+ post_unique_id = "TEST_POST_{}".format(uuid.uuid4().hex)[:20]
+ # create a temporary job
+ job_name = job_search_create_job.create_job(
+ PROJECT_ID, tenant, company, post_unique_id, "www.jobUrl.com"
+ )
+
+ # extract company id
+ job_id = job_name.split("/")[-1]
+
+ yield job_id
+
+ try:
+ job_search_delete_job.delete_job(PROJECT_ID, tenant, job_id)
+ except NotFound as e:
+ print("Ignoring NotFound upon cleanup, details: {}".format(e))
diff --git a/jobs/v4beta1/job_search_autocomplete_job_title.py b/jobs/v4beta1/job_search_autocomplete_job_title.py
new file mode 100644
index 000000000000..af817ec1a7cc
--- /dev/null
+++ b/jobs/v4beta1/job_search_autocomplete_job_title.py
@@ -0,0 +1,56 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_autocomplete_job_title]
+
+from google.cloud import talent_v4beta1
+from google.cloud.talent import enums
+import six
+
+
+def complete_query(project_id, tenant_id, query):
+ """Complete job title given partial text (autocomplete)"""
+
+ client = talent_v4beta1.CompletionClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # query = '[partially typed job title]'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(query, six.binary_type):
+ query = query.decode("utf-8")
+
+ parent = client.tenant_path(project_id, tenant_id)
+
+ response = client.complete_query(
+ parent,
+ query,
+ page_size=5, # limit for number of results
+ language_codes=["en-US"], # language code
+ )
+ for result in response.completion_results:
+ print("Suggested title: {}".format(result.suggestion))
+ # Suggestion type is JOB_TITLE or COMPANY_TITLE
+ print(
+ "Suggestion type: {}".format(
+ enums.CompleteQueryRequest.CompletionType(result.type).name
+ )
+ )
+
+
+# [END job_search_autocomplete_job_title]
diff --git a/jobs/v4beta1/job_search_autocomplete_job_title_test.py b/jobs/v4beta1/job_search_autocomplete_job_title_test.py
new file mode 100644
index 000000000000..4fe2498481c3
--- /dev/null
+++ b/jobs/v4beta1/job_search_autocomplete_job_title_test.py
@@ -0,0 +1,25 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_autocomplete_job_title
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_autocomplete_job_title(capsys, tenant):
+ job_search_autocomplete_job_title.complete_query(PROJECT_ID, tenant, "Software")
+ out, _ = capsys.readouterr()
+ assert "Suggested title:" in out
diff --git a/jobs/v4beta1/job_search_batch_create_jobs.py b/jobs/v4beta1/job_search_batch_create_jobs.py
new file mode 100644
index 000000000000..a221cc57c9c7
--- /dev/null
+++ b/jobs/v4beta1/job_search_batch_create_jobs.py
@@ -0,0 +1,133 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_batch_create_jobs]
+
+from google.cloud import talent
+import six
+
+
+def batch_create_jobs(
+ project_id,
+ tenant_id,
+ company_name_one,
+ requisition_id_one,
+ title_one,
+ description_one,
+ job_application_url_one,
+ address_one,
+ language_code_one,
+ company_name_two,
+ requisition_id_two,
+ title_two,
+ description_two,
+ job_application_url_two,
+ address_two,
+ language_code_two,
+):
+ """
+ Batch Create Jobs
+
+ Args:
+ project_id Your Google Cloud Project ID
+ tenant_id Identifier of the Tenant
+ """
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # company_name_one = 'Company name, e.g. projects/your-project/companies/company-id'
+ # requisition_id_one = 'Job requisition ID, aka Posting ID. Unique per job.'
+ # title_one = 'Software Engineer'
+ # description_one = 'This is a description of this wonderful job!'
+ # job_application_url_one = 'https://www.example.org/job-posting/123'
+ # address_one = '1600 Amphitheatre Parkway, Mountain View, CA 94043'
+ # language_code_one = 'en-US'
+ # company_name_two = 'Company name, e.g. projects/your-project/companies/company-id'
+ # requisition_id_two = 'Job requisition ID, aka Posting ID. Unique per job.'
+ # title_two = 'Quality Assurance'
+ # description_two = 'This is a description of this wonderful job!'
+ # job_application_url_two = 'https://www.example.org/job-posting/123'
+ # address_two = '111 8th Avenue, New York, NY 10011'
+ # language_code_two = 'en-US'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(company_name_one, six.binary_type):
+ company_name_one = company_name_one.decode("utf-8")
+ if isinstance(requisition_id_one, six.binary_type):
+ requisition_id_one = requisition_id_one.decode("utf-8")
+ if isinstance(title_one, six.binary_type):
+ title_one = title_one.decode("utf-8")
+ if isinstance(description_one, six.binary_type):
+ description_one = description_one.decode("utf-8")
+ if isinstance(job_application_url_one, six.binary_type):
+ job_application_url_one = job_application_url_one.decode("utf-8")
+ if isinstance(address_one, six.binary_type):
+ address_one = address_one.decode("utf-8")
+ if isinstance(language_code_one, six.binary_type):
+ language_code_one = language_code_one.decode("utf-8")
+ if isinstance(company_name_two, six.binary_type):
+ company_name_two = company_name_two.decode("utf-8")
+ if isinstance(requisition_id_two, six.binary_type):
+ requisition_id_two = requisition_id_two.decode("utf-8")
+ if isinstance(title_two, six.binary_type):
+ title_two = title_two.decode("utf-8")
+ if isinstance(description_two, six.binary_type):
+ description_two = description_two.decode("utf-8")
+ if isinstance(job_application_url_two, six.binary_type):
+ job_application_url_two = job_application_url_two.decode("utf-8")
+ if isinstance(address_two, six.binary_type):
+ address_two = address_two.decode("utf-8")
+ if isinstance(language_code_two, six.binary_type):
+ language_code_two = language_code_two.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+ uris = [job_application_url_one]
+ application_info = {"uris": uris}
+ addresses = [address_one]
+ jobs_element = {
+ "company": company_name_one,
+ "requisition_id": requisition_id_one,
+ "title": title_one,
+ "description": description_one,
+ "application_info": application_info,
+ "addresses": addresses,
+ "language_code": language_code_one,
+ }
+ uris_2 = [job_application_url_two]
+ application_info_2 = {"uris": uris_2}
+ addresses_2 = [address_two]
+ jobs_element_2 = {
+ "company": company_name_two,
+ "requisition_id": requisition_id_two,
+ "title": title_two,
+ "description": description_two,
+ "application_info": application_info_2,
+ "addresses": addresses_2,
+ "language_code": language_code_two,
+ }
+ jobs = [jobs_element, jobs_element_2]
+
+ operation = client.batch_create_jobs(parent, jobs)
+
+ print("Waiting for operation to complete...")
+ response = operation.result(90)
+
+ print("Batch response: {}".format(response))
+
+
+# [END job_search_batch_create_jobs]
diff --git a/jobs/v4beta1/job_search_batch_update_jobs.py b/jobs/v4beta1/job_search_batch_update_jobs.py
new file mode 100644
index 000000000000..bac4232e2ea5
--- /dev/null
+++ b/jobs/v4beta1/job_search_batch_update_jobs.py
@@ -0,0 +1,143 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_batch_update_jobs]
+
+from google.cloud import talent
+import six
+
+
+def batch_update_jobs(
+ project_id,
+ tenant_id,
+ job_name_one,
+ company_name_one,
+ requisition_id_one,
+ title_one,
+ description_one,
+ job_application_url_one,
+ address_one,
+ language_code_one,
+ job_name_two,
+ company_name_two,
+ requisition_id_two,
+ title_two,
+ description_two,
+ job_application_url_two,
+ address_two,
+ language_code_two,
+):
+ """
+ Batch Update Jobs
+
+ Args:
+ project_id Your Google Cloud Project ID
+ tenant_id Identifier of the Tenant
+ """
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # job_name_one = 'job name, projects/your-project/tenants/tenant-id/jobs/job-id'
+ # company_name_one = 'Company name, e.g. projects/your-project/companies/company-id'
+ # requisition_id_one = 'Job requisition ID, aka Posting ID. Unique per job.'
+ # title_one = 'Software Engineer'
+ # description_one = 'This is a description of this wonderful job!'
+ # job_application_url_one = 'https://www.example.org/job-posting/123'
+ # address_one = '1600 Amphitheatre Parkway, Mountain View, CA 94043'
+ # language_code_one = 'en-US'
+ # job_name_two = 'job name, projects/your-project/tenants/tenant-id/jobs/job-id'
+ # company_name_two = 'Company name, e.g. projects/your-project/companies/company-id'
+ # requisition_id_two = 'Job requisition ID, aka Posting ID. Unique per job.'
+ # title_two = 'Quality Assurance'
+ # description_two = 'This is a description of this wonderful job!'
+ # job_application_url_two = 'https://www.example.org/job-posting/123'
+ # address_two = '111 8th Avenue, New York, NY 10011'
+ # language_code_two = 'en-US'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(job_name_one, six.binary_type):
+ job_name_one = job_name_one.decode("utf-8")
+ if isinstance(company_name_one, six.binary_type):
+ company_name_one = company_name_one.decode("utf-8")
+ if isinstance(requisition_id_one, six.binary_type):
+ requisition_id_one = requisition_id_one.decode("utf-8")
+ if isinstance(title_one, six.binary_type):
+ title_one = title_one.decode("utf-8")
+ if isinstance(description_one, six.binary_type):
+ description_one = description_one.decode("utf-8")
+ if isinstance(job_application_url_one, six.binary_type):
+ job_application_url_one = job_application_url_one.decode("utf-8")
+ if isinstance(address_one, six.binary_type):
+ address_one = address_one.decode("utf-8")
+ if isinstance(language_code_one, six.binary_type):
+ language_code_one = language_code_one.decode("utf-8")
+ if isinstance(job_name_two, six.binary_type):
+ job_name_two = job_name_two.decode("utf-8")
+ if isinstance(company_name_two, six.binary_type):
+ company_name_two = company_name_two.decode("utf-8")
+ if isinstance(requisition_id_two, six.binary_type):
+ requisition_id_two = requisition_id_two.decode("utf-8")
+ if isinstance(title_two, six.binary_type):
+ title_two = title_two.decode("utf-8")
+ if isinstance(description_two, six.binary_type):
+ description_two = description_two.decode("utf-8")
+ if isinstance(job_application_url_two, six.binary_type):
+ job_application_url_two = job_application_url_two.decode("utf-8")
+ if isinstance(address_two, six.binary_type):
+ address_two = address_two.decode("utf-8")
+ if isinstance(language_code_two, six.binary_type):
+ language_code_two = language_code_two.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+ uris = [job_application_url_one]
+ application_info = {"uris": uris}
+ addresses = [address_one]
+ jobs_element = {
+ "name": job_name_one,
+ "company": company_name_one,
+ "requisition_id": requisition_id_one,
+ "title": title_one,
+ "description": description_one,
+ "application_info": application_info,
+ "addresses": addresses,
+ "language_code": language_code_one,
+ }
+ uris_2 = [job_application_url_two]
+ application_info_2 = {"uris": uris_2}
+ addresses_2 = [address_two]
+ jobs_element_2 = {
+ "name": job_name_two,
+ "company": company_name_two,
+ "requisition_id": requisition_id_two,
+ "title": title_two,
+ "description": description_two,
+ "application_info": application_info_2,
+ "addresses": addresses_2,
+ "language_code": language_code_two,
+ }
+ jobs = [jobs_element, jobs_element_2]
+
+ operation = client.batch_update_jobs(parent, jobs)
+
+ print("Waiting for operation to complete...")
+ response = operation.result(90)
+
+ print("Batch response: {}".format(response))
+
+
+# [END job_search_batch_update_jobs]
diff --git a/jobs/v4beta1/job_search_commute_search.py b/jobs/v4beta1/job_search_commute_search.py
new file mode 100644
index 000000000000..1a5df79f6f3d
--- /dev/null
+++ b/jobs/v4beta1/job_search_commute_search.py
@@ -0,0 +1,66 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_commute_search]
+
+from google.cloud import talent
+from google.cloud.talent import enums
+import six
+
+
+def search_jobs(project_id, tenant_id):
+ """Search Jobs using commute distance"""
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+ domain = "www.example.com"
+ session_id = "Hashed session identifier"
+ user_id = "Hashed user identifier"
+ request_metadata = {"domain": domain, "session_id": session_id, "user_id": user_id}
+ commute_method = enums.CommuteMethod.TRANSIT
+ seconds = 1800
+ travel_duration = {"seconds": seconds}
+ latitude = 37.422408
+ longitude = -122.084068
+ start_coordinates = {"latitude": latitude, "longitude": longitude}
+ commute_filter = {
+ "commute_method": commute_method,
+ "travel_duration": travel_duration,
+ "start_coordinates": start_coordinates,
+ }
+ job_query = {"commute_filter": commute_filter}
+
+ # Iterate over all results
+ results = []
+ for response_item in client.search_jobs(
+ parent, request_metadata, job_query=job_query
+ ):
+ print("Job summary: {}".format(response_item.job_summary))
+ print("Job title snippet: {}".format(response_item.job_title_snippet))
+ job = response_item.job
+ results.append(job.name)
+ print("Job name: {}".format(job.name))
+ print("Job title: {}".format(job.title))
+ return results
+
+
+# [END job_search_commute_search]
diff --git a/jobs/v4beta1/job_search_commute_search_test.py b/jobs/v4beta1/job_search_commute_search_test.py
new file mode 100644
index 000000000000..911875015dce
--- /dev/null
+++ b/jobs/v4beta1/job_search_commute_search_test.py
@@ -0,0 +1,25 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_commute_search
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_commute_search(tenant):
+ jobs = job_search_commute_search.search_jobs(PROJECT_ID, tenant)
+ for job in jobs:
+ assert "projects/" in job
diff --git a/jobs/v4beta1/job_search_create_client_event.py b/jobs/v4beta1/job_search_create_client_event.py
new file mode 100644
index 000000000000..c5bb1b48f7da
--- /dev/null
+++ b/jobs/v4beta1/job_search_create_client_event.py
@@ -0,0 +1,77 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_create_client_event]
+
+from google.cloud import talent
+from google.cloud.talent import enums
+import six
+
+
+def create_client_event(project_id, tenant_id, request_id, event_id):
+ """
+ Creates a client event
+
+ Args:
+ project_id Your Google Cloud Project ID
+ tenant_id Identifier of the Tenant
+ request_id A unique ID generated in the API responses.
+ Value should be set to the request_id from an API response.
+ event_id A unique identifier, generated by the client application
+ """
+
+ client = talent.EventServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # request_id = '[request_id from ResponseMetadata]'
+ # event_id = '[Set this to a unique identifier]'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(request_id, six.binary_type):
+ request_id = request_id.decode("utf-8")
+ if isinstance(event_id, six.binary_type):
+ event_id = event_id.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+
+ # The timestamp of the event as seconds of UTC time since Unix epoch
+ # For more information on how to create google.protobuf.Timestamps
+ # See:
+ # https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto
+ seconds = 0
+ create_time = {"seconds": seconds}
+
+ # The type of event attributed to the behavior of the end user
+ type_ = enums.JobEvent.JobEventType.VIEW
+
+ # List of job names associated with this event
+ jobs_element = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]"
+ jobs_element_2 = "projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]"
+ jobs = [jobs_element, jobs_element_2]
+ job_event = {"type": type_, "jobs": jobs}
+ client_event = {
+ "request_id": request_id,
+ "event_id": event_id,
+ "create_time": create_time,
+ "job_event": job_event,
+ }
+
+ response = client.create_client_event(parent, client_event)
+ print(response)
+
+
+# [END job_search_create_client_event]
diff --git a/jobs/v4beta1/job_search_create_company.py b/jobs/v4beta1/job_search_create_company.py
new file mode 100644
index 000000000000..828fb0e49dbc
--- /dev/null
+++ b/jobs/v4beta1/job_search_create_company.py
@@ -0,0 +1,50 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_create_company]
+
+from google.cloud import talent
+import six
+
+
+def create_company(project_id, tenant_id, display_name, external_id):
+ """Create Company"""
+
+ client = talent.CompanyServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # display_name = 'My Company Name'
+ # external_id = 'Identifier of this company in my system'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(display_name, six.binary_type):
+ display_name = display_name.decode("utf-8")
+ if isinstance(external_id, six.binary_type):
+ external_id = external_id.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+ company = {"display_name": display_name, "external_id": external_id}
+
+ response = client.create_company(parent, company)
+ print("Created Company")
+ print("Name: {}".format(response.name))
+ print("Display Name: {}".format(response.display_name))
+ print("External ID: {}".format(response.external_id))
+ return response.name
+
+
+# [END job_search_create_company]
diff --git a/jobs/v4beta1/job_search_create_company_test.py b/jobs/v4beta1/job_search_create_company_test.py
new file mode 100644
index 000000000000..e78f60903212
--- /dev/null
+++ b/jobs/v4beta1/job_search_create_company_test.py
@@ -0,0 +1,48 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import uuid
+
+import pytest
+
+import job_search_create_company
+import job_search_delete_company
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+COMPANY_EXT_ID = "COMPANY_EXT_ID_{}".format(uuid.uuid4())
+
+
+def test_create_company(capsys, tenant, cleaner):
+ # create company
+ company_name = job_search_create_company.create_company(
+ PROJECT_ID, tenant, "Test Company Name", COMPANY_EXT_ID
+ )
+ out, _ = capsys.readouterr()
+ assert "Created" in out
+ assert "Name:" in out
+
+ # extract id
+ company_id = company_name.split("/")[-1]
+ cleaner.append(company_id)
+
+
+@pytest.fixture(scope="module")
+def cleaner(tenant):
+ companies = []
+
+ yield companies
+
+ for company_id in companies:
+ job_search_delete_company.delete_company(PROJECT_ID, tenant, company_id)
diff --git a/jobs/v4beta1/job_search_create_job.py b/jobs/v4beta1/job_search_create_job.py
new file mode 100644
index 000000000000..ed065d24fab6
--- /dev/null
+++ b/jobs/v4beta1/job_search_create_job.py
@@ -0,0 +1,71 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_create_job]
+
+from google.cloud import talent
+import six
+
+
+def create_job(
+ project_id, tenant_id, company_id, requisition_id, job_application_url,
+):
+ """Create Job"""
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # company_id = 'Company name, e.g. projects/your-project/companies/company-id'
+ # requisition_id = 'Job requisition ID, aka Posting ID. Unique per job.'
+ # title = 'Software Engineer'
+ # description = 'This is a description of this wonderful job!'
+ # job_application_url = 'https://www.example.org/job-posting/123'
+ # address_one = '1600 Amphitheatre Parkway, Mountain View, CA 94043'
+ # address_two = '111 8th Avenue, New York, NY 10011'
+ # language_code = 'en-US'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(company_id, six.binary_type):
+ company_id = company_id.decode("utf-8")
+ if isinstance(requisition_id, six.binary_type):
+ requisition_id = requisition_id.decode("utf-8")
+ if isinstance(job_application_url, six.binary_type):
+ job_application_url = job_application_url.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+ uris = [job_application_url]
+ application_info = {"uris": uris}
+ addresses = [
+ "1600 Amphitheatre Parkway, Mountain View, CA 94043",
+ "111 8th Avenue, New York, NY 10011",
+ ]
+ job = {
+ "company": company_id,
+ "requisition_id": requisition_id,
+ "title": "Software Developer",
+ "description": "Develop, maintain the software solutions.",
+ "application_info": application_info,
+ "addresses": addresses,
+ "language_code": "en-US",
+ }
+
+ response = client.create_job(parent, job)
+ print("Created job: {}".format(response.name))
+ return response.name
+
+
+# [END job_search_create_job]
diff --git a/jobs/v4beta1/job_search_create_job_custom_attributes.py b/jobs/v4beta1/job_search_create_job_custom_attributes.py
new file mode 100644
index 000000000000..de8aa40e999b
--- /dev/null
+++ b/jobs/v4beta1/job_search_create_job_custom_attributes.py
@@ -0,0 +1,63 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_create_job_custom_attributes]
+
+from google.cloud import talent
+import six
+
+
+def create_job(project_id, tenant_id, company_id, requisition_id):
+ """Create Job with Custom Attributes"""
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # company_id = 'Company name, e.g. projects/your-project/companies/company-id'
+ # requisition_id = 'Job requisition ID, aka Posting ID. Unique per job.'
+ # language_code = 'en-US'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(company_id, six.binary_type):
+ company_id = company_id.decode("utf-8")
+
+ # Custom attribute can be string or numeric value,
+ # and can be filtered in search queries.
+ # https://cloud.google.com/talent-solution/job-search/docs/custom-attributes
+ custom_attribute = talent.types.CustomAttribute()
+ custom_attribute.filterable = True
+ custom_attribute.string_values.append("Intern")
+ custom_attribute.string_values.append("Apprenticeship")
+
+ parent = client.tenant_path(project_id, tenant_id)
+
+ job = {
+ "company": company_id,
+ "title": "Software Engineer",
+ "requisition_id": requisition_id,
+ "description": "This is a description of this job",
+ "language_code": "en-US",
+ "custom_attributes": {"FOR_STUDENTS": custom_attribute},
+ }
+
+ response = client.create_job(parent, job)
+ print("Created job: {}".format(response.name))
+ return response.name
+
+
+# [END job_search_create_job_custom_attributes]
diff --git a/jobs/v4beta1/job_search_create_job_custom_attributes_test.py b/jobs/v4beta1/job_search_create_job_custom_attributes_test.py
new file mode 100644
index 000000000000..028fedb7074c
--- /dev/null
+++ b/jobs/v4beta1/job_search_create_job_custom_attributes_test.py
@@ -0,0 +1,46 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import uuid
+
+import pytest
+
+import job_search_create_job_custom_attributes
+import job_search_delete_job
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+JOB_EXT_UNIQUE_ID = "TEST_JOB_{}".format(uuid.uuid4())
+
+
+def test_create_job_with_attributes(capsys, tenant, company, cleaner):
+ job_name = job_search_create_job_custom_attributes.create_job(
+ PROJECT_ID, tenant, company, JOB_EXT_UNIQUE_ID
+ )
+ out, _ = capsys.readouterr()
+ assert "Created job:" in out
+
+ # extract job id
+ job_id = job_name.split("/")[-1]
+ cleaner.append(job_id)
+
+
+@pytest.fixture(scope="module")
+def cleaner(tenant):
+ jobs = []
+
+ yield jobs
+
+ for job_id in jobs:
+ job_search_delete_job.delete_job(PROJECT_ID, tenant, job_id)
diff --git a/jobs/v4beta1/job_search_create_job_test.py b/jobs/v4beta1/job_search_create_job_test.py
new file mode 100644
index 000000000000..505d27f6c379
--- /dev/null
+++ b/jobs/v4beta1/job_search_create_job_test.py
@@ -0,0 +1,47 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import uuid
+
+import pytest
+
+import job_search_create_job
+import job_search_delete_job
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+JOB_EXT_UNIQUE_ID = "TEST_JOB_{}".format(uuid.uuid4())
+
+
+def test_create_job(capsys, tenant, company, cleaner):
+ # create a job
+ job_name = job_search_create_job.create_job(
+ PROJECT_ID, tenant, company, JOB_EXT_UNIQUE_ID, "www.example.com"
+ )
+ out, _ = capsys.readouterr()
+ assert "Created job:" in out
+
+ # extract job id
+ job_id = job_name.split("/")[-1]
+ cleaner.append(job_id)
+
+
+@pytest.fixture(scope="module")
+def cleaner(tenant):
+ jobs = []
+
+ yield jobs
+
+ for job_id in jobs:
+ job_search_delete_job.delete_job(PROJECT_ID, tenant, job_id)
diff --git a/jobs/v4beta1/job_search_create_tenant.py b/jobs/v4beta1/job_search_create_tenant.py
new file mode 100644
index 000000000000..8d4fde32811c
--- /dev/null
+++ b/jobs/v4beta1/job_search_create_tenant.py
@@ -0,0 +1,43 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_create_tenant]
+
+from google.cloud import talent
+import six
+
+
+def create_tenant(project_id, external_id):
+ """Create Tenant for scoping resources, e.g. companies and jobs"""
+
+ client = talent.TenantServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # external_id = 'Your Unique Identifier for Tenant'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(external_id, six.binary_type):
+ external_id = external_id.decode("utf-8")
+ parent = client.project_path(project_id)
+ tenant = {"external_id": external_id}
+
+ response = client.create_tenant(parent, tenant)
+ print("Created Tenant")
+ print("Name: {}".format(response.name))
+ print("External ID: {}".format(response.external_id))
+ return response.name
+
+
+# [END job_search_create_tenant]
diff --git a/jobs/v4beta1/job_search_create_tenant_test.py b/jobs/v4beta1/job_search_create_tenant_test.py
new file mode 100644
index 000000000000..e8c9c0495fbe
--- /dev/null
+++ b/jobs/v4beta1/job_search_create_tenant_test.py
@@ -0,0 +1,48 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import uuid
+
+import pytest
+
+import job_search_create_tenant
+import job_search_delete_tenant
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+TENANT_EXT_UNIQUE_ID = "TEST_TENANT_{}".format(uuid.uuid4())
+
+
+def test_create_tenant(capsys, cleaner):
+ # create tenant
+ tenant_name = job_search_create_tenant.create_tenant(
+ PROJECT_ID, TENANT_EXT_UNIQUE_ID
+ )
+ out, _ = capsys.readouterr()
+ assert "Created Tenant" in out
+ assert "Name:" in out
+
+ # extract tenant id
+ tenant_id = tenant_name.split("/")[-1]
+ cleaner.append(tenant_id)
+
+
+@pytest.fixture(scope="module")
+def cleaner():
+ tenants = []
+
+ yield tenants
+
+ for tenant_id in tenants:
+ job_search_delete_tenant.delete_tenant(PROJECT_ID, tenant_id)
diff --git a/jobs/v4beta1/job_search_custom_ranking_search.py b/jobs/v4beta1/job_search_custom_ranking_search.py
new file mode 100644
index 000000000000..1b33aab36216
--- /dev/null
+++ b/jobs/v4beta1/job_search_custom_ranking_search.py
@@ -0,0 +1,64 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_custom_ranking_search]
+
+from google.cloud import talent
+from google.cloud.talent import enums
+import six
+
+
+def search_jobs(project_id, tenant_id):
+ """Search Jobs using custom rankings"""
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+ domain = "www.example.com"
+ session_id = "Hashed session identifier"
+ user_id = "Hashed user identifier"
+ request_metadata = {"domain": domain, "session_id": session_id, "user_id": user_id}
+ importance_level = enums.SearchJobsRequest.CustomRankingInfo.ImportanceLevel.EXTREME
+ ranking_expression = "(someFieldLong + 25) * 0.25"
+ custom_ranking_info = {
+ "importance_level": importance_level,
+ "ranking_expression": ranking_expression,
+ }
+ order_by = "custom_ranking desc"
+
+ # Iterate over all results
+ results = []
+ for response_item in client.search_jobs(
+ parent,
+ request_metadata,
+ custom_ranking_info=custom_ranking_info,
+ order_by=order_by,
+ ):
+ print("Job summary: {}".format(response_item.job_summary))
+ print("Job title snippet: {}".format(response_item.job_title_snippet))
+ job = response_item.job
+ results.append(job.name)
+ print("Job name: {}".format(job.name))
+ print("Job title: {}".format(job.title))
+ return results
+
+
+# [END job_search_custom_ranking_search]
diff --git a/jobs/v4beta1/job_search_custom_ranking_search_test.py b/jobs/v4beta1/job_search_custom_ranking_search_test.py
new file mode 100644
index 000000000000..3a8e80bcbb0a
--- /dev/null
+++ b/jobs/v4beta1/job_search_custom_ranking_search_test.py
@@ -0,0 +1,25 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_custom_ranking_search
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_search_jobs_custom_ranking(tenant):
+ jobs = job_search_custom_ranking_search.search_jobs(PROJECT_ID, tenant)
+ for job in jobs:
+ assert "projects/" in job
diff --git a/jobs/v4beta1/job_search_delete_company.py b/jobs/v4beta1/job_search_delete_company.py
new file mode 100644
index 000000000000..1eb1ed19355d
--- /dev/null
+++ b/jobs/v4beta1/job_search_delete_company.py
@@ -0,0 +1,42 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_delete_company]
+
+from google.cloud import talent
+import six
+
+
+def delete_company(project_id, tenant_id, company_id):
+ """Delete Company"""
+
+ client = talent.CompanyServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # company_id = 'ID of the company to delete'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(company_id, six.binary_type):
+ company_id = company_id.decode("utf-8")
+ name = client.company_path(project_id, tenant_id, company_id)
+
+ client.delete_company(name)
+ print("Deleted company")
+
+
+# [END job_search_delete_company]
diff --git a/jobs/v4beta1/job_search_delete_company_test.py b/jobs/v4beta1/job_search_delete_company_test.py
new file mode 100644
index 000000000000..f581935b0c43
--- /dev/null
+++ b/jobs/v4beta1/job_search_delete_company_test.py
@@ -0,0 +1,27 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_delete_company
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_delete_company(capsys, tenant, company):
+ out, _ = capsys.readouterr()
+
+ job_search_delete_company.delete_company(PROJECT_ID, tenant, company)
+ out, _ = capsys.readouterr()
+ assert "Deleted" in out
diff --git a/jobs/v4beta1/job_search_delete_job.py b/jobs/v4beta1/job_search_delete_job.py
new file mode 100644
index 000000000000..f6dd0cf38e50
--- /dev/null
+++ b/jobs/v4beta1/job_search_delete_job.py
@@ -0,0 +1,42 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_delete_job]
+
+from google.cloud import talent
+import six
+
+
+def delete_job(project_id, tenant_id, job_id):
+ """Delete Job"""
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # job_id = 'Company ID'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(job_id, six.binary_type):
+ job_id = job_id.decode("utf-8")
+ name = client.job_path(project_id, tenant_id, job_id)
+
+ client.delete_job(name)
+ print("Deleted job.")
+
+
+# [END job_search_delete_job]
diff --git a/jobs/v4beta1/job_search_delete_job_test.py b/jobs/v4beta1/job_search_delete_job_test.py
new file mode 100644
index 000000000000..ef151a2b53cc
--- /dev/null
+++ b/jobs/v4beta1/job_search_delete_job_test.py
@@ -0,0 +1,25 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_delete_job
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_delete_job(capsys, tenant, job):
+ job_search_delete_job.delete_job(PROJECT_ID, tenant, job)
+ out, _ = capsys.readouterr()
+ assert "Deleted" in out
diff --git a/jobs/v4beta1/job_search_delete_tenant.py b/jobs/v4beta1/job_search_delete_tenant.py
new file mode 100644
index 000000000000..9d95498bd44d
--- /dev/null
+++ b/jobs/v4beta1/job_search_delete_tenant.py
@@ -0,0 +1,39 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_delete_tenant]
+
+from google.cloud import talent
+import six
+
+
+def delete_tenant(project_id, tenant_id):
+ """Delete Tenant"""
+
+ client = talent.TenantServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID)'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ name = client.tenant_path(project_id, tenant_id)
+
+ client.delete_tenant(name)
+ print("Deleted Tenant.")
+
+
+# [END job_search_delete_tenant]
diff --git a/jobs/v4beta1/job_search_delete_tenant_test.py b/jobs/v4beta1/job_search_delete_tenant_test.py
new file mode 100644
index 000000000000..a2fc490bbbca
--- /dev/null
+++ b/jobs/v4beta1/job_search_delete_tenant_test.py
@@ -0,0 +1,25 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_delete_tenant
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_delete_tenant(capsys, tenant):
+ job_search_delete_tenant.delete_tenant(PROJECT_ID, tenant)
+ out, _ = capsys.readouterr()
+ assert "Deleted" in out
diff --git a/jobs/v4beta1/job_search_get_company.py b/jobs/v4beta1/job_search_get_company.py
new file mode 100644
index 000000000000..ceac6e899002
--- /dev/null
+++ b/jobs/v4beta1/job_search_get_company.py
@@ -0,0 +1,43 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_get_company]
+
+from google.cloud import talent
+import six
+
+
+def get_company(project_id, tenant_id, company_id):
+ """Get Company"""
+
+ client = talent.CompanyServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # company_id = 'Company ID'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(company_id, six.binary_type):
+ company_id = company_id.decode("utf-8")
+ name = client.company_path(project_id, tenant_id, company_id)
+
+ response = client.get_company(name)
+ print("Company name: {}".format(response.name))
+ print("Display name: {}".format(response.display_name))
+
+
+# [END job_search_get_company]
diff --git a/jobs/v4beta1/job_search_get_company_test.py b/jobs/v4beta1/job_search_get_company_test.py
new file mode 100644
index 000000000000..f11263304da3
--- /dev/null
+++ b/jobs/v4beta1/job_search_get_company_test.py
@@ -0,0 +1,25 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_get_company
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_job_search_get_company(capsys, tenant, company):
+ job_search_get_company.get_company(PROJECT_ID, tenant, company)
+ out, _ = capsys.readouterr()
+ assert "Company name:" in out
diff --git a/jobs/v4beta1/job_search_get_job.py b/jobs/v4beta1/job_search_get_job.py
new file mode 100644
index 000000000000..f311202bcecf
--- /dev/null
+++ b/jobs/v4beta1/job_search_get_job.py
@@ -0,0 +1,52 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_get_job]
+
+from google.cloud import talent
+import six
+
+
+def get_job(project_id, tenant_id, job_id):
+ """Get Job"""
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # job_id = 'Job ID'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(job_id, six.binary_type):
+ job_id = job_id.decode("utf-8")
+ name = client.job_path(project_id, tenant_id, job_id)
+
+ response = client.get_job(name)
+ print("Job name: {}".format(response.name))
+ print("Requisition ID: {}".format(response.requisition_id))
+ print("Title: {}".format(response.title))
+ print("Description: {}".format(response.description))
+ print("Posting language: {}".format(response.language_code))
+ for address in response.addresses:
+ print("Address: {}".format(address))
+ for email in response.application_info.emails:
+ print("Email: {}".format(email))
+ for website_uri in response.application_info.uris:
+ print("Website: {}".format(website_uri))
+
+
+# [END job_search_get_job]
diff --git a/jobs/v4beta1/job_search_get_job_test.py b/jobs/v4beta1/job_search_get_job_test.py
new file mode 100644
index 000000000000..264c57725e9d
--- /dev/null
+++ b/jobs/v4beta1/job_search_get_job_test.py
@@ -0,0 +1,25 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_get_job
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_job_search_get_job(capsys, tenant, job):
+ job_search_get_job.get_job(PROJECT_ID, tenant, job)
+ out, _ = capsys.readouterr()
+ assert "Job name:" in out
diff --git a/jobs/v4beta1/job_search_get_tenant.py b/jobs/v4beta1/job_search_get_tenant.py
new file mode 100644
index 000000000000..484c44d6f035
--- /dev/null
+++ b/jobs/v4beta1/job_search_get_tenant.py
@@ -0,0 +1,40 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_get_tenant]
+
+from google.cloud import talent
+import six
+
+
+def get_tenant(project_id, tenant_id):
+ """Get Tenant by name"""
+
+ client = talent.TenantServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ name = client.tenant_path(project_id, tenant_id)
+
+ response = client.get_tenant(name)
+ print("Name: {}".format(response.name))
+ print("External ID: {}".format(response.external_id))
+
+
+# [END job_search_get_tenant]
diff --git a/jobs/v4beta1/job_search_get_tenant_test.py b/jobs/v4beta1/job_search_get_tenant_test.py
new file mode 100644
index 000000000000..d1f8c1cd8cfa
--- /dev/null
+++ b/jobs/v4beta1/job_search_get_tenant_test.py
@@ -0,0 +1,26 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import os
+
+import job_search_get_tenant
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_get_tenant(capsys, tenant):
+ job_search_get_tenant.get_tenant(PROJECT_ID, tenant)
+ out, _ = capsys.readouterr()
+ assert "Name: " in out
diff --git a/jobs/v4beta1/job_search_histogram_search.py b/jobs/v4beta1/job_search_histogram_search.py
new file mode 100644
index 000000000000..f238e6a620c9
--- /dev/null
+++ b/jobs/v4beta1/job_search_histogram_search.py
@@ -0,0 +1,65 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_histogram_search]
+
+from google.cloud import talent
+import six
+
+
+def search_jobs(project_id, tenant_id, query):
+ """
+ Search Jobs with histogram queries
+
+ Args:
+ query Histogram query
+ More info on histogram facets, constants, and built-in functions:
+ https://godoc.org/google.golang.org/genproto/googleapis/cloud/talent/v4beta1#SearchJobsRequest
+ """
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # query = 'count(base_compensation, [bucket(12, 20)])'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(query, six.binary_type):
+ query = query.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+ domain = "www.example.com"
+ session_id = "Hashed session identifier"
+ user_id = "Hashed user identifier"
+ request_metadata = {"domain": domain, "session_id": session_id, "user_id": user_id}
+ histogram_queries_element = {"histogram_query": query}
+ histogram_queries = [histogram_queries_element]
+
+ # Iterate over all results
+ results = []
+ for response_item in client.search_jobs(
+ parent, request_metadata, histogram_queries=histogram_queries
+ ):
+ print("Job summary: {}".format(response_item.job_summary))
+ print("Job title snippet: {}".format(response_item.job_title_snippet))
+ job = response_item.job
+ results.append(job)
+ print("Job name: {}".format(job.name))
+ print("Job title: {}".format(job.title))
+ return results
+
+
+# [END job_search_histogram_search]
diff --git a/jobs/v4beta1/job_search_histogram_search_test.py b/jobs/v4beta1/job_search_histogram_search_test.py
new file mode 100644
index 000000000000..1f6594de9d61
--- /dev/null
+++ b/jobs/v4beta1/job_search_histogram_search_test.py
@@ -0,0 +1,26 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_histogram_search
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_search_jobs_histogram(tenant):
+ query = "count(base_compensation, [bucket(12, 20)])"
+ jobs = job_search_histogram_search.search_jobs(PROJECT_ID, tenant, query)
+ for job in jobs:
+ assert "projects/" in job
diff --git a/jobs/v4beta1/job_search_list_companies.py b/jobs/v4beta1/job_search_list_companies.py
new file mode 100644
index 000000000000..bdef589c150a
--- /dev/null
+++ b/jobs/v4beta1/job_search_list_companies.py
@@ -0,0 +1,45 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_list_companies]
+
+from google.cloud import talent
+import six
+
+
+def list_companies(project_id, tenant_id):
+ """List Companies"""
+
+ client = talent.CompanyServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+
+ # Iterate over all results
+ results = []
+ for company in client.list_companies(parent):
+ results.append(company.name)
+ print("Company Name: {}".format(company.name))
+ print("Display Name: {}".format(company.display_name))
+ print("External ID: {}".format(company.external_id))
+ return results
+
+
+# [END job_search_list_companies]
diff --git a/jobs/v4beta1/job_search_list_companies_test.py b/jobs/v4beta1/job_search_list_companies_test.py
new file mode 100644
index 000000000000..c8d71a850b7c
--- /dev/null
+++ b/jobs/v4beta1/job_search_list_companies_test.py
@@ -0,0 +1,25 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_list_companies
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_list_companies(tenant):
+ results = job_search_list_companies.list_companies(PROJECT_ID, tenant)
+ for company in results:
+ assert "projects/" in company.name
diff --git a/jobs/v4beta1/job_search_list_jobs.py b/jobs/v4beta1/job_search_list_jobs.py
new file mode 100644
index 000000000000..0ae52dc18610
--- /dev/null
+++ b/jobs/v4beta1/job_search_list_jobs.py
@@ -0,0 +1,56 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_list_jobs]
+
+from google.cloud import talent
+import six
+
+
+def list_jobs(project_id, tenant_id, filter_):
+ """List Jobs"""
+
+ client = talent.JobServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+ # tenant_id = 'Your Tenant ID (using tenancy is optional)'
+ # filter_ = 'companyName=projects/my-project/companies/company-id'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ if isinstance(tenant_id, six.binary_type):
+ tenant_id = tenant_id.decode("utf-8")
+ if isinstance(filter_, six.binary_type):
+ filter_ = filter_.decode("utf-8")
+ parent = client.tenant_path(project_id, tenant_id)
+
+ # Iterate over all results
+ results = []
+ for job in client.list_jobs(parent, filter_):
+ results.append(job.name)
+ print("Job name: {}".format(job.name))
+ print("Job requisition ID: {}".format(job.requisition_id))
+ print("Job title: {}".format(job.title))
+ print("Job description: {}".format(job.description))
+ return results
+
+
+# [END job_search_list_jobs]
+list_jobs(
+ "python-docs-samples-tests",
+ "b603d325-3fb5-4979-8994-eba4ecf726f4",
+ 'companyName="projects/{}/companies/{}"'.format(
+ "python-docs-samples-tests", "4c0b9887-8f69-429b-bc67-a072ef55ec3e"
+ ),
+)
diff --git a/jobs/v4beta1/job_search_list_jobs_test.py b/jobs/v4beta1/job_search_list_jobs_test.py
new file mode 100644
index 000000000000..a2187fd97f4b
--- /dev/null
+++ b/jobs/v4beta1/job_search_list_jobs_test.py
@@ -0,0 +1,26 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_list_jobs
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_list_jobs(capsys, tenant, company):
+ filter = 'companyName="projects/{}/companies/{}"'.format(PROJECT_ID, company)
+ jobs = job_search_list_jobs.list_jobs(PROJECT_ID, tenant, filter)
+ for job in jobs:
+ assert "projects/" in job
diff --git a/jobs/v4beta1/job_search_list_tenants.py b/jobs/v4beta1/job_search_list_tenants.py
new file mode 100644
index 000000000000..2045bccac5e6
--- /dev/null
+++ b/jobs/v4beta1/job_search_list_tenants.py
@@ -0,0 +1,38 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# [START job_search_list_tenants]
+
+from google.cloud import talent
+import six
+
+
+def list_tenants(project_id):
+ """List Tenants"""
+
+ client = talent.TenantServiceClient()
+
+ # project_id = 'Your Google Cloud Project ID'
+
+ if isinstance(project_id, six.binary_type):
+ project_id = project_id.decode("utf-8")
+ parent = client.project_path(project_id)
+
+ # Iterate over all results
+ for response_item in client.list_tenants(parent):
+ print("Tenant Name: {}".format(response_item.name))
+ print("External ID: {}".format(response_item.external_id))
+
+
+# [END job_search_list_tenants]
diff --git a/jobs/v4beta1/job_search_list_tenants_test.py b/jobs/v4beta1/job_search_list_tenants_test.py
new file mode 100644
index 000000000000..38d840d564a0
--- /dev/null
+++ b/jobs/v4beta1/job_search_list_tenants_test.py
@@ -0,0 +1,25 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import job_search_list_tenants
+
+PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
+
+
+def test_list_tenants(capsys):
+ job_search_list_tenants.list_tenants(PROJECT_ID)
+ out, _ = capsys.readouterr()
+ assert "Tenant Name:" in out
diff --git a/jobs/v4beta1/requirements-test.txt b/jobs/v4beta1/requirements-test.txt
new file mode 100644
index 000000000000..10b405fa748e
--- /dev/null
+++ b/jobs/v4beta1/requirements-test.txt
@@ -0,0 +1 @@
+pytest==5.4.2
\ No newline at end of file
diff --git a/jobs/v4beta1/requirements.txt b/jobs/v4beta1/requirements.txt
new file mode 100755
index 000000000000..d2d6347f5538
--- /dev/null
+++ b/jobs/v4beta1/requirements.txt
@@ -0,0 +1 @@
+google.cloud.talent==0.6.0
\ No newline at end of file