Beispiel #1
0
 def test_search_with_sort_by_references(self, registry, pool, inst, query):
     """Use the first reference (not back reference) to sort."""
     from hypatia.util import ResultSet
     from adhocracy_core.interfaces import Reference
     from adhocracy_core.interfaces import ISheet
     child = self._make_resource(registry, parent=pool)
     child2 = self._make_resource(registry, parent=pool)
     search_result = ResultSet((child.__oid__, child2.__oid__), 2, None)
     inst._search_elements = Mock(return_value=search_result)
     references_result = ResultSet((child2.__oid__, child.__oid__), 2, None)
     reference_index = inst['adhocracy']['reference']
     reference_index.search_with_order = Mock(
         return_value=references_result)
     reference = Reference(child, ISheet, 'field', None)
     back_reference = Reference(None, ISheet, 'field', child2)
     result = inst.search(
         query._replace(interfaces=IPool,
                        references=(back_reference, reference),
                        sort_by='reference'))
     reference_index.search_with_order.assert_called_once_with(reference)
     assert list(result.elements) == [child2, child]
Beispiel #2
0
 def test_search_with_sort_by_references_and_limit(self, registry, pool,
                                                   inst, query):
     from adhocracy_core.interfaces import Reference
     from adhocracy_core.interfaces import ISheet
     child = self._make_resource(registry, parent=pool)
     reference = Reference(child, ISheet, 'field', None)
     with raises(NotImplementedError):
         inst.search(
             query._replace(interfaces=IPool,
                            references=(reference, ),
                            sort_by='reference',
                            limit=10))
Beispiel #3
0
 def test_search_with_references(self, registry, pool, inst, query):
     from adhocracy_core.interfaces import ITag
     from adhocracy_core.interfaces import Reference
     from adhocracy_core import sheets
     from adhocracy_core.utils import get_sheet
     referenced = pool
     referencing = self._make_resource(registry, parent=pool, iresource=ITag)
     sheet = get_sheet(referencing, sheets.tags.ITag)
     sheet.set({'elements': [referenced]})
     reference = Reference(None, sheets.tags.ITag, 'elements', referenced)
     result = inst.search(query._replace(references=[reference]))
     assert list(result.elements) == [referencing]
Beispiel #4
0
 def test_search_with_references(self, registry, pool, inst, query):
     from adhocracy_core.interfaces import IItem
     from adhocracy_core.interfaces import Reference
     from adhocracy_core import sheets
     referenced = pool
     referencing = self._make_resource(registry,
                                       parent=pool,
                                       iresource=IItem)
     sheet = registry.content.get_sheet(referencing, sheets.tags.ITags)
     sheet.set({'FIRST': referenced})
     reference = Reference(None, sheets.tags.ITags, 'FIRST', referenced)
     result = inst.search(query._replace(references=[reference]))
     assert list(result.elements) == [referencing]
Beispiel #5
0
 def test_search_with_two_references(self, registry, pool, service, inst,
                                     query):
     from copy import deepcopy
     from adhocracy_core.interfaces import Reference
     from adhocracy_core.resources.principal import IUser
     from adhocracy_core import sheets
     pool['principals'] = service
     pool['principals']['groups'] = deepcopy(service)
     user = self._make_resource(registry, parent=pool, iresource=IUser)
     referencing = self._make_resource(registry, parent=pool)
     sheet = registry.content.get_sheet(referencing,
                                        sheets.metadata.IMetadata)
     sheet.set({'creator': [user]})
     reference = Reference(None, sheets.metadata.IMetadata, 'creator', user)
     result = inst.search(query._replace(references=[reference, reference]))
     elements = list(result.elements)
     assert elements == [user]
Beispiel #6
0
 def test_search_with_back_references(self, registry, pool, inst, query):
     from adhocracy_core.interfaces import IItem
     from adhocracy_core.interfaces import Reference
     from adhocracy_core import sheets
     referenced1 = self._make_resource(registry, parent=pool)
     referenced2 = self._make_resource(registry, parent=pool)
     referenced3 = self._make_resource(registry, parent=pool)
     referencing = self._make_resource(registry,
                                       parent=pool,
                                       iresource=IItem)
     sheet = registry.content.get_sheet(referencing, sheets.tags.ITags)
     sheet.set({'LAST': [referenced3, referenced1, referenced2]})
     reference = Reference(referencing, sheets.tags.ITags, 'LAST', None)
     result = inst.search(query._replace(references=[reference]))
     elements = list(result.elements)
     assert len(elements) == 3  # search for back references is not ordered
     assert referenced1 in elements
     assert referenced2 in elements
     assert referenced3 in elements
Beispiel #7
0
 def test_search_with_back_reference_traverse(self, registry, pool, service,
                                              inst, query):
     from adhocracy_core.interfaces import Reference
     from adhocracy_core.interfaces import ReferenceComparator
     from adhocracy_core.resources.comment import IComment
     from adhocracy_core.resources.comment import ICommentVersion
     from adhocracy_core.resources.comment import ICommentsService
     from adhocracy_core import sheets
     registry.content.create(ICommentsService.__identifier__, parent=pool)
     comments = pool['comments']
     comment = self._make_resource(registry,
                                   parent=comments,
                                   iresource=IComment)
     referencing = self._make_resource(registry,
                                       parent=comment,
                                       iresource=ICommentVersion)
     referenced1 = self._make_resource(registry,
                                       parent=comment,
                                       iresource=ICommentVersion)
     referenced2 = self._make_resource(registry,
                                       parent=comment,
                                       iresource=ICommentVersion)
     sheet = registry.content.get_sheet(referencing,
                                        sheets.comment.IComment)
     sheet.set({'refers_to': referenced1})
     sheet = registry.content.get_sheet(referenced1,
                                        sheets.comment.IComment)
     sheet.set({'refers_to': referenced2})
     reference = Reference(referencing, sheets.comment.IComment,
                           'refers_to', None)
     result = inst.search(
         query._replace(references=[(ReferenceComparator.traverse.value,
                                     reference)]))
     elements = list(result.elements)
     assert len(elements) == 2  # search with traversal is not ordered
     assert referenced1 in elements
     assert referenced2 in elements