Beispiel #1
0
    def search_and_lookup(self, entity_type, search_terms, num_results=10):
        """Search for the given search terms and look up their details.

        For each result, yield a dict of the entity and it's properties.

        Parameters
        ----------
        entity_type : { 'metrics', 'items', 'regions', 'sources' }
        search_terms : string
        num_results: int
            Maximum number of results to return. Defaults to 10.

        Yields
        ------
        dict
            Result from :meth:`~.search` passed to :meth:`~.lookup` to get additional details.
            
            Example::

                { 'id': 274,
                  'contains': [779, 780, ...],
                  'name': 'Corn',
                  'definition': 'The seeds of the widely cultivated...' }

            See output of :meth:`~.lookup`. Note that as with :meth:`~.search`, the first result is
            the best match for the given search term(s).

        """
        return lib.search_and_lookup(self.access_token, self.api_host,
                                     entity_type, search_terms, num_results)
Beispiel #2
0
def test_search_and_lookup(search_mocked, lookup_mocked):
    # Set up
    # mock return values
    search_mocked.return_value = [{'id': 1}, {'id': 2}]
    lookup_mocked.side_effect = lookup_mock
    search_and_lookup_result = list(lib.search_and_lookup(MOCK_TOKEN, MOCK_HOST,
                                                          'regions', 'test123'))

    assert search_and_lookup_result == [
        LOOKUP_MAP['regions']['1'],
        LOOKUP_MAP['regions']['2']
    ]
Beispiel #3
0
def test_search_and_lookup(search_mocked, lookup_mocked):
    # Set up
    # mock return values
    search_mocked.return_value = [{'id': 'test1'}, {'id': 'test2'}]
    mock_data = ['obj1', 'obj2']
    lookup_mocked.return_value = mock_data
    search_and_lookup_result = list(
        lib.search_and_lookup(MOCK_TOKEN, MOCK_HOST, 'items', 'test123'))

    assert search_and_lookup_result == [mock_data] * 2

    assert [
        mock.call('pytest.groclient.token', 'pytest.groclient.url', 'items',
                  'test123')
    ] == search_mocked.mock_calls
    assert [
        mock.call('pytest.groclient.token', 'pytest.groclient.url', 'items',
                  'test1'),
        mock.call('pytest.groclient.token', 'pytest.groclient.url', 'items',
                  'test2')
    ] == lookup_mocked.mock_calls
Beispiel #4
0
def test_search_and_lookup(search_mocked, lookup_mocked):
    # Set up
    # mock return values
    search_mocked.return_value = [{"id": "test1"}, {"id": "test2"}]
    mock_data = ["obj1", "obj2"]
    lookup_mocked.return_value = mock_data
    search_and_lookup_result = list(
        lib.search_and_lookup(MOCK_TOKEN, MOCK_HOST, "items", "test123"))

    assert search_and_lookup_result == [mock_data] * 2

    assert [
        mock.call('pytest.groclient.token', 'pytest.groclient.url', 'items',
                  'test123')
    ] == search_mocked.mock_calls
    assert [
        mock.call('pytest.groclient.token', 'pytest.groclient.url', 'items',
                  'test1'),
        mock.call('pytest.groclient.token', 'pytest.groclient.url', 'items',
                  'test2')
    ] == lookup_mocked.mock_calls
Beispiel #5
0
 def search_and_lookup(self, entity_type, search_terms):
     return lib.search_and_lookup(self.access_token, self.api_host,
                                  entity_type, search_terms)