예제 #1
0
def test_lookup_belongs(mock_requests_get, lookup_mocked):
    # Set up
    # mock return values
    mock_data = ['obj1', 'obj2']
    mock_requests_get.return_value.json.return_value = {
        'data': {
            'test_entity': [1, 2, 3]
        }
    }
    mock_requests_get.return_value.status_code = 200
    lookup_mocked.return_value = mock_data

    lookup_belongs_result = list(
        lib.lookup_belongs(MOCK_TOKEN, MOCK_HOST, 'items', 'test_entity'))

    assert [mock_data] * 3 == lookup_belongs_result

    assert [
        mock.call('https://pytest.groclient.url/v2/items/belongs-to',
                  headers={'authorization': 'Bearer pytest.groclient.token'},
                  params={'ids': 'test_entity'},
                  timeout=None)
    ] == mock_requests_get.call_args_list

    assert [
        mock.call('pytest.groclient.token', 'pytest.groclient.url', 'items',
                  1),
        mock.call('pytest.groclient.token', 'pytest.groclient.url', 'items',
                  2),
        mock.call('pytest.groclient.token', 'pytest.groclient.url', 'items', 3)
    ] == lookup_mocked.mock_calls
예제 #2
0
def test_lookup_belongs(mock_requests_get, lookup_mocked):
    mock_requests_get.return_value.json.return_value = {'data': {'1': [3]}}
    mock_requests_get.return_value.status_code = 200
    lookup_mocked.side_effect = lookup_mock

    lookup_belongs_result = list(lib.lookup_belongs(MOCK_TOKEN, MOCK_HOST, 'regions', 1))

    assert lookup_belongs_result == [LOOKUP_MAP['regions']['3']]
예제 #3
0
    def lookup_belongs(self, entity_type, entity_id):
        """Look up details of entities containing the given entity.

        Parameters
        ----------
        entity_type : { 'metrics', 'items', 'regions' }
        entity_id : int

        Yields
        ------
        dict
            Result of :meth:`~.lookup` on each entity the given entity belongs to.

            For example: For the region 'United States', one yielded result will be for
            'North America.' The format of which matches the output of :meth:`~.lookup`::

                { 'id': 15,
                  'contains': [ 1008, 1009, 1012, 1215, ... ],
                  'name': 'North America',
                  'level': 2 }

        """
        return lib.lookup_belongs(self.access_token, self.api_host,
                                  entity_type, entity_id)
예제 #4
0
 def lookup_belongs(self, entity_type, entity_id):
     return lib.lookup_belongs(self.access_token, self.api_host,
                               entity_type, entity_id)