Skip to content

Commit

Permalink
test: fix sample tests
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 committed Sep 25, 2020
1 parent ffe4a88 commit 5df7915
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 125 deletions.
16 changes: 7 additions & 9 deletions talent/job_search_autocomplete_job_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# [START job_search_autocomplete_job_title]

from google.cloud import talent_v4beta1
from google.cloud.talent import enums
import six


Expand All @@ -35,21 +34,20 @@ def complete_query(project_id, tenant_id, query):
if isinstance(query, six.binary_type):
query = query.decode("utf-8")

parent = client.tenant_path(project_id, tenant_id)
parent = f"projects/{project_id}/tenants/{tenant_id}"

response = client.complete_query(
parent,
query,
request = talent_v4beta1.CompleteQueryRequest(
parent=parent,
query=query,
page_size=5, # limit for number of results
language_codes=["en-US"], # language code
)
response = client.complete_query(request=request)
for result in response.completion_results:
print("Suggested title: {}".format(result.suggestion))
print(f"Suggested title: {result.suggestion}")
# Suggestion type is JOB_TITLE or COMPANY_TITLE
print(
"Suggestion type: {}".format(
enums.CompleteQueryRequest.CompletionType(result.type).name
)
f"Suggestion type: {talent_v4beta1.CompleteQueryRequest.CompletionType(result.type).name}"
)


Expand Down
4 changes: 2 additions & 2 deletions talent/job_search_batch_create_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def batch_create_jobs(
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)
parent = f"projects/{project_id}/tenants/{tenant_id}"
uris = [job_application_url_one]
application_info = {"uris": uris}
addresses = [address_one]
Expand All @@ -122,7 +122,7 @@ def batch_create_jobs(
}
jobs = [jobs_element, jobs_element_2]

operation = client.batch_create_jobs(parent, jobs)
operation = client.batch_create_jobs(parent=parent, jobs=jobs)

print("Waiting for operation to complete...")
response = operation.result(90)
Expand Down
46 changes: 24 additions & 22 deletions talent/job_search_batch_update_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,36 +103,38 @@ def batch_update_jobs(
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)
parent = f"projects/{project_id}/tenants/{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,
}
jobs_element = talent.Job(
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_element_2 = talent.Job(
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)
operation = client.batch_update_jobs(parent=parent, jobs=jobs)

print("Waiting for operation to complete...")
response = operation.result(90)
Expand Down
40 changes: 23 additions & 17 deletions talent/job_search_commute_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# [START job_search_commute_search]

from google.cloud import talent
from google.cloud.talent import enums
import six


Expand All @@ -31,35 +30,42 @@ def search_jobs(project_id, tenant_id):
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)
parent = f"projects/{project_id}/tenants/{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
request_metadata = talent.RequestMetadata(
domain=domain,
session_id=session_id,
user_id=user_id
)
commute_method = talent.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}
commute_filter = talent.CommuteFilter(
commute_method=commute_method,
travel_duration=travel_duration,
start_coordinates=start_coordinates,
)
job_query = talent.JobQuery(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))
request = talent.SearchJobsRequest(
parent=parent,
request_metadata=request_metadata,
job_query=job_query,
)
for response_item in client.search_jobs(request=request):
print(f"Job summary: {response_item.job_summary}")
print(f"Job title snippet: {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))
print(f"Job name: {job.name}")
print(f"Job title: {job.title}")
return results


Expand Down
4 changes: 2 additions & 2 deletions talent/job_search_create_client_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_client_event(project_id, tenant_id, request_id, event_id):
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)
parent = f"projects/{project_id}/tenants/{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
Expand All @@ -70,7 +70,7 @@ def create_client_event(project_id, tenant_id, request_id, event_id):
"job_event": job_event,
}

response = client.create_client_event(parent, client_event)
response = client.create_client_event(parent=parent, client_event=client_event)
print(response)


Expand Down
4 changes: 2 additions & 2 deletions talent/job_search_create_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def create_company(project_id, tenant_id, display_name, external_id):
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)
parent = f"projects/{project_id}/tenants/{tenant_id}"
company = {"display_name": display_name, "external_id": external_id}

