Example #1
0
    def get_data_series(self, **selection):
        """Get available data series for the given selections.

        https://developers.gro-intelligence.com/data-series-definition.html

        Parameters
        ----------
        metric_id : integer, optional
        item_id : integer, optional
        region_id : integer, optional
        partner_region_id : integer, optional
        source_id : integer, optional
        frequency_id : integer, optional

        Returns
        -------
        list of dicts

            Example::

                [{ 'metric_id': 2020032, 'metric_name': 'Seed Use',
                   'item_id': 274, 'item_name': 'Corn',
                   'region_id': 1215, 'region_name': 'United States',
                   'source_id': 24, 'source_name': 'USDA FEEDGRAINS',
                   'frequency_id': 7,
                   'start_date': '1975-03-01T00:00:00.000Z',
                   'end_date': '2018-05-31T00:00:00.000Z'
                 }, { ... }, ... ]

        """
        return lib.get_data_series(self.access_token, self.api_host,
                                   **selection)
Example #2
0
def test_get_data_series(mock_requests_get):
    # Test general case
    mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)
    selection_dict = {
        'item_id': 123,
        'metric_id': 456,
        'region_id': 789,
        'partner_region_id': 161718,
        'frequency_id': 101112,
        'source_id': 12
    }

    assert lib.get_data_series(MOCK_TOKEN, MOCK_HOST,
                               **selection_dict) == mock_data['data']

    # Make sure that call now exists in the mock call stack
    assert [
        mock.call('https://pytest.groclient.url/v2/data_series/list',
                  headers={'authorization': 'Bearer pytest.groclient.token'},
                  params={
                      'itemId': 123,
                      'metricId': 456,
                      'regionId': 789,
                      'partnerRegionId': 161718,
                      'frequencyId': 101112,
                      'sourceId': 12
                  },
                  timeout=None)
    ] == mock_requests_get.call_args_list
Example #3
0
def test_get_data_series(mock_requests_get):
    # Test general case
    mock_data = initialize_requests_mocker_and_get_mock_data(mock_requests_get)
    selection_dict = {'item_id': 123, 'metric_id': 456, 'region_id': 789,
                      'partner_region_id': 161718, 'frequency_id': 101112, 'source_id': 12}

    assert lib.get_data_series(MOCK_TOKEN, MOCK_HOST, **selection_dict) == mock_data['data']
Example #4
0
 def get_data_series(self, **selection):
     return lib.get_data_series(self.access_token, self.api_host,
                                **selection)