Exemplo n.º 1
0
 def testQueryExpression(self):
     conversion = Conversion()
     kwargs = {'q': QueryExpression.searchterm(term='term')}
     dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
     loadedMessage, loadedKwargs = conversion.jsonLoadMessage(dump)
     self.assertEquals('aMessage', loadedMessage)
     self.assertEquals({'q': QueryExpression.searchterm(term='term')}, loadedKwargs)
Exemplo n.º 2
0
    def testSpecialObject(self):
        class MyObject():
            def asDict(self):
                return {"this":"dict"}
            @classmethod
            def fromDict(cls, aDict):
                self.assertEquals({"this": "dict"}, aDict)
                return cls()

        conversion = Conversion()
        conversion._addObject('__MyObject__', MyObject, MyObject.asDict, MyObject.fromDict)
        kwargs = {'q': "query", 'object': MyObject()}
        dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
        self.assertEquals({
                'kwargs': {
                    'object': {
                        '__MyObject__': '{"this": "dict"}'
                    },
                    'q': 'query'
                },
                'message':'aMessage'
            }, loads(dump))
        loadedMessage, loadedKwargs = conversion.jsonLoadMessage(dump)
        self.assertEqual('aMessage', loadedMessage)
        self.assertEqual('query', loadedKwargs['q'])
        self.assertTrue(isinstance(loadedKwargs['object'], MyObject))
Exemplo n.º 3
0
 def testQueryExpression(self):
     conversion = Conversion()
     kwargs = {'q': QueryExpression.searchterm(term='term')}
     dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
     loadedMessage, loadedKwargs = conversion.jsonLoadMessage(dump)
     self.assertEquals('aMessage', loadedMessage)
     self.assertEquals({'q': QueryExpression.searchterm(term='term')},
                       loadedKwargs)
Exemplo n.º 4
0
 def testConversion(self):
     kwargs = {'q': parseString('CQL'), 'attr': {'qs': [parseString('qs')]}}
     dump = Conversion().jsonDumpMessage(message='aMessage', **kwargs)
     self.assertEquals(str, type(dump))
     message, kwargs = Conversion().jsonLoadMessage(dump)
     self.assertEquals('aMessage', message)
     self.assertEquals(parseString('CQL'), kwargs['q'])
     self.assertEquals([parseString('qs')], kwargs['attr']['qs'])
Exemplo n.º 5
0
 def testQueryExpressionWithOperands(self):
     conversion = Conversion()
     qe = QueryExpression.nested(operator='AND')
     qe.operands = [QueryExpression.searchterm(term='term'), QueryExpression.searchterm(term='term1')]
     kwargs = {'q': qe}
     dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
     loadedMessage, loadedKwargs = conversion.jsonLoadMessage(dump)
     self.assertEquals('aMessage', loadedMessage)
     self.assertEquals({'q': qe}, loadedKwargs)
Exemplo n.º 6
0
 def testQueryExpressionWithOperands(self):
     conversion = Conversion()
     qe = QueryExpression.nested(operator='AND')
     qe.operands = [
         QueryExpression.searchterm(term='term'),
         QueryExpression.searchterm(term='term1')
     ]
     kwargs = {'q': qe}
     dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
     loadedMessage, loadedKwargs = conversion.jsonLoadMessage(dump)
     self.assertEquals('aMessage', loadedMessage)
     self.assertEquals({'q': qe}, loadedKwargs)
Exemplo n.º 7
0
    def testConversionOfComposedQuery(self):
        conversion = Conversion()
        cq = ComposedQuery('coreA')
        cq.setCoreQuery(core='coreA', query=parseString('Q0'), filterQueries=['Q1', 'Q2'], facets=['F0', 'F1'])
        cq.setCoreQuery(core='coreB', query=QueryExpression.searchterm(term='Q3'), filterQueries=['Q4'])
        cq.addMatch(dict(core='coreA', uniqueKey='keyA'), dict(core='coreB', key='keyB'))
        cq.addUnite(dict(core='coreA', query='AQuery'), dict(core='coreB', query='anotherQuery'))
        cq.start = 0
        cq.sortKeys = [dict(sortBy='field', sortDescending=True)]

        kwargs = {'q': cq}
        dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
        self.assertEquals(str, type(dump))
        message, kwargs = conversion.jsonLoadMessage(dump)
        self.assertEquals('aMessage', message)
        cq2 = kwargs['q']
        self.assertEquals(parseString('Q0'), cq2.queryFor('coreA'))
Exemplo n.º 8
0
    def testSpecialObject(self):
        class MyObject():
            def asDict(self):
                return {"this": "dict"}

            @classmethod
            def fromDict(cls, aDict):
                self.assertEquals({"this": "dict"}, aDict)
                return cls()

        conversion = Conversion()
        conversion._addObject('__MyObject__', MyObject, MyObject.asDict,
                              MyObject.fromDict)
        kwargs = {'q': "query", 'object': MyObject()}
        dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
        self.assertEquals(
            {
                'kwargs': {
                    'object': {
                        '__MyObject__': '{"this": "dict"}'
                    },
                    'q': 'query'
                },
                'message': 'aMessage'
            }, loads(dump))
        loadedMessage, loadedKwargs = conversion.jsonLoadMessage(dump)
        self.assertEqual('aMessage', loadedMessage)
        self.assertEqual('query', loadedKwargs['q'])
        self.assertTrue(isinstance(loadedKwargs['object'], MyObject))
Exemplo n.º 9
0
    def testConversionOfComposedQuery(self):
        conversion = Conversion()
        cq = ComposedQuery('coreA')
        cq.setCoreQuery(core='coreA',
                        query=parseString('Q0'),
                        filterQueries=['Q1', 'Q2'],
                        facets=['F0', 'F1'])
        cq.setCoreQuery(core='coreB',
                        query=QueryExpression.searchterm(term='Q3'),
                        filterQueries=['Q4'])
        cq.addMatch(dict(core='coreA', uniqueKey='keyA'),
                    dict(core='coreB', key='keyB'))
        cq.addUnite(dict(core='coreA', query='AQuery'),
                    dict(core='coreB', query='anotherQuery'))
        cq.start = 0
        cq.sortKeys = [dict(sortBy='field', sortDescending=True)]

        kwargs = {'q': cq}
        dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
        self.assertEquals(str, type(dump))
        message, kwargs = conversion.jsonLoadMessage(dump)
        self.assertEquals('aMessage', message)
        cq2 = kwargs['q']
        self.assertEquals(parseString('Q0'), cq2.queryFor('coreA'))