Exemplo n.º 1
0
 def testSuspendBeforeSelect(self):
     self.assertEqual([],
                      asList(SuspendRegister().suspendBeforeSelect(
                          continueAfter='9876', some='argument')))
     self.assertEqual(
         [],
         asList(
             SuspendRegister(batchMode=True).suspendBeforeSelect(
                 continueAfter='9876', some='argument')))
Exemplo n.º 2
0
 def testServiceConfig(self):
     c = ServiceConfig(type='api', minVersion="4.2", untilVersion="5.0")
     consume(c.updateConfig(**CONFIG_SERVICES()))
     self.assertEquals(['api.front.example.org', 'alias1', 'alias2'], asList(c.servernames()))
     self.assertEquals('', asString(c.zones()))
     self.assertEquals('    location / {\n        proxy_pass http://__var_af9b2fd9f1c7f17413223dc3c26aeee4_api;\n    }', asString(c.locations()))
     self.assertEquals('    listen 0.0.0.0:80;\n', asString(c.listenLines()))
Exemplo n.º 3
0
    def testEachBatchWillHaveItsOwnTimestamp(self):
        reactor = CallTrace("reactor")
        register = SuspendRegister(batchMode=True)
        register.signalOaiUpdate(metadataPrefixes=['prefix'],
                                 sets=set(),
                                 otherKey='ignored',
                                 stamp=1000)
        register.startOaiBatch()

        suspend = next(
            compose(
                register.suspendBeforeSelect(clientIdentifier="id0",
                                             prefix='prefix',
                                             sets=[],
                                             continueAfter='1000')))
        suspend(reactor, lambda: None)

        register.signalOaiUpdate(metadataPrefixes=['prefix'],
                                 sets=set(),
                                 otherKey='ignored',
                                 stamp=2000)
        self.assertEqual(1, len(register))
        register.stopOaiBatch()
        self.assertEqual(0, len(register))
        register.startOaiBatch()
        self.assertEqual([],
                         asList(
                             register.suspendBeforeSelect(
                                 clientIdentifier="id0",
                                 prefix='prefix',
                                 sets=[],
                                 continueAfter='1000')))
        self.assertEqual(0, len(register))
Exemplo n.º 4
0
 def testInitialBatchSuspendBeforeResult(self):
     register = SuspendRegister(batchMode=True)
     register.startOaiBatch()
     self.assertEqual([],
                      asList(
                          register.suspendBeforeSelect(
                              clientIdentifier="a-client-id",
                              prefix='prefix',
                              sets=[],
                              continueAfter='0')))
     self.assertEqual([],
                      asList(
                          register.suspendBeforeSelect(
                              clientIdentifier="a-client-id",
                              prefix='prefix',
                              sets=[],
                              continueAfter='1000')))
Exemplo n.º 5
0
    def testPointCoordinates(self):
        g = Geometry.parseWkt("POINT(30 10)")
        self.assertEquals([(30, 10)], asList(g.pointCoordinates()))

        g = Geometry.parseWkt("POINT(30.12 10.07)")
        self.assertEquals([(30.12, 10.07)], asList(g.pointCoordinates()))

        g = Geometry.parseWkt("POINT(5.979788757821533 51.517618506703975)")
        self.assertEquals([(5.979788757821533, 51.517618506703975)], asList(g.pointCoordinates()))

        g = Point(Decimal("5.976364581846588"), Decimal("51.52243586973127"))
        self.assertEquals([(Decimal("5.976364581846588"), Decimal("51.52243586973127"))], asList(g.pointCoordinates()))

        g = MultiLineString([[10, 10], [20, 20], [10, 40]], [[40, 40], [30, 30], [40, 20], [30, 10]])
        self.assertEquals(
            [(10, 10), (20, 20), (10, 40), (40, 40), (30, 30), (40, 20), (30, 10)], asList(g.pointCoordinates())
        )

        g = MultiPolygon(
            [[[40, 40], [20, 45], [45, 30], [40, 40]]],
            [[[20, 35], [10, 30], [10, 10], [30, 5], [45, 20], [20, 35]], [[30, 20], [20, 15], [20, 25], [30, 20]]],
        )
        self.assertEquals(
            [
                (40, 40),
                (20, 45),
                (45, 30),
                (40, 40),
                (20, 35),
                (10, 30),
                (10, 10),
                (30, 5),
                (45, 20),
                (20, 35),
                (30, 20),
                (20, 15),
                (20, 25),
                (30, 20),
            ],
            asList(g.pointCoordinates()),
        )
 def _generate(self, **kwargs):
     yield self.all.updateConfig(**kwargs)
     yield '## Generated by meresco.distributed.failover.HttpToHttpsRedirect\n\n'
     yield 'server {\n'
     yield self.all.listenLines()
     yield '    server_name '
     servernames = ' '.join(asList(self.all.servernames()))
     if not servernames:
         raise ValueError('Cannot generate config without servername.')
     yield servernames
     yield ';\n\n'
     yield '    rewrite  ^ https://{servername}$request_uri? permanent;\n'.format(servername=servernames.split(' ')[0])
     yield '}\n'
