示例#1
0
    def test_expected(self):
        """
        Ensure that required, requested, and standard fields remain while extras are removed.
        """
        m_model = mock.MagicMock()
        m_model._fields = {'required': mock.MagicMock(required=True)}
        results = [{'extra': 'f', 'required': 'f', 'requested': 'f', '_id': 'always'}]

        search._trim_results(m_model, results, ['requested'])

        self.assertEqual(len(results), 1)
        self.assertDictEqual(results[0], {'required': 'f', 'requested': 'f', '_id': 'always'})
示例#2
0
    def get_results(cls, query, search_method, options, *args, **kwargs):
        """
        This overrides the base class's implementation so we can optionally include extra data.


        :param query: The criteria that should be used to search for objects
        :type  query: dict
        :param search_method: function that should be used to search
        :type  search_method: func
        :param options: additional options for including extra data
        :type  options: dict

        :return: processed results of the query
        :rtype:  list
        """
        only = query.get('fields', [])
        results = list(search_method(query))
        results = _process_repos(results, options.get('details', False),
                                 options.get('importers', False),
                                 options.get('distributors', False))
        if only:
            only.extend(['importers', 'distributors'])
            search._trim_results(cls.model, results, only)
        return results
示例#3
0
    def get_results(cls, query, search_method, options, *args, **kwargs):
        """
        This overrides the base class's implementation so we can optionally include extra data.


        :param query: The criteria that should be used to search for objects
        :type  query: dict
        :param search_method: function that should be used to search
        :type  search_method: func
        :param options: additional options for including extra data
        :type  options: dict

        :return: processed results of the query
        :rtype:  list
        """
        only = query.get('fields', [])
        results = list(search_method(query))
        results = _process_repos(results, options.get('details', False),
                                 options.get('importers', False),
                                 options.get('distributors', False))
        if only:
            only.extend(['importers', 'distributors'])
            search._trim_results(cls.model, results, only)
        return results