Пример #1
0
 def test_group_terms(self):
     """:meth:`._group_terms` groups terms using logical precedence."""
     query = AdvancedQuery(terms=FieldedSearchList([
         FieldedSearchTerm(operator=None, field='title', term='muon'),
         FieldedSearchTerm(operator='OR', field='title', term='gluon'),
         FieldedSearchTerm(operator='NOT', field='title', term='foo'),
         FieldedSearchTerm(operator='AND', field='title', term='boson'),
     ]))
     expected = (
         FieldedSearchTerm(operator=None, field='title', term='muon'),
         'OR',
         (
           (
             FieldedSearchTerm(operator='OR', field='title', term='gluon'),
             'NOT',
             FieldedSearchTerm(operator='NOT', field='title', term='foo')
           ),
           'AND',
           FieldedSearchTerm(operator='AND', field='title', term='boson')
         )
     )
     try:
         terms = advanced._group_terms(query)
     except AssertionError:
         self.fail('Should result in a single group')
     self.assertEqual(expected, terms)
Пример #2
0
 def test_group_terms(self):
     """:meth:`._group_terms` groups terms using logical precedence."""
     query = AdvancedQuery(terms=FieldedSearchList([
         FieldedSearchTerm(operator=None, field="title", term="muon"),
         FieldedSearchTerm(operator="OR", field="title", term="gluon"),
         FieldedSearchTerm(operator="NOT", field="title", term="foo"),
         FieldedSearchTerm(operator="AND", field="title", term="boson"),
     ]))
     expected = (
         FieldedSearchTerm(operator=None, field="title", term="muon"),
         "OR",
         (
             (
                 FieldedSearchTerm(operator="OR",
                                   field="title",
                                   term="gluon"),
                 "NOT",
                 FieldedSearchTerm(operator="NOT",
                                   field="title",
                                   term="foo"),
             ),
             "AND",
             FieldedSearchTerm(operator="AND", field="title", term="boson"),
         ),
     )
     try:
         terms = advanced._group_terms(query)
     except AssertionError:
         self.fail("Should result in a single group")
     self.assertEqual(expected, terms)