Exemplo n.º 7
0
 def testShouldNotInterfereIfSortKeysIsOmitted(self):
     total, recordIds = asList(
         self.sortKeysRename.executeQuery(query='AbstractSyntaxTree',
                                          start=1,
                                          stop=2))[0]
     self.assertEqual(0, total)
     self.assertEqual([], recordIds)
     self.assertEqual(1, len(self.observer.calledMethods))
     self.assertEqual(
         {
             'query': 'AbstractSyntaxTree',
             'start': 1,
             'stop': 2,
             'sortKeys': None
         }, self.observer.calledMethods[0].kwargs)
Exemplo n.º 8
0
    def testEachBatchWillHaveItsOwnTimestamp(self):
        reactor = CallTrace("reactor")
        register = SuspendRegister(batchMode=True)
        register.signalOaiUpdate(metadataPrefixes=['prefix'], sets=set(), otherKey='ignored', stamp=1000)
        register.startOaiBatch()

        suspend = compose(register.suspendBeforeSelect(clientIdentifier="id0", prefix='prefix', sets=[], continueAfter='1000')).next()
        suspend(reactor, lambda: None)

        register.signalOaiUpdate(metadataPrefixes=['prefix'], sets=set(), otherKey='ignored', stamp=2000)
        self.assertEquals(1, len(register))
        register.stopOaiBatch()
        self.assertEquals(0, len(register))
        register.startOaiBatch()
        self.assertEquals([], asList(register.suspendBeforeSelect(clientIdentifier="id0", prefix='prefix', sets=[], continueAfter='1000')))
        self.assertEquals(0, len(register))
Exemplo n.º 9
0
    def testPassThroughOfCallables(self):
        def callableMethod():
            pass

        def handleRequest(*args, **kwargs):
            yield callableMethod
            yield "HTTP/1.0 200 OK\r\n\r\nBODY"
            yield callableMethod
            yield "THE END"

        self.observer.handleRequest = handleRequest
        result = asList(self.handler.handleRequest(Headers={}))
        self.assertEquals(callableMethod, result[0])
        self.assertEquals("HTTP/1.0 200 OK\r\n", result[1])
        self.assertEquals("\r\nBODY", result[3])
        self.assertEquals(callableMethod, result[4])
        self.assertTrue(result[2].startswith('Set-Cookie: session'), result[2])
        self.assertEquals("THE END", result[5])
    def testPassThroughOfCallables(self):
        def callableMethod():
            pass
        class MyObserver(Observable):
            def handleRequest(*args, **kwargs):
                yield callableMethod
                yield "HTTP/1.0 200 OK\r\n\r\nBODY"
                yield callableMethod
                yield "THE END"

        self.handler.addObserver(MyObserver())
        result = asList(self.handler.handleRequest(Headers={}))
        self.assertEquals(callableMethod, result[0])
        self.assertEquals("HTTP/1.0 200 OK\r\n", result[1])
        self.assertEquals("\r\nBODY", result[3])
        self.assertEquals(callableMethod, result[4])
        self.assertTrue(result[2].startswith('Set-Cookie: session'), result[2])
        self.assertEquals("THE END", result[5])
