Ejemplo n.º 1
0
    def testOneResult(self):
        observer = CallTrace(
            returnValues={
                'getRecord': '<item><title>Test Title</title><link>Test Identifier</link><description>Test Description</description></item>',
            },
            ignoredAttributes=['unknown', 'extraResponseData', 'echoedExtraRequestData'])

        def executeQuery(**kwargs):
            raise StopIteration(Response(total=1, hits=[Hit(1)]))
            yield
        observer.methods['executeQuery'] = executeQuery

        rss = Rss(
            title = 'Test title',
            description = 'Test description',
            link = 'http://www.example.org',
            sortKeys = 'date,,1',
            maximumRecords = '15',
        )
        rss.addObserver(observer)

        result = asString(rss.handleRequest(RequestURI='/?query=aQuery'))
        self.assertEqualsWS(RSS % """<item>
        <title>Test Title</title>
        <link>Test Identifier</link>
        <description>Test Description</description>
        </item>""", result)
Ejemplo n.º 2
0
    def assertMaxAndSort(self, maximumRecords, sortKey, sortDirection, rssArgs, sruArgs):
        rss = Rss(
            title = 'Test title',
            description = 'Test description',
            link = 'http://www.example.org',
            **rssArgs
        )
        recordIds = []
        def getRecord(identifier):
            recordIds.append(identifier)
            return '<item/>'

        def executeQuery(start, stop, *args, **kwargs):
            response = Response(total=50, hits=[Hit(i) for i in range(start, stop)])
            raise StopIteration(response)
            yield
        observer = CallTrace(
            methods={
                'executeQuery': executeQuery,
                'getRecord': getRecord,
            },
            ignoredAttributes=['extraResponseData', 'echoedExtraRequestData'])
        rss.addObserver(observer)

        consume(rss.handleRequest(RequestURI='/?query=aQuery&' + urlencode(sruArgs)))

        method = observer.calledMethods[0]
        self.assertEquals('executeQuery', method.name)
        if sortKey is not None:
            self.assertEquals([{'sortBy': sortKey, 'sortDescending': sortDirection}], method.kwargs['sortKeys'])
        else:
            self.assertEquals(None, method.kwargs['sortKeys'])
        self.assertEquals(maximumRecords, len(recordIds))
Ejemplo n.º 3
0
    def testContentType(self):
        observer = CallTrace(
            returnValues={'executeQuery': (0, [])},
            ignoredAttributes=['extraResponseData', 'echoedExtraRequestData'])
        rss = Rss(title = 'Title', description = 'Description', link = 'Link')
        rss.addObserver(observer)

        result = "".join(rss.handleRequest())
        self.assertTrue('Content-Type: application/rss+xml' in result, result)
Ejemplo n.º 4
0
    def testWebQueryIgnoresWrongFilters(self):
        observer = CallTrace(
            ignoredAttributes=['unknown', 'extraResponseData', 'echoedExtraRequestData'])
        observer.exceptions['executeQuery'] = StopIteration([0, []])
        rss = Rss(title = 'Title', description = 'Description', link = 'Link')
        rss.addObserver(observer)

        result = "".join(rss.handleRequest(RequestURI='/?query=one+two&filter=invalid&filter='))

        self.assertTrue("<description>An error occurred 'Invalid filter: invalid'</description>" in result, result)
Ejemplo n.º 5
0
    def testErrorNoQuery(self):
        rss = Rss(
            title = 'Test title',
            description = 'Test description',
            link = 'http://www.example.org',
        )
        result = asString(rss.handleRequest(RequestURI='/'))

        xml = parse(StringIO(result[result.index("<?xml"):]))
        self.assertEquals(['ERROR Test title'], xml.xpath('/rss/channel/title/text()'))
        self.assertEquals(["An error occurred 'MANDATORY parameter 'query' not supplied or empty'"], xml.xpath('/rss/channel/description/text()'))
