def test_set_iam_policy(self): # Setup Expected Response version = 351608024 etag = b"21" expected_response = {"version": version, "etag": etag} expected_response = policy_pb2.Policy(**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 = datacatalog_v1beta1.PolicyTagManagerClient() # Setup Request resource = "resource-341064690" policy = {} response = client.set_iam_policy(resource, policy) assert expected_response == response assert len(channel.requests) == 1 expected_request = iam_policy_pb2.SetIamPolicyRequest( resource=resource, policy=policy) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_taxonomy(self): # Setup Expected Response name = "name3373707" display_name = "displayName1615086568" description = "description-1724546052" expected_response = { "name": name, "display_name": display_name, "description": description, } expected_response = policytagmanager_pb2.Taxonomy(**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 = datacatalog_v1beta1.PolicyTagManagerClient() response = client.create_taxonomy() assert expected_response == response assert len(channel.requests) == 1 expected_request = policytagmanager_pb2.CreateTaxonomyRequest() actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_test_iam_permissions(self): # Setup Expected Response expected_response = {} expected_response = iam_policy_pb2.TestIamPermissionsResponse( **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 = datacatalog_v1beta1.PolicyTagManagerClient() # Setup Request resource = "resource-341064690" permissions = [] response = client.test_iam_permissions(resource, permissions) assert expected_response == response assert len(channel.requests) == 1 expected_request = iam_policy_pb2.TestIamPermissionsRequest( resource=resource, permissions=permissions) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_policy_tag(self): # Setup Expected Response name_2 = "name2-1052831874" display_name = "displayName1615086568" description = "description-1724546052" parent_policy_tag = "parentPolicyTag2071382466" expected_response = { "name": name_2, "display_name": display_name, "description": description, "parent_policy_tag": parent_policy_tag, } expected_response = policytagmanager_pb2.PolicyTag(**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 = datacatalog_v1beta1.PolicyTagManagerClient() # Setup Request name = client.policy_tag_path("[PROJECT]", "[LOCATION]", "[TAXONOMY]", "[POLICY_TAG]") response = client.get_policy_tag(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = policytagmanager_pb2.GetPolicyTagRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_policy_tags(self): # Setup Expected Response next_page_token = "" policy_tags_element = {} policy_tags = [policy_tags_element] expected_response = { "next_page_token": next_page_token, "policy_tags": policy_tags, } expected_response = policytagmanager_pb2.ListPolicyTagsResponse( **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 = datacatalog_v1beta1.PolicyTagManagerClient() # Setup Request parent = client.taxonomy_path("[PROJECT]", "[LOCATION]", "[TAXONOMY]") paged_list_response = client.list_policy_tags(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.policy_tags[0] == resources[0] assert len(channel.requests) == 1 expected_request = policytagmanager_pb2.ListPolicyTagsRequest( parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_taxonomy_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 = datacatalog_v1beta1.PolicyTagManagerClient() with pytest.raises(CustomException): client.create_taxonomy()
def test_delete_policy_tag(self): channel = ChannelStub() patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = datacatalog_v1beta1.PolicyTagManagerClient() client.delete_policy_tag() assert len(channel.requests) == 1 expected_request = policytagmanager_pb2.DeletePolicyTagRequest() actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_iam_policy_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 = datacatalog_v1beta1.PolicyTagManagerClient() # Setup request resource = "resource-341064690" with pytest.raises(CustomException): client.get_iam_policy(resource)
def test_list_policy_tags_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 = datacatalog_v1beta1.PolicyTagManagerClient() # Setup request parent = client.taxonomy_path("[PROJECT]", "[LOCATION]", "[TAXONOMY]") paged_list_response = client.list_policy_tags(parent) with pytest.raises(CustomException): list(paged_list_response)
def test_get_taxonomy_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 = datacatalog_v1beta1.PolicyTagManagerClient() # Setup request name = client.taxonomy_path("[PROJECT]", "[LOCATION]", "[TAXONOMY]") with pytest.raises(CustomException): client.get_taxonomy(name)
def test_delete_taxonomy(self): channel = ChannelStub() patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = datacatalog_v1beta1.PolicyTagManagerClient() # Setup Request name = client.taxonomy_path("[PROJECT]", "[LOCATION]", "[TAXONOMY]") client.delete_taxonomy(name) assert len(channel.requests) == 1 expected_request = policytagmanager_pb2.DeleteTaxonomyRequest( name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_policy_tags(self): # Setup Expected Response next_page_token = "nextPageToken-1530815211" expected_response = {"next_page_token": next_page_token} expected_response = policytagmanager_pb2.ListPolicyTagsResponse( **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 = datacatalog_v1beta1.PolicyTagManagerClient() response = client.list_policy_tags() assert expected_response == response assert len(channel.requests) == 1 expected_request = policytagmanager_pb2.ListPolicyTagsRequest() actual_request = channel.requests[0][1] assert expected_request == actual_request