Exemplo n.º 11
0
    def testSuspendBeforeSelectWithContinueAfter(self):
        reactor = CallTrace("reactor")
        register = SuspendRegister(batchMode=True)
        register.signalOaiUpdate(metadataPrefixes=['prefix'],
                                 sets=set(),
                                 otherKey='ignored',
                                 stamp=1000)
        register.startOaiBatch()
        resumed = []

        suspend = next(
            compose(
                register.suspendBeforeSelect(clientIdentifier="id0",
                                             prefix='prefix',
                                             sets=[],
                                             continueAfter='1000')))
        suspend(reactor, lambda: resumed.append(True))
        suspend = next(
            compose(
                register.suspendBeforeSelect(clientIdentifier="id1",
                                             prefix='prefix',
                                             sets=[],
                                             continueAfter='1001')))
        suspend(reactor, lambda: resumed.append(True))
        self.assertEqual([],
                         asList(
                             register.suspendBeforeSelect(
                                 clientIdentifier="id2",
                                 prefix='prefix',
                                 sets=[],
                                 continueAfter='999')))

        self.assertEqual([], resumed)

        register.signalOaiUpdate(metadataPrefixes=['prefix'],
                                 sets=set(),
                                 otherKey='ignored',
                                 stamp=2000)
        self.assertEqual([], resumed)
        self.assertEqual(2, len(register))
        register.stopOaiBatch()
        self.assertEqual([True, True], resumed)
        self.assertEqual(0, len(register))
Exemplo n.º 12
0
    def testSuspendBeforeSelectWithContinueAfter(self):
        reactor = CallTrace("reactor")
        register = SuspendRegister(batchMode=True)
        register.signalOaiUpdate(metadataPrefixes=['prefix'], sets=set(), otherKey='ignored', stamp=1000)
        register.startOaiBatch()
        resumed = []

        suspend = compose(register.suspendBeforeSelect(clientIdentifier="id0", prefix='prefix', sets=[], continueAfter='1000')).next()
        suspend(reactor, lambda: resumed.append(True))
        suspend = compose(register.suspendBeforeSelect(clientIdentifier="id1", prefix='prefix', sets=[], continueAfter='1001')).next()
        suspend(reactor, lambda: resumed.append(True))
        self.assertEquals([], asList(register.suspendBeforeSelect(clientIdentifier="id2", prefix='prefix', sets=[], continueAfter='999')))

        self.assertEquals([], resumed)

        register.signalOaiUpdate(metadataPrefixes=['prefix'], sets=set(), otherKey='ignored', stamp=2000)
        self.assertEquals([], resumed)
        self.assertEquals(2, len(register))
        register.stopOaiBatch()
        self.assertEquals([True, True], resumed)
        self.assertEquals(0, len(register))
Exemplo n.º 13
0
 def add(self, lxmlNode, **kwargs):
     if type(lxmlNode) is _ElementTree:
         lxmlNode = lxmlNode.getroot()
     fieldslist = asList(fieldsFromAnnotation(lxmlNode))
     yield self.all.add(fieldslist=fieldslist, **kwargs)
Exemplo n.º 14
0
 def testInitialBatchSuspendBeforeResult(self):
     register = SuspendRegister(batchMode=True)
     register.startOaiBatch()
     self.assertEquals([], asList(register.suspendBeforeSelect(clientIdentifier="a-client-id", prefix='prefix', sets=[], continueAfter='0')))
     self.assertEquals([], asList(register.suspendBeforeSelect(clientIdentifier="a-client-id", prefix='prefix', sets=[], continueAfter='1000')))
Exemplo n.º 15
0
 def getStatus(self, **kwargs):
     return JsonList([x for x in asList(self._getStatus(**kwargs))])
Exemplo n.º 16
0
 def testCoreInfo(self):
     infos = asList(self._multiLucene.coreInfo())
     self.assertEquals(1, len(infos))
Exemplo n.º 17
0
 def testSuspendBeforeSelect(self):
     self.assertEquals([], asList(SuspendRegister().suspendBeforeSelect(continueAfter='9876', some='argument')))
     self.assertEquals([], asList(SuspendRegister(batchMode=True).suspendBeforeSelect(continueAfter='9876', some='argument')))
Exemplo n.º 18
0
 def getStatus(self, **kwargs):
     return JsonList([x for x in asList(self._getStatus(**kwargs))])