Ejemplo n.º 6
0
    def testWebQueryUsage(self):
        observer = CallTrace(
            ignoredAttributes=['unknown', 'extraResponseData', 'echoedExtraRequestData'])
        def executeQuery(**kwargs):
            raise StopIteration(Response(total=0, hits=[]))
            yield
        observer.methods['executeQuery'] = executeQuery
        rss = Rss(title = 'Title', description = 'Description', link = 'Link')
        rss.addObserver(observer)

        consume(rss.handleRequest(RequestURI='/?query=one+two'))
        self.assertEquals(['executeQuery'], [m.name for m in observer.calledMethods])
        self.assertEquals(None, observer.calledMethods[0].kwargs['sortKeys'])
        self.assertEquals(0, observer.calledMethods[0].kwargs['start'])
        self.assertEquals(10, observer.calledMethods[0].kwargs['stop'])
Ejemplo n.º 7
0
    def testWebQueryUsesFilters(self):
        observer = CallTrace(
            ignoredAttributes=['unknown', 'extraResponseData', 'echoedExtraRequestData'])
        def executeQuery(**kwargs):
            return Response(total=0, hits=[])
            yield
        observer.methods['executeQuery'] = executeQuery
        rss = Rss(title = 'Title', description = 'Description', link = 'Link')
        rss.addObserver(observer)

        consume(rss.handleRequest(RequestURI='/?query=one+two&filter=field1:value1&filter=field2:value2'))
        self.assertEqual(['executeQuery'], [m.name for m in observer.calledMethods])
        self.assertEqual(None, observer.calledMethods[0].kwargs['sortKeys'])
        self.assertEqual(0, observer.calledMethods[0].kwargs['start'])
        self.assertEqual(10, observer.calledMethods[0].kwargs['stop'])
        self.assertEqual(cqlToExpression("(one AND two) AND field1 exact value1 AND field2 exact value2"), observer.calledMethods[0].kwargs['query'])
Ejemplo n.º 8
0
    def testEmptyQueryWithAntiUnaryClauseIsPassedToWebQuery(self):
        observer = CallTrace(
            ignoredAttributes=['unknown', 'extraResponseData', 'echoedExtraRequestData'])
        def executeQuery(**kwargs):
            raise StopIteration(Response(total=0, hits=[]))
            yield
        observer.methods['executeQuery'] = executeQuery
        rss = Rss(title='Title', description='Description', link='Link', antiUnaryClause='antiunary')
        rss.addObserver(observer)

        consume(rss.handleRequest(RequestURI='/?query='))

        self.assertEquals(['executeQuery'], [m.name for m in observer.calledMethods])
        self.assertEquals(None, observer.calledMethods[0].kwargs['sortKeys'])
        self.assertEquals(0, observer.calledMethods[0].kwargs['start'])
        self.assertEquals(10, observer.calledMethods[0].kwargs['stop'])
        self.assertEquals(cqlToExpression("antiunary"), observer.calledMethods[0].kwargs['query'])
Ejemplo n.º 9
0
    def testError(self):
        observer = CallTrace(
            ignoredAttributes=['unknown', 'extraResponseData', 'echoedExtraRequestData'])
        def executeQuery(**kwargs):
            raise StopIteration(Response(total=0, hits=[]))
            yield
        observer.methods['executeQuery'] = executeQuery
        rss = Rss(
            title = 'Test title',
            description = 'Test description',
            link = 'http://www.example.org',
        )
        rss.addObserver(observer)
        result = asString(rss.handleRequest(RequestURI='/?query=aQuery%29')) #%29 == ')'

        xml = parse(StringIO(result[result.index("<?xml"):]))
        self.assertEquals(['Test title'], xml.xpath('/rss/channel/title/text()'))
        self.assertEquals(['Test description'], xml.xpath('/rss/channel/description/text()'))
Ejemplo n.º 10
0
    def testNoResults(self):
        observer = CallTrace(
            ignoredAttributes=['unknown', 'extraResponseData', 'echoedExtraRequestData'])
        def executeQuery(**kwargs):
            raise StopIteration(Response(total=0, hits=[]))
            yield
        observer.methods['executeQuery'] = executeQuery

        rss = Rss(
            title = 'Test title',
            description = 'Test description',
            link = 'http://www.example.org',
            sortKeys = 'date,,1',
            maximumRecords = '15',
        )
        rss.addObserver(observer)

        result = asString(rss.handleRequest(RequestURI='/?query=aQuery'))
        self.assertEqualsWS(RSS % '', result)