class PresenceServerTest(unittest.TestCase): def setUp(self): self.presence = PresenceService(MemoryStorage()) @defer.inlineCallbacks def test_removeStatus(self): tag1 = yield self.presence.putStatus('*****@*****.**', {"status": "online"}, expires=3600, tag='forwarding', priority=10) tag2 = yield self.presence.putStatus('*****@*****.**', {"status": "online"}, expires=3600) self.assertEqual('forwarding', tag1) yield self.presence.removeStatus('*****@*****.**', tag2) yield self.presence.removeStatus('*****@*****.**', 'forwarding') s1 = yield self.presence.getStatus('*****@*****.**') s2 = yield self.presence.getStatus('*****@*****.**') self.assertEqual(s1, []) self.assertEqual(s2, []) @defer.inlineCallbacks def test_statusExpires(self): yield self.presence.putStatus('*****@*****.**', '', tag='forwarding', expires=0.01) yield self.presence.putStatus('*****@*****.**', '', tag='calendar', expires=0.01) yield self.presence.putStatus('*****@*****.**', '', tag='rand', expires=0.01) d = defer.Deferred() reactor.callLater(0.02, d.callback, None) yield d s = yield self.presence.getStatus('*****@*****.**') self.assertEqual(s, []) @defer.inlineCallbacks def test_removeUnknownStatus(self): yield self.presence.removeStatus('*****@*****.**', 'cadabra') @defer.inlineCallbacks def test_getStatus(self): aq = self.assertEqual yield self.presence.putStatus('*****@*****.**', {"status": "online"}, expires=3600, tag='forwarding', priority=10) r = yield self.presence.getStatus('*****@*****.**') aq(len(r), 1) tag, status = r[0] aq(tag, 'forwarding') aq(status['presence'], {'status': 'online'}) yield self.presence.removeStatus('*****@*****.**', 'forwarding') @defer.inlineCallbacks def test_getUnknownStatus(self): aq = self.assertEqual r = yield self.presence.getStatus('*****@*****.**') aq(r, []) @defer.inlineCallbacks def test_statusLoadStore(self): d = defer.Deferred() yield self.presence._storeStatusTimer('*****@*****.**', 'tag', 0.01) yield self.presence._loadStatusTimers() self.assertTrue(self.presence._status_timers['*****@*****.**', 'tag'].active()) reactor.callLater( 0.02, lambda: d.callback(len(self.presence._status_timers))) d.addCallback(self.assertEqual, 0) yield d
def setUp(self): self.presence = PresenceService(MemoryStorage())
class PresenceServerTest(unittest.TestCase): def setUp(self): self.presence = PresenceService(MemoryStorage()) @defer.inlineCallbacks def test_removeStatus(self): tag1 = yield self.presence.putStatus('*****@*****.**', {"status": "online"}, expires=3600, tag='forwarding', priority=10) tag2 = yield self.presence.putStatus('*****@*****.**', {"status": "online"}, expires=3600) self.assertEqual('forwarding', tag1) yield self.presence.removeStatus('*****@*****.**', tag2) yield self.presence.removeStatus('*****@*****.**', 'forwarding') s1 = yield self.presence.getStatus('*****@*****.**') s2 = yield self.presence.getStatus('*****@*****.**') self.assertEqual(s1, []) self.assertEqual(s2, []) @defer.inlineCallbacks def test_statusExpires(self): yield self.presence.putStatus('*****@*****.**', {'status': 'online'}, tag='forwarding', expires=0.01) yield self.presence.putStatus('*****@*****.**', {'status': 'online'}, tag='calendar', expires=0.01) yield self.presence.putStatus('*****@*****.**', {'status': 'online'}, tag='rand', expires=0.01) d = defer.Deferred() reactor.callLater(0.02, d.callback, None) yield d s = yield self.presence.getStatus('*****@*****.**') self.assertEqual(s, []) @defer.inlineCallbacks def test_removeUnknownStatus(self): yield self.presence.removeStatus('*****@*****.**', 'cadabra') @defer.inlineCallbacks def test_getStatus(self): aq = self.assertEqual yield self.presence.putStatus('*****@*****.**', {"status": "online"}, expires=3600, tag='forwarding', priority=10) r = yield self.presence.getStatus('*****@*****.**') aq(len(r), 1) tag, status = r[0] aq(tag, 'forwarding') aq(status['presence'], {'status': 'online'}) yield self.presence.removeStatus('*****@*****.**', 'forwarding') @defer.inlineCallbacks def test_getUnknownStatus(self): aq = self.assertEqual r = yield self.presence.getStatus('*****@*****.**') aq(r, []) @defer.inlineCallbacks def test_statusLoadStore(self): d = defer.Deferred() yield self.presence._storeStatusTimer('*****@*****.**', 'tag', 0.01) yield self.presence._loadStatusTimers() self.assertTrue(self.presence._status_timers['*****@*****.**', 'tag'].active()) reactor.callLater(0.02, lambda: d.callback(len(self.presence._status_timers))) d.addCallback(self.assertEqual, 0) yield d