Exemplo n.º 1
0
    def list_available(self, selected_entities):
        """List available entities given some selected entities.

        Given one or more selections, return entities combinations that have
        data for the given selections.

        Parameters
        ----------
        selected_entities : dict

            Example::

                { 'metric_id': 123, 'item_id': 456, 'source_id': 7 }

            Keys may include: metric_id, item_id, region_id, partner_region_id,
            source_id, frequency_id

        Returns
        -------
        list of dicts

            Example::

                [ { 'metric_id': 11078, 'metric_name': 'Export Value (currency)',
                    'item_id': 274, 'item_name': 'Corn',
                    'region_id': 1215, 'region_name': 'United States',
                    'source_id': 15, 'source_name': 'USDA GATS' },
                  { ... },
                ... ]

        """
        return lib.list_available(self.access_token, self.api_host,
                                  selected_entities)
Exemplo n.º 2
0
def test_list_available(mock_requests_get):
    # Tests the base functionality
    mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)

    entities = {'metricId': '123', 'itemId': '456', 'regionId': '789'}

    assert lib.list_available(MOCK_TOKEN, MOCK_HOST, entities) == mock_data['data']
Exemplo n.º 3
0
def test_list_available(mock_requests_get):
    # Tests the base functionality
    mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)

    entities = {'metricId': '123', 'itemId': '456', 'regionId': '789'}

    assert lib.list_available(MOCK_TOKEN, MOCK_HOST,
                              entities) == mock_data['data']

    # Make sure that call now exists in the mock call stack
    mock_requests_get.assert_has_calls([
        mock.call('https://pytest.groclient.url/v2/entities/list',
                  headers={'authorization': 'Bearer pytest.groclient.token'},
                  params=entities,
                  timeout=None)
    ])
Exemplo n.º 4
0
def test_list_available_snake_to_camel(mock_requests_get):
    #Tests that the camel-ing fix is working properly.
    mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)

    entities = {'metric_id': '123', 'item_id': '456', 'regionId': '789'}
    entities_camel = {'metricId': '123', 'itemId': '456', 'regionId': '789'}

    assert lib.list_available(MOCK_TOKEN, MOCK_HOST,
                              entities) == mock_data["data"]

    # Make sure that call now exists in the mock call stack
    mock_requests_get.assert_has_calls([
        mock.call('https://pytest.groclient.url/v2/entities/list',
                  headers={'authorization': 'Bearer pytest.groclient.token'},
                  params=entities_camel,
                  timeout=None)
    ])
Exemplo n.º 5
0
 def list_available(self, selected_entities):
     return lib.list_available(self.access_token, self.api_host,
                               selected_entities)
Exemplo n.º 6
0
def test_list_available_snake_to_camel(mock_requests_get):
    # Tests that the camel-ing fix is working properly.
    mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)
    entities = {'metric_id': '123', 'item_id': '456', 'regionId': '789'}
    assert lib.list_available(MOCK_TOKEN, MOCK_HOST, entities) == mock_data['data']