Ejemplo n.º 1
0
    def test_search_uris(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = webrisk_pb2.SearchUrisResponse(**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_v1beta1.WebRiskServiceV1Beta1Client()

        # Setup Request
        uri = "uri116076"
        threat_types = []

        response = client.search_uris(uri, threat_types)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = webrisk_pb2.SearchUrisRequest(
            uri=uri, threat_types=threat_types
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 2
0
    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_v1beta1.WebRiskServiceV1Beta1Client()

        # 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
Ejemplo n.º 3
0
    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_v1beta1.WebRiskServiceV1Beta1Client()

        with pytest.raises(CustomException):
            client.search_hashes()
Ejemplo n.º 4
0
    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_v1beta1.WebRiskServiceV1Beta1Client()

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

        with pytest.raises(CustomException):
            client.compute_threat_list_diff(threat_type, constraints)