Esempio n. 1
0
    def testCountIPMessages(self):
        d = defer.succeed(None)

        for i in xrange(15):
            d.addCallback(lambda _: userFrequencyCheck(domain=getDefaultDomain(), message=self.message4, attribute="ip", storage="testStorage", count=16, timeout=10). \
                addCallback(self.assertTrue))

        d.addCallback(lambda _: userFrequencyCheck(domain=getDefaultDomain(), message=self.message4, attribute="ip", storage="testStorage", count=16, timeout=10). \
            addCallback(self.assertFalse)).addCallback(lambda _: advanceTestTimer(10)). \
        addCallback(lambda _: userFrequencyCheck(domain=getDefaultDomain(), message=self.message4, attribute="ip", storage="testStorage", count=16, timeout=10). \
            addCallback(self.assertTrue))

        return d
Esempio n. 2
0
    def testCleanup(self):
        def checkState1(_):
            self.assertEquals(self.s.deleteQueue, { 100 : { 'key1' : 1 }, 101 : { 'key2' : 1 }})
            self.assertEquals(self.s.hash, { 'key1' : (1005, 'value1'), 'key2' : (1015, 'value2') })
            self.assertEquals(self.s.lastDeleteTime, 100)

        def checkState2(_):
            self.assertEquals(self.s.deleteQueue, { 101 : { 'key2' : 1 }})
            self.assertEquals(self.s.hash, { 'key2' : (1015, 'value2') })
            self.assertEquals(self.s.lastDeleteTime, 101)

        return self.s.set('key1', 'value1', 5).addCallback(lambda _: self.s.set('key2', 'value2', 15)).addCallback(checkState1) \
                .addCallback(lambda _: advanceTestTimer(12)).addCallback(lambda _: self.s._cleanup()).addCallback(checkState2)
Esempio n. 3
0
 def testSetUnlimited(self):
     return self.s.set('key_u', 'value', 0).addCallback(lambda _: advanceTestTimer(1000000)).addCallback(lambda _: self.s.get('key_u')) \
             .addCallback(self.assertEquals, 'value')
Esempio n. 4
0
 def testAdd(self):
     return self.s.set('key', 'value', 1).addCallback(lambda _: self.s.add('key', 'value2', 1)).addCallback(lambda _: self.assert_(False)) \
             .addErrback(lambda failure: failure.trap(KeyError)).addCallback(lambda _: advanceTestTimer(1)) \
             .addCallback(lambda _: self.s.add('key', 'value2', 1)).addCallback(lambda _: self.s.get('key')) \
             .addCallback(self.assertEquals, 'value2')
Esempio n. 5
0
 def testAdvance(self):
     advanceTestTimer(20)
     self.assertEquals(30, time())
Esempio n. 6
0
 def testFirstWithShift(self):
     return defer.DeferredList([self.log.put(self.message2, when=when) for when in [850, 852, 900, 901, 920]]) \
             .addCallback(lambda _: advanceTestTimer(500)).addCallback(lambda _: self.log.fetch(first=852)) \
             .addCallback(lambda result: self.assertEquals([852, 900, 901, 920], map(lambda i: i.when, result)))
Esempio n. 7
0
 def testPutFetchLong(self):
     return self.log.put(self.message1).addCallback(lambda _: advanceTestTimer(989)).addCallback(lambda _: self.log.fetch()) \
             .addCallback(self.assertEquals, [LogEntry(when=1000, message=self.message1, id=1)] ) \
             .addCallback(lambda _: advanceTestTimer(1)).addCallback(lambda _: self.log.fetch()).addCallback(self.assertEquals, [])