# Copyright (C) 2006-2012 Mortal Coil Games # See LICENSE for details. """ -*- test-case-name: mv3d.test.test_eventservice Test the EventService Class """ from twisted.internet import reactor from twisted.internet import defer from twisted.trial.unittest import TestCase from mv3d.reporter.event import Event from mv3d.reporter.event import Filter, FilterCondition from mv3d.reporter.event import EventService from mv3d.reporter.event import EventSubscription from mv3d.util.date import Date class Test_EventService(TestCase): """ You need to add a docstring here ! """ def receiveEvent(self, e): """ You need to add a docstring here ! """ self.event = e def setUp(self): """ You need to add a docstring here ! """ self.event = 0 def createFilter(self): """ You need to add a docstring here ! """ fc = FilterCondition() f = Filter() fc.item = "date" fc.test = ">" fc.addParameter(Date().parse("yesterday")) f.addRule(fc) return f def test_Constructor(self): """ You need to add a docstring here ! """ t = EventService(self) self.assertEqual(t.server, self) self.assertEqual(t.subscribers, []) self.assertEqual(t.recentevents, []) self.assertEqual(t.maxrecentevents, 500) def test_pushEvent(self): """ You need to add a docstring here ! """ t = EventService(self) t.subscribers = [self] e = Event() e.setCategory("Hello") t.pushEvent(e) self.assertNotEqual(self.event, 0) self.assertEqual(self.event.getCategory(), "Hello") def test_subscribe(self): """ You need to add a docstring here ! """ t = EventService(self) t.subscribe(self) self.assertEqual(len(t.subscribers), 1) def test_unsubscribe(self): """ You need to add a docstring here ! """ t = EventService(self) t.subscribe(self) r = t.unsubscribe(self) self.assertEqual(r, 1) self.assertNotIn(self, t.subscribers) def test_newSubscription(self): """ You need to add a docstring here ! """ t = EventService(self) t.newSubscription(self) self.assertEqual(len(t.subscribers), 1) self.assertEqual(t.subscribers[0].receiver, self.receiveEvent) def test_DuplicateEvent(self): """ You need to add a docstring here ! """ t = EventService(self) s = t.newSubscription(self) f = self.createFilter() s.addFilter(f) e = Event() e.setCategory("Test") t.pushEvent(e) self.assertEqual(self.event, e) self.event = 0 t.pushEvent(e) self.assertEqual(self.event, 0) e.setCategory("Test2") self.event = 0 t.pushEvent(e) self.assertEqual(self.event, e)