response = client.create_company(parent, company)
response = client.create_company(parent=parent, company=company)
print("Created Company")
print("Name: {}".format(response.name))
print("Display Name: {}".format(response.display_name))
Expand Down
2 changes: 1 addition & 1 deletion talent/job_search_create_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_job(
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)
parent = f"projects/{project_id}/tenants/{tenant_id}"
uris = [job_application_url]
application_info = {"uris": uris}
addresses = [
Expand Down
24 changes: 12 additions & 12 deletions talent/job_search_create_job_custom_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ def create_job(project_id, tenant_id, company_id, requisition_id):
# 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 = talent.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)
parent = f"projects/{project_id}/tenants/{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},
}
job = talent.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))
response = client.create_job(parent=parent, job=job)
print(f"Created job: {response.name}")
return response.name


Expand Down
10 changes: 5 additions & 5 deletions talent/job_search_create_tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def create_tenant(project_id, external_id):
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}
parent = f"projects/{project_id}"
tenant = talent.Tenant(external_id=external_id)

response = client.create_tenant(parent, tenant)
response = client.create_tenant(parent=parent, tenant=tenant)
print("Created Tenant")
print("Name: {}".format(response.name))
print("External ID: {}".format(response.external_id))
print(f"Name: {response.name}")
print(f"External ID: {response.external_id}")
return response.name


Expand Down
30 changes: 17 additions & 13 deletions talent/job_search_custom_ranking_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# [START job_search_custom_ranking_search]

from google.cloud import talent
from google.cloud.talent import enums
import six


Expand All @@ -31,12 +30,16 @@ def search_jobs(project_id, tenant_id):
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)
parent = f"projects/{project_id}/tenants/{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
request_metadata = talent.RequestMetadata(
domain=domain,
session_id=session_id,
user_id=user_id
)
importance_level = talent.SearchJobsRequest.CustomRankingInfo.ImportanceLevel.EXTREME
ranking_expression = "(someFieldLong + 25) * 0.25"
custom_ranking_info = {
"importance_level": importance_level,
Expand All @@ -46,18 +49,19 @@ def search_jobs(project_id, tenant_id):

# Iterate over all results
results = []
for response_item in client.search_jobs(
parent,
request_metadata,
request = talent.SearchJobsRequest(
parent=parent,
request_metadata=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))
order_by=order_by
)
for response_item in client.search_jobs(request=request):
print(f"Job summary: {response_item.job_summary}")
print(f"Job title snippet: {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))
print(f"Job name: {job.name}")
print(f"Job title: {job.title}")
return results


Expand Down
2 changes: 1 addition & 1 deletion talent/job_search_delete_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def delete_company(project_id, tenant_id, company_id):
company_id = company_id.decode("utf-8")
name = client.company_path(project_id, tenant_id, company_id)

client.delete_company(name)
client.delete_company(name=name)
print("Deleted company")


Expand Down
2 changes: 1 addition & 1 deletion talent/job_search_delete_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def delete_job(project_id, tenant_id, job_id):
job_id = job_id.decode("utf-8")
name = client.job_path(project_id, tenant_id, job_id)

client.delete_job(name)
client.delete_job(name=name)
print("Deleted job.")


Expand Down
2 changes: 1 addition & 1 deletion talent/job_search_delete_tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def delete_tenant(project_id, tenant_id):
tenant_id = tenant_id.decode("utf-8")
name = client.tenant_path(project_id, tenant_id)

client.delete_tenant(name)
client.delete_tenant(name=name)
print("Deleted Tenant.")


Expand Down
6 changes: 3 additions & 3 deletions talent/job_search_get_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def get_company(project_id, tenant_id, company_id):
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))
response = client.get_company(name=name)
print(f"Company name: {response.name}")
print(f"Display name: {response.display_name}")


# [END job_search_get_company]
Loading

0 comments on commit 5df7915

Please sign in to comment.