def test_list_jobs(self): # Setup Expected Response next_page_token = "" jobs_element = {} jobs = [jobs_element] expected_response = {"next_page_token": next_page_token, "jobs": jobs} expected_response = job_service_pb2.ListJobsResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup Request parent = client.tenant_path("[PROJECT]", "[TENANT]") filter_ = "filter-1274492040" paged_list_response = client.list_jobs(parent, filter_) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.jobs[0] == resources[0] assert len(channel.requests) == 1 expected_request = job_service_pb2.ListJobsRequest(parent=parent, filter=filter_) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_batch_update_jobs(self): # Setup Expected Response expected_response = {} expected_response = job_service_pb2.JobOperationResult( **expected_response) operation = operations_pb2.Operation( name="operations/test_batch_update_jobs", done=True) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup Request parent = client.tenant_path("[PROJECT]", "[TENANT]") jobs = [] response = client.batch_update_jobs(parent, jobs) result = response.result() assert expected_response == result assert len(channel.requests) == 1 expected_request = job_service_pb2.BatchUpdateJobsRequest( parent=parent, jobs=jobs) actual_request = channel.requests[0][1] assert expected_request == actual_request
def sample_get_job(project_id, tenant_id, job_id): """Get Job""" # [START job_search_get_job_core] client = talent_v4beta1.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))
def sample_create_job(project_id, tenant_id, company_name, requisition_id, language_code): """Create Job with Custom Attributes""" # [START job_search_create_job_custom_attributes_core] client = talent_v4beta1.JobServiceClient() # project_id = 'Your Google Cloud Project ID' # tenant_id = 'Your Tenant ID (using tenancy is optional)' # company_name = '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_name, six.binary_type): company_name = company_name.decode('utf-8') if isinstance(requisition_id, six.binary_type): requisition_id = requisition_id.decode('utf-8') if isinstance(language_code, six.binary_type): language_code = language_code.decode('utf-8') parent = client.tenant_path(project_id, tenant_id) job = { 'company': company_name, 'requisition_id': requisition_id, 'language_code': language_code } response = client.create_job(parent, job) print('Created job: {}'.format(response.name))
def sample_create_job(project_id, tenant_id, company_name, requisition_id, title, description, job_application_url, address_one, address_two, language_code): """Create Job""" # [START job_search_create_job_core] client = talent_v4beta1.JobServiceClient() # project_id = 'Your Google Cloud Project ID' # tenant_id = 'Your Tenant ID (using tenancy is optional)' # company_name = '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 <i>wonderful</i> 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_name, six.binary_type): company_name = company_name.decode('utf-8') if isinstance(requisition_id, six.binary_type): requisition_id = requisition_id.decode('utf-8') if isinstance(title, six.binary_type): title = title.decode('utf-8') if isinstance(description, six.binary_type): description = description.decode('utf-8') if isinstance(job_application_url, six.binary_type): job_application_url = job_application_url.decode('utf-8') if isinstance(address_one, six.binary_type): address_one = address_one.decode('utf-8') if isinstance(address_two, six.binary_type): address_two = address_two.decode('utf-8') if isinstance(language_code, six.binary_type): language_code = language_code.decode('utf-8') parent = client.tenant_path(project_id, tenant_id) uris = [job_application_url] application_info = {'uris': uris} addresses = [address_one, address_two] job = { 'company': company_name, 'requisition_id': requisition_id, 'title': title, 'description': description, 'application_info': application_info, 'addresses': addresses, 'language_code': language_code } response = client.create_job(parent, job) print('Created job: {}'.format(response.name))
def test_update_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup request job = {} with pytest.raises(CustomException): client.update_job(job)
def test_delete_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup request name = client.job_path("[PROJECT]", "[TENANT]", "[JOBS]") with pytest.raises(CustomException): client.delete_job(name)
def test_search_jobs_exception(self): channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup request parent = client.tenant_path("[PROJECT]", "[TENANT]") request_metadata = {} paged_list_response = client.search_jobs(parent, request_metadata) with pytest.raises(CustomException): list(paged_list_response)
def test_batch_delete_jobs_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup request parent = client.tenant_path("[PROJECT]", "[TENANT]") filter_ = "filter-1274492040" with pytest.raises(CustomException): client.batch_delete_jobs(parent, filter_)
def test_list_jobs_exception(self): channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup request parent = client.project_path("[PROJECT]") filter_ = "filter-1274492040" paged_list_response = client.list_jobs(parent, filter_) with pytest.raises(CustomException): list(paged_list_response)
def test_create_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup request parent = client.tenant_path('[PROJECT]', '[TENANT]') job = {} with pytest.raises(CustomException): client.create_job(parent, job)
def test_create_job(self): # Setup Expected Response name = "name3373707" company = "company950484093" requisition_id = "requisitionId980224926" title = "title110371416" description = "description-1724546052" department = "department848184146" incentives = "incentives-1262874520" language_code = "languageCode-412800396" promotion_value = 353413845 qualifications = "qualifications1903501412" responsibilities = "responsibilities-926952660" company_display_name = "companyDisplayName1982424170" expected_response = { "name": name, "company": company, "requisition_id": requisition_id, "title": title, "description": description, "department": department, "incentives": incentives, "language_code": language_code, "promotion_value": promotion_value, "qualifications": qualifications, "responsibilities": responsibilities, "company_display_name": company_display_name, } expected_response = job_pb2.Job(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup Request parent = client.tenant_path("[PROJECT]", "[TENANT]") job = {} response = client.create_job(parent, job) assert expected_response == response assert len(channel.requests) == 1 expected_request = job_service_pb2.CreateJobRequest(parent=parent, job=job) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_job(self): # Setup Expected Response name = 'name3373707' company = 'company950484093' requisition_id = 'requisitionId980224926' title = 'title110371416' description = 'description-1724546052' department = 'department848184146' incentives = 'incentives-1262874520' language_code = 'languageCode-412800396' promotion_value = 353413845 qualifications = 'qualifications1903501412' responsibilities = 'responsibilities-926952660' company_display_name = 'companyDisplayName1982424170' expected_response = { 'name': name, 'company': company, 'requisition_id': requisition_id, 'title': title, 'description': description, 'department': department, 'incentives': incentives, 'language_code': language_code, 'promotion_value': promotion_value, 'qualifications': qualifications, 'responsibilities': responsibilities, 'company_display_name': company_display_name } expected_response = job_pb2.Job(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup Request parent = client.tenant_path('[PROJECT]', '[TENANT]') job = {} response = client.create_job(parent, job) assert expected_response == response assert len(channel.requests) == 1 expected_request = job_service_pb2.CreateJobRequest(parent=parent, job=job) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_delete_job(self): channel = ChannelStub() patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup Request name = client.job_path("[PROJECT]", "[TENANT]", "[JOBS]") client.delete_job(name) assert len(channel.requests) == 1 expected_request = job_service_pb2.DeleteJobRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_batch_delete_jobs(self): channel = ChannelStub() patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup Request parent = client.tenant_path("[PROJECT]", "[TENANT]") filter_ = "filter-1274492040" client.batch_delete_jobs(parent, filter_) assert len(channel.requests) == 1 expected_request = job_service_pb2.BatchDeleteJobsRequest( parent=parent, filter=filter_) actual_request = channel.requests[0][1] assert expected_request == actual_request
def sample_search_jobs(project_id, tenant_id): """Search Jobs using commute distance""" # [START job_search_commute_search_core] client = talent_v4beta1.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 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 print('Job name: {}'.format(job.name)) print('Job title: {}'.format(job.title))
def sample_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 """ # [START job_search_histogram_search_core] client = talent_v4beta1.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 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 print('Job name: {}'.format(job.name)) print('Job title: {}'.format(job.title))
def sample_delete_job(project_id, tenant_id, job_id): """Delete Job""" # [START job_search_delete_job_core] client = talent_v4beta1.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.')
def sample_search_jobs(project_id, tenant_id): """Search Jobs using custom rankings""" # [START job_search_custom_ranking_search_core] client = talent_v4beta1.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 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 print('Job name: {}'.format(job.name)) print('Job title: {}'.format(job.title))
def test_search_jobs_for_alert(self): # Setup Expected Response next_page_token = "" estimated_total_size = 1882144769 total_size = 705419236 broadened_query_jobs_count = 1432104658 matching_jobs_element = {} matching_jobs = [matching_jobs_element] expected_response = { "next_page_token": next_page_token, "estimated_total_size": estimated_total_size, "total_size": total_size, "broadened_query_jobs_count": broadened_query_jobs_count, "matching_jobs": matching_jobs, } expected_response = job_service_pb2.SearchJobsResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup Request parent = client.tenant_path("[PROJECT]", "[TENANT]") request_metadata = {} paged_list_response = client.search_jobs_for_alert( parent, request_metadata) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.matching_jobs[0] == resources[0] assert len(channel.requests) == 1 expected_request = job_service_pb2.SearchJobsRequest( parent=parent, request_metadata=request_metadata) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_batch_update_jobs_exception(self): # Setup Response error = status_pb2.Status() operation = operations_pb2.Operation( name="operations/test_batch_update_jobs_exception", done=True) operation.error.CopyFrom(error) # Mock the API response channel = ChannelStub(responses=[operation]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = talent_v4beta1.JobServiceClient() # Setup Request parent = client.tenant_path("[PROJECT]", "[TENANT]") jobs = [] response = client.batch_update_jobs(parent, jobs) exception = response.exception() assert exception.errors[0] == error
def sample_list_jobs(project_id, tenant_id, filter_): """List Jobs""" # [START job_search_list_jobs_core] client = talent_v4beta1.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 for response_item in client.list_jobs(parent, filter_): print('Job name: {}'.format(response_item.name)) print('Job requisition ID: {}'.format(response_item.requisition_id)) print('Job title: {}'.format(response_item.title)) print('Job description: {}'.format(response_item.description))