Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Talent v4beta1 samples [Restoring deleted branch samples] #3273

Merged
merged 44 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fcbd9f3
restored deleted samples
munkhuushmgl Apr 3, 2020
fed3630
fixed lint issues
munkhuushmgl Apr 3, 2020
a9d5334
added tests and formatted code
munkhuushmgl Apr 23, 2020
ffa5704
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl Apr 23, 2020
2ac12c2
corrected test req.txt file
munkhuushmgl Apr 23, 2020
c05d682
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl Apr 23, 2020
6e79a1a
Merge branch 'master' into talent-v4beta1-samples
Apr 29, 2020
69a175b
made requested changes and added return val for samples
munkhuushmgl May 15, 2020
ea51187
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl May 15, 2020
84dcd99
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl May 15, 2020
e8a67b0
added secrets.txt to bash, script
munkhuushmgl May 15, 2020
3f28e5e
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl May 15, 2020
64f06af
fixed the lint
munkhuushmgl May 15, 2020
6f4fe16
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl May 15, 2020
7d22192
Merge branch 'master' into talent-v4beta1-samples
May 16, 2020
88ff29e
moved to requirements-test.txt
May 17, 2020
5340974
delete resources in teardown just in case
May 17, 2020
e454c4e
Merge branch 'master' into talent-v4beta1-samples
May 17, 2020
3a3efe9
restored deleted samples
munkhuushmgl Apr 3, 2020
ee75d23
resolved the conflicts
munkhuushmgl May 18, 2020
8974b3d
added some spacing
munkhuushmgl May 18, 2020
69d471a
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl May 18, 2020
b41139d
restored deleted samples
munkhuushmgl Apr 3, 2020
68c1c93
fixed merge conflicts
munkhuushmgl May 18, 2020
c44b313
fixed merge conflicts
munkhuushmgl May 18, 2020
64a71ae
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl May 18, 2020
ef7be49
added conftest.py and refactored samples with loop
munkhuushmgl May 19, 2020
6dd6793
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl May 19, 2020
a133f36
removed talent secret.txt from bash script
munkhuushmgl May 19, 2020
640151f
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl May 19, 2020
ab3bf67
fixed the lint issue
munkhuushmgl May 19, 2020
db5d438
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl May 19, 2020
72540a8
removed unnecessary env vars
munkhuushmgl May 19, 2020
489d96c
deleted global random ids, deleted unnecessary setup code from delete…
munkhuushmgl May 20, 2020
642aa6c
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl May 20, 2020
15ad14a
removed unused imports
munkhuushmgl May 20, 2020
55ec1cc
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl May 20, 2020
75ce337
removed pytest
munkhuushmgl May 20, 2020
e117bf4
removed unused IDs
munkhuushmgl May 20, 2020
6e05a60
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl May 20, 2020
7ec8505
deleted unused uuid imports
munkhuushmgl May 20, 2020
740f227
Merge branch 'talent-v4beta1-samples' of https://github.com/munkhuush…
munkhuushmgl May 20, 2020
76e3762
Merge branch 'master' into talent-v4beta1-samples
munkhuushmgl May 20, 2020
6526fbd
Merge branch 'master' into talent-v4beta1-samples
May 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions jobs/v4beta1/conftest.py
Original file line number Diff line number Diff line change
@@ -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"]

COMPANY_EXT_ID = "COMPANY_EXT_ID_{}".format(uuid.uuid4())
munkhuushmgl marked this conversation as resolved.
Show resolved Hide resolved
POST_UNIQUE_ID = "TEST_POST_{}".format(uuid.uuid4())[:20]
munkhuushmgl marked this conversation as resolved.
Show resolved Hide resolved
TENANT_EXT_UNIQUE_ID = "TEST_TENANT_{}".format(uuid.uuid4())


@pytest.fixture(scope="module")
def tenant():
# 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):
# 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):
# 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))
56 changes: 56 additions & 0 deletions jobs/v4beta1/job_search_autocomplete_job_title.py
Original file line number Diff line number Diff line change
@@ -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]
25 changes: 25 additions & 0 deletions jobs/v4beta1/job_search_autocomplete_job_title_test.py
Original file line number Diff line number Diff line change
@@ -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
133 changes: 133 additions & 0 deletions jobs/v4beta1/job_search_batch_create_jobs.py
Original file line number Diff line number Diff line change
@@ -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 <i>wonderful</i> 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 <i>wonderful</i> 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]
Loading