def test_update_tenant(self): # Setup Expected Response name = 'name3373707' external_id = 'externalId-1153075697' expected_response = {'name': name, 'external_id': external_id} expected_response = tenant_pb2.Tenant(**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.TenantServiceClient() # Setup Request tenant = {} response = client.update_tenant(tenant) assert expected_response == response assert len(channel.requests) == 1 expected_request = tenant_service_pb2.UpdateTenantRequest( tenant=tenant) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_tenant(self): # Setup Expected Response name = "name3373707" external_id = "externalId-1153075697" expected_response = {"name": name, "external_id": external_id} expected_response = tenant_pb2.Tenant(**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.TenantServiceClient() # Setup Request parent = client.project_path("[PROJECT]") tenant = {} response = client.create_tenant(parent, tenant) assert expected_response == response assert len(channel.requests) == 1 expected_request = tenant_service_pb2.CreateTenantRequest( parent=parent, tenant=tenant) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_tenants(self): # Setup Expected Response next_page_token = "" tenants_element = {} tenants = [tenants_element] expected_response = { "next_page_token": next_page_token, "tenants": tenants } expected_response = tenant_service_pb2.ListTenantsResponse( **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.TenantServiceClient() # Setup Request parent = client.project_path("[PROJECT]") paged_list_response = client.list_tenants(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.tenants[0] == resources[0] assert len(channel.requests) == 1 expected_request = tenant_service_pb2.ListTenantsRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_delete_tenant_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.TenantServiceClient() # Setup request name = client.tenant_path("[PROJECT]", "[TENANT]") with pytest.raises(CustomException): client.delete_tenant(name)
def test_list_tenants_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.TenantServiceClient() # Setup request parent = client.project_path("[PROJECT]") paged_list_response = client.list_tenants(parent) with pytest.raises(CustomException): list(paged_list_response)
def test_update_tenant_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.TenantServiceClient() # Setup request tenant = {} with pytest.raises(CustomException): client.update_tenant(tenant)
def test_create_tenant_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.TenantServiceClient() # Setup request parent = client.project_path('[PROJECT]') tenant = {} with pytest.raises(CustomException): client.create_tenant(parent, tenant)
def test_delete_tenant(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.TenantServiceClient() # Setup Request name = client.tenant_path("[PROJECT]", "[TENANT]") client.delete_tenant(name) assert len(channel.requests) == 1 expected_request = tenant_service_pb2.DeleteTenantRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def sample_list_tenants(project_id): """List Tenants""" # [START job_search_list_tenants_core] client = talent_v4beta1.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))
def sample_delete_tenant(project_id, tenant_id): """Delete Tenant""" # [START job_search_delete_tenant_core] client = talent_v4beta1.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.')
def sample_get_tenant(project_id, tenant_id): """Get Tenant by name""" # [START job_search_get_tenant_core] client = talent_v4beta1.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))
def sample_create_tenant(project_id, external_id): """Create Tenant for scoping resources, e.g. companies and jobs""" # [START job_search_create_tenant_core] client = talent_v4beta1.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))
def test_get_tenant(self): # Setup Expected Response name_2 = "name2-1052831874" external_id = "externalId-1153075697" expected_response = {"name": name_2, "external_id": external_id} expected_response = tenant_pb2.Tenant(**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.TenantServiceClient() # Setup Request name = client.tenant_path("[PROJECT]", "[TENANT]") response = client.get_tenant(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = tenant_service_pb2.GetTenantRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request