def test_compute_threat_list_diff(self):
        # Setup Expected Response
        new_version_token = b"115"
        expected_response = {"new_version_token": new_version_token}
        expected_response = webrisk_pb2.ComputeThreatListDiffResponse(
            **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 = webrisk_v1.WebRiskServiceClient()

        # Setup Request
        threat_type = enums.ThreatType.THREAT_TYPE_UNSPECIFIED
        constraints = {}

        response = client.compute_threat_list_diff(threat_type, constraints)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = webrisk_pb2.ComputeThreatListDiffRequest(
            threat_type=threat_type, constraints=constraints)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_create_submission(self):
        # Setup Expected Response
        uri = "uri116076"
        expected_response = {"uri": uri}
        expected_response = webrisk_pb2.Submission(**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 = webrisk_v1.WebRiskServiceClient()

        # Setup Request
        parent = client.project_path("[PROJECT]")
        submission = {}

        response = client.create_submission(parent, submission)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = webrisk_pb2.CreateSubmissionRequest(
            parent=parent, submission=submission)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_search_hashes_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 = webrisk_v1.WebRiskServiceClient()

        # Setup request
        threat_types = []

        with pytest.raises(CustomException):
            client.search_hashes(threat_types)
    def test_compute_threat_list_diff_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 = webrisk_v1.WebRiskServiceClient()

        # Setup request
        threat_type = enums.ThreatType.THREAT_TYPE_UNSPECIFIED
        constraints = {}

        with pytest.raises(CustomException):
            client.compute_threat_list_diff(threat_type, constraints)
    def test_create_submission_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 = webrisk_v1.WebRiskServiceClient()

        # Setup request
        parent = client.project_path("[PROJECT]")
        submission = {}

        with pytest.raises(CustomException):
            client.create_submission(parent, submission)
    def test_search_hashes(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = webrisk_pb2.SearchHashesResponse(
            **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 = webrisk_v1.WebRiskServiceClient()

        # Setup Request
        threat_types = []

        response = client.search_hashes(threat_types)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = webrisk_pb2.SearchHashesRequest(
            threat_types=threat_types)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request