def test_list_companies(self): # Setup Expected Response next_page_token = "" companies_element = {} companies = [companies_element] expected_response = {"next_page_token": next_page_token, "companies": companies} expected_response = company_service_pb2.ListCompaniesResponse( **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.CompanyServiceClient() # Setup Request parent = client.project_path("[PROJECT]") paged_list_response = client.list_companies(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.companies[0] == resources[0] assert len(channel.requests) == 1 expected_request = company_service_pb2.ListCompaniesRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def sample_create_company(project_id, tenant_id, display_name, external_id): """Create Company""" # [START job_search_create_company_core] client = talent_v4beta1.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))
def test_list_companies_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.CompanyServiceClient() # Setup request parent = client.project_path("[PROJECT]") paged_list_response = client.list_companies(parent) with pytest.raises(CustomException): list(paged_list_response)
def test_delete_company_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.CompanyServiceClient() # Setup request name = client.company_path("[PROJECT]", "[COMPANY]") with pytest.raises(CustomException): client.delete_company(name)
def test_update_company_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.CompanyServiceClient() # Setup request company = {} with pytest.raises(CustomException): client.update_company(company)
def test_create_company_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.CompanyServiceClient() # Setup request parent = client.tenant_path("[PROJECT]", "[TENANT]") company = {} with pytest.raises(CustomException): client.create_company(parent, company)
def test_delete_company(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.CompanyServiceClient() # Setup Request name = client.company_path("[PROJECT]", "[COMPANY]") client.delete_company(name) assert len(channel.requests) == 1 expected_request = company_service_pb2.DeleteCompanyRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_company(self): # Setup Expected Response name = "name3373707" display_name = "displayName1615086568" external_id = "externalId-1153075697" headquarters_address = "headquartersAddress-1879520036" hiring_agency = False eeo_text = "eeoText-1652097123" website_uri = "websiteUri-2118185016" career_site_uri = "careerSiteUri1223331861" image_uri = "imageUri-877823864" suspended = False expected_response = { "name": name, "display_name": display_name, "external_id": external_id, "headquarters_address": headquarters_address, "hiring_agency": hiring_agency, "eeo_text": eeo_text, "website_uri": website_uri, "career_site_uri": career_site_uri, "image_uri": image_uri, "suspended": suspended, } expected_response = company_pb2.Company(**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.CompanyServiceClient() # Setup Request parent = client.project_path("[PROJECT]") company = {} response = client.create_company(parent, company) assert expected_response == response assert len(channel.requests) == 1 expected_request = company_service_pb2.CreateCompanyRequest( parent=parent, company=company ) actual_request = channel.requests[0][1] assert expected_request == actual_request
def sample_list_companies(project_id): """List Companies""" # [START talent_list_companies_core] client = talent_v4beta1.CompanyServiceClient() # 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_companies(parent): print('Company: {}'.format(response_item.name)) print('Display name: {}'.format(response_item.display_name))
def list_companies(project_id): """List Companies""" client = talent_v4beta1.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') parent = client.project_path(project_id) # Iterate over all results for response_item in client.list_companies(parent): print('Company Name: {}'.format(response_item.name)) print('Display Name: {}'.format(response_item.display_name)) print('External ID: {}'.format(response_item.external_id))
def test_create_company(self): # Setup Expected Response name = 'name3373707' display_name = 'displayName1615086568' external_id = 'externalId-1153075697' headquarters_address = 'headquartersAddress-1879520036' hiring_agency = False eeo_text = 'eeoText-1652097123' website_uri = 'websiteUri-2118185016' career_site_uri = 'careerSiteUri1223331861' image_uri = 'imageUri-877823864' suspended = False expected_response = { 'name': name, 'display_name': display_name, 'external_id': external_id, 'headquarters_address': headquarters_address, 'hiring_agency': hiring_agency, 'eeo_text': eeo_text, 'website_uri': website_uri, 'career_site_uri': career_site_uri, 'image_uri': image_uri, 'suspended': suspended } expected_response = company_pb2.Company(**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.CompanyServiceClient() # Setup Request parent = client.tenant_path('[PROJECT]', '[TENANT]') company = {} response = client.create_company(parent, company) assert expected_response == response assert len(channel.requests) == 1 expected_request = company_service_pb2.CreateCompanyRequest( parent=parent, company=company) actual_request = channel.requests[0][1] assert expected_request == actual_request
def sample_delete_company(project_id, company_id): """Delete Company""" # [START talent_delete_company_core] client = talent_v4beta1.CompanyServiceClient() # project_id = 'Your Google Cloud Project ID' # company_id = 'ID of the company to delete' if isinstance(project_id, six.binary_type): project_id = project_id.decode('utf-8') if isinstance(company_id, six.binary_type): company_id = company_id.decode('utf-8') name = client.company_path(project_id, company_id) client.delete_company(name) print('Deleted company')
def sample_create_company(project_id, display_name): """Create Company""" # [START talent_create_company_core] client = talent_v4beta1.CompanyServiceClient() # project_id = 'Your Google Cloud Project ID' # display_name = 'My Company Name' if isinstance(project_id, six.binary_type): project_id = project_id.decode('utf-8') if isinstance(display_name, six.binary_type): display_name = display_name.decode('utf-8') parent = client.project_path(project_id) external_id = 'Identifier of this company in my system' company = {'display_name': display_name, 'external_id': external_id} response = client.create_company(parent, company) print('Created company: {}'.format(response.display_name)) print('Company name: {}'.format(response.name))
def sample_get_company(project_id, tenant_id, company_id): """Get Company""" # [START job_search_get_company_core] client = talent_v4beta1.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))