Ejemplo n.º 1
0
 def test_filesize_accessor_with_obj_lookup(self):
     self.login(self.regular_user)
     obj = OGSolrContentListingObject(
         OGSolrDocument({"UID": "9398dad21bcd49f8a197cd50d10ea778"}))
     obj.getObject = Mock()
     obj.getObject.return_value = self.document
     self.assertEqual(filesize(obj), self.document.file.size)
     self.assertTrue(obj.getObject.called)
Ejemplo n.º 2
0
    def solr_results(self, query):
        term = query['SearchableText'].rstrip('*').decode('utf8')
        pattern = (
            u'(Title:{term}* OR SearchableText:{term}* OR metadata:{term}* OR '
            u'Title:{term} OR SearchableText:{term} OR metadata:{term})')

        term_queries = [pattern.format(term=escape(t)) for t in term.split()]
        solr_query = u' AND '.join(term_queries)

        filters = [u'trashed:false']
        for key, value in query.items():
            if key == 'SearchableText':
                continue
            elif key == 'sort_on' or key == 'sort_order':
                continue
            elif key == 'path':
                filters.append(u'path_parent:{}'.format(
                    escape(value.get('query'))))
            elif isinstance(value, (list, tuple)):
                filters.append(u'{}:({})'.format(key,
                                                 escape(' OR '.join(value))))
            elif isinstance(value, bool):
                filters.append(u'{}:{}'.format(key,
                                               'true' if value else 'false'))
            else:
                filters.append(u'{}:{}'.format(key, escape(value)))

        sort = query.get('sort_on', None)
        if sort:
            sort_order = query.get('sort_order', 'ascending')
            if sort_order in ['descending', 'reverse']:
                sort += ' desc'
            else:
                sort += ' asc'

        # Todo: modified be removed once the changed metadata is filled on
        # all deployments.
        # https://github.com/4teamwork/opengever.core/issues/4988
        fl = [
            'UID', 'getIcon', 'portal_type', 'path', 'id',
            'bumblebee_checksum', 'modified'
        ]
        fl = fl + [c['column'] for c in self.config.columns if c['column']]
        params = {
            'fl': fl,
            'q.op': 'AND',
        }

        solr = getUtility(ISolrSearch)
        resp = solr.search(query=solr_query,
                           filters=filters,
                           start=0,
                           rows=50,
                           sort=sort,
                           **params)

        return [OGSolrDocument(doc) for doc in resp.docs]
Ejemplo n.º 3
0
 def test_filename_accessor_avoids_obj_lookup(self):
     obj = OGSolrContentListingObject(
         OGSolrDocument({
             "UID": "9398dad21bcd49f8a197cd50d10ea778",
             "filename": "Foo.pdf"
         }))
     obj.getObject = Mock()
     self.assertEqual(filename(obj), "Foo.pdf")
     self.assertFalse(obj.getObject.called)
Ejemplo n.º 4
0
 def test_croppeddescription_without_snippets(self):
     doc = OGSolrDocument(data={'Description': 'My Description'})
     obj = OGSolrContentListingObject(doc)
     self.assertEqual(obj.CroppedDescription(), 'My Description')
Ejemplo n.º 5
0
 def test_croppeddescription_returns_snippets(self):
     doc = OGSolrDocument(data={'_snippets_': 'snippets'})
     obj = OGSolrContentListingObject(doc)
     self.assertEqual(obj.CroppedDescription(), 'snippets')
Ejemplo n.º 6
0
 def test_with_containing_dossier(self):
     doc = OGSolrDocument(data={'containing_dossier': 'My Dossier'})
     self.assertEqual(doc.containing_dossier, 'My Dossier')
Ejemplo n.º 7
0
 def test_without_containing_dossier(self):
     doc = OGSolrDocument(data={})
     self.assertEqual(doc.containing_dossier, None)
Ejemplo n.º 8
0
 def test_with_bumblebee_checksum(self):
     doc = OGSolrDocument(data={'bumblebee_checksum': '123abc'})
     self.assertEqual(doc.bumblebee_checksum, '123abc')
Ejemplo n.º 9
0
 def test_without_bumblebee_checksum(self):
     doc = OGSolrDocument(data={})
     self.assertEqual(doc.bumblebee_checksum, None)
Ejemplo n.º 10
0
 def test_filename_accessor_with_obj_lookup(self):
     self.login(self.regular_user)
     obj = OGSolrContentListingObject(
         OGSolrDocument({"UID": "9398dad21bcd49f8a197cd50d10ea778"}))
     obj.filename = u'Vertraegsentwurf.docx'
     self.assertEqual(filename(obj), self.document.file.filename)