Example #1
0
    def test_query_response(self, mock_query_response, mock_api_client_logon,
                            mock_api_client):
        mock_api_client_logon.return_value = None
        mock_api_client.return_value = None
        mocked_return_value = '108cb8b0-0744-4dd9-8e35-ea8311cd6211'
        mock_query_response.return_value = mocked_return_value

        config = {
            "auth": {
                "bxapikey": "placeholder"
            },
            "client_info": "placeholder"
        }
        connection = {
            "instance_crn": "placeholder",
            "target_cos": "placeholder"
        }
        query = '{"query":"SELECT target.id from cos://us-geo/at-data/rest.1*.json STORED AS JSON c"}'
        entry_point = EntryPoint(connection, config)
        query_response = entry_point.create_query_connection(query)

        assert query_response is not None
        assert 'search_id' in query_response
        assert query_response[
            'search_id'] == "108cb8b0-0744-4dd9-8e35-ea8311cd6211"
Example #2
0
    def test_query_flow(self, mock_results_response, mock_status_response,
                        mock_query_response, mock_api_client_logon,
                        mock_api_client):
        mock_api_client_logon.return_value = None
        mock_api_client.return_value = None
        results_mock = pd.DataFrame(columns=['id'])
        results_mock = results_mock.append(
            [{
                'id': 'crn:v1:bluemix:public:iam-identity::a/::apikey:1234'
            }],
            ignore_index=True)
        query_mock = '108cb8b0-0744-4dd9-8e35-ea8311cd6211'
        status_mock = json.loads(
            '{"status": "completed", "end_time": "2018-08-28T15:51:24.899Z", "submit_time": "2018-08-28T15:51:19.899Z"}'
        )
        mock_results_response.return_value = results_mock
        mock_status_response.return_value = status_mock
        mock_query_response.return_value = query_mock
        config = {
            "auth": {
                "bxapikey": "placeholder"
            },
            "client_info": "placeholder"
        }
        connection = {
            "instance_crn": "placeholder",
            "target_cos": "placeholder"
        }
        query = '{"query":"SELECT target.id from cos://us-geo/at-data/rest.1*.json STORED AS JSON c"}'
        entry_point = EntryPoint(connection, config)

        query_response = entry_point.create_query_connection(query)

        assert query_response is not None
        assert 'search_id' in query_response
        assert query_response[
            'search_id'] == "108cb8b0-0744-4dd9-8e35-ea8311cd6211"

        search_id = "108cb8b0-0744-4dd9-8e35-ea8311cd6211"
        status_response = entry_point.create_status_connection(search_id)

        assert status_response is not None
        assert 'status' in status_response
        assert status_response['status'] == Status.COMPLETED.value

        offset = 0
        length = 1
        results_response = entry_point.create_results_connection(
            search_id, offset, length)

        assert results_response is not None
        assert 'data' in results_response
        assert len(results_response['data']) > 0