def test_search(self, mock_search): mock_hit = Hit({}) mock_hit.system = 'test.system' mock_hit.path = '/path/to/file' mock_result = MagicMock() mock_result.__iter__.return_value = [mock_hit] mock_result.hits.total.value = 1 mock_search().query().filter().extra().execute\ .return_value = mock_result search_res = search(None, 'test.system', '/path', query_string='query') mock_search().query.assert_called_with( Q("query_string", query='query', fields=["name"], minimum_should_match='100%', default_operator='or') | Q("query_string", query='query', fields=["name._exact, name._pattern"], default_operator='and')) mock_search().query().filter.assert_called_with( 'term', **{'system._exact': 'test.system'}) mock_search().query().filter().extra.assert_called_with(from_=int(0), size=int(100)) self.assertEqual( search_res, { 'listing': [{ 'system': 'test.system', 'path': '/path/to/file' }], 'reachedEnd': True, 'count': 1 })
def execute(self): out = [] for position in range( self._s.to_dict()["from"], self._s.to_dict()["from"] + self._s.to_dict()["size"]): result = template.copy() result["highlight"] = { "name": ["<mark>" + str(position) + "</mark>"] } result["fields"]["name"] = str(position) result["fields"]["name_escaped"] = str(position) result["fields"]["id"] = position out.append(Hit(result)) hits = AttrList(out) hits.__setattr__("total", len(out) * 2) return AttrDict({"hits": hits, "facets": get_aggregations()})
def execute(self): out = [] for position in range( self._s.to_dict()["from"], self._s.to_dict()["from"] + self._s.to_dict()["size"], ): result = template.copy() result["highlight"] = {"name": ["<mark>" + str(position) + "</mark>"]} result["fields"] = { "id": position, "name": str(position), "name_escaped": str(position), "type": "file", "type_translated": "File", "created": "2017-11-24T09:06:05.159381+00:00", "modified": "2017-12-01T10:56:37.297771+00:00", } out.append(Hit(result)) hits = AttrList(out) hits.__setattr__("total", len(out) * 2) return AttrDict({"hits": hits, "facets": get_aggregations()})
def execute(self): hits = AttrList([Hit(template)]) hits.__setattr__("total", 1) return AttrDict({"hits": hits, "facets": get_aggregations()})
def execute(self): hits = AttrList([Hit(template.copy())]) hits.__setattr__("total", {"value": 1, "relation": "eq"}) return AttrDict({"hits": hits, "facets": get_aggregations()})
def _hit_to_doc(hit: Hit) -> JSON: return self.translate_fields(catalog, hit.to_dict(), forward=False)
def _hit_to_doc(self, hit: Hit) -> JSON: return self.service.translate_fields(self.catalog, hit.to_dict(), forward=False)