def test_search_assets(self):
        # Setup Expected Response
        next_page_token = ''
        total_size = 705419236
        assets_element = {}
        assets = [assets_element]
        expected_response = {
            'next_page_token': next_page_token,
            'total_size': total_size,
            'assets': assets
        }
        expected_response = messages_pb2.SearchAssetsResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = securitycenter_v1alpha3.SecurityCenterClient(channel=channel)

        # Setup Request
        org_name = client.organization_path('[ORGANIZATION]')

        paged_list_response = client.search_assets(org_name)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.assets[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = messages_pb2.SearchAssetsRequest(org_name=org_name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_modify_finding(self):
        # Setup Expected Response
        id_2 = 'id23227150'
        asset_id = 'assetId-373202742'
        scanner_id = 'scannerId-332541188'
        expected_response = {
            'id': id_2,
            'asset_id': asset_id,
            'scanner_id': scanner_id
        }
        expected_response = messages_pb2.Finding(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = securitycenter_v1alpha3.SecurityCenterClient(channel=channel)

        # Setup Request
        org_name = client.organization_path('[ORGANIZATION]')
        id_ = 'id3355'

        response = client.modify_finding(org_name, id_)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = messages_pb2.ModifyFindingRequest(
            org_name=org_name, id=id_)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_search_assets_exception(self):
        channel = ChannelStub(responses=[CustomException()])
        client = securitycenter_v1alpha3.SecurityCenterClient(channel=channel)

        # Setup request
        org_name = client.organization_path('[ORGANIZATION]')

        paged_list_response = client.search_assets(org_name)
        with pytest.raises(CustomException):
            list(paged_list_response)
    def test_modify_finding_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = securitycenter_v1alpha3.SecurityCenterClient(channel=channel)

        # Setup request
        org_name = client.organization_path('[ORGANIZATION]')
        id_ = 'id3355'

        with pytest.raises(CustomException):
            client.modify_finding(org_name, id_)
    def test_create_finding_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = securitycenter_v1alpha3.SecurityCenterClient(channel=channel)

        # Setup request
        org_name = client.organization_path('[ORGANIZATION]')
        source_finding = {}

        with pytest.raises(CustomException):
            client.create_finding(org_name, source_finding)
    def test_modify_asset(self):
        # Setup Expected Response
        id_2 = 'id23227150'
        parent_id = 'parentId2070327504'
        type_ = 'type3575610'
        expected_response = {'id': id_2, 'parent_id': parent_id, 'type': type_}
        expected_response = messages_pb2.Asset(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = securitycenter_v1alpha3.SecurityCenterClient(channel=channel)

        # Setup Request
        org_name = client.organization_path('[ORGANIZATION]')
        id_ = 'id3355'

        response = client.modify_asset(org_name, id_)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = messages_pb2.ModifyAssetRequest(
            org_name=org_name, id=id_)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request