Merge lp:~exarkun/divmod.org/grabber-scheduler-usage into lp:divmod.org

Proposed by Jean-Paul Calderone
Status: Merged
Approved by: Tristan Seligmann
Approved revision: 2692
Merged at revision: 2692
Proposed branch: lp:~exarkun/divmod.org/grabber-scheduler-usage
Merge into: lp:divmod.org
Diff against target: 166 lines (+86/-5)
2 files modified
Quotient/xquotient/grabber.py (+9/-3)
Quotient/xquotient/test/test_grabber.py (+77/-2)
To merge this branch: bzr merge lp:~exarkun/divmod.org/grabber-scheduler-usage
Reviewer Review Type Date Requested Status
Tristan Seligmann Approve
Review via email: mp+103982@code.launchpad.net

Description of the change

Changed the three obvious places in `Quotient/xquotient/grabber.py` that used the long-since deleted `scheduler` attribute. Added a test for each.

To post a comment you must log in.
Revision history for this message
Tristan Seligmann (mithrandi) wrote :

The code changes are indeed obvious, and the new tests look good; please merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Quotient/xquotient/grabber.py'
2--- Quotient/xquotient/grabber.py 2009-07-16 00:52:55 +0000
3+++ Quotient/xquotient/grabber.py 2012-04-28 14:28:21 +0000
4@@ -93,6 +93,7 @@
5 """, default=0)
6 powerupNames = ["xquotient.grabber.GrabberConfiguration"]
7
8+
9 class GrabberConfiguration(item.Item):
10 """
11 Manages the creation, operation, and destruction of grabbers
12@@ -124,7 +125,7 @@
13 config=self,
14 ssl=ssl)
15 # DO IT *NOW*
16- self.scheduler.schedule(pg, extime.Time())
17+ iaxiom.IScheduler(self.store).schedule(pg, extime.Time())
18 # OR MAYBE A LITTLE LATER
19
20 item.declareLegacyItem(GrabberConfiguration.typeName, 1, dict(
21@@ -274,7 +275,7 @@
22 self.status = Status(store=self.store, message=u'idle')
23
24 def delete(self):
25- self.config.scheduler.unscheduleAll(self)
26+ iaxiom.IScheduler(self.store).unscheduleAll(self)
27 if self.running:
28 if self.protocol is not None:
29 self.protocol.stop()
30@@ -633,7 +634,7 @@
31 return
32 self.grabber.running = False
33 if self._transient:
34- self.grabber.config.scheduler.reschedule(
35+ iaxiom.IScheduler(self.grabber.store).reschedule(
36 self.grabber,
37 self.grabber.scheduled,
38 extime.Time())
39@@ -645,6 +646,11 @@
40 protocol = ControlledPOP3GrabberProtocol
41
42 def __init__(self, grabber, ssl):
43+ """
44+ @param grabber: The L{POP3Grabber} item driving this factory.
45+
46+ @param ssl: A flag indicating whether an SSL connection will be attempted.
47+ """
48 self.grabber = grabber
49 self.ssl = ssl
50
51
52=== modified file 'Quotient/xquotient/test/test_grabber.py'
53--- Quotient/xquotient/test/test_grabber.py 2006-11-22 03:43:56 +0000
54+++ Quotient/xquotient/test/test_grabber.py 2012-04-28 14:28:21 +0000
55@@ -12,7 +12,7 @@
56
57 from epsilon.test import iosim
58
59-from axiom import store
60+from axiom import iaxiom, store, substore, scheduler
61
62 from xquotient import grabber, mimepart
63
64@@ -195,7 +195,7 @@
65
66
67
68-class POP3GrabberTestCase(unittest.TestCase):
69+class POP3GrabberProtocolTestCase(unittest.TestCase):
70 testMessageStrings = ['First message', 'Second message', 'Last message']
71
72
73@@ -360,14 +360,75 @@
74
75
76
77+class ControlledPOP3GrabberTestCase(unittest.TestCase):
78+ """
79+ Tests for L{xquotient.grabber.ControlledPOP3GrabberProtocol}.
80+ """
81+ def test_stoppedRunningWithGrabber(self):
82+ """
83+ When L{ControlledPOP3GrabberProtocol.stoppedRunning} is called after a
84+ transient failure, and the protocol instance has an associated grabber,
85+ that grabber is rescheduled to run immediately.
86+ """
87+ siteStore = store.Store()
88+ subStore = substore.SubStore.createNew(siteStore, ['grabber'])
89+ userStore = subStore.open()
90+ scheduler = iaxiom.IScheduler(userStore)
91+
92+ grabberItem = grabber.POP3Grabber(
93+ store=userStore, username=u"alice", domain=u"example.com",
94+ password=u"secret", running=True,
95+ config=grabber.GrabberConfiguration(store=userStore))
96+ grabberItem.scheduled = extime.Time()
97+ scheduler.schedule(grabberItem, grabberItem.scheduled)
98+
99+ factory = grabber.POP3GrabberFactory(grabberItem, False)
100+ protocol = factory.buildProtocol(None)
101+ protocol.transientFailure(None)
102+ protocol.stoppedRunning()
103+ self.assertEqual(False, grabberItem.running)
104+
105+ scheduled = list(scheduler.scheduledTimes(grabberItem))
106+ self.assertEqual(1, len(scheduled))
107+ self.assertTrue(scheduled[0] <= extime.Time())
108+
109+
110+
111+class GrabberConfigurationTestCase(unittest.TestCase):
112+ """
113+ Tests for L{xquotient.grabber.GrabberConfiguration}.
114+ """
115+ def test_addGrabber(self):
116+ """
117+ L{GrabberConfiguration.addGrabber} creates a new L{POP3Grabber} item
118+ scheduled to run immediately.
119+ """
120+ siteStore = store.Store()
121+ subStore = substore.SubStore.createNew(siteStore, ['grabber'])
122+ userStore = subStore.open()
123+ scheduler = iaxiom.IScheduler(userStore)
124+
125+ config = grabber.GrabberConfiguration(store=userStore)
126+ config.addGrabber(u"alice", u"secret", u"example.com", False)
127+ grabberItems = list(userStore.query(grabber.POP3Grabber))
128+
129+ self.assertEqual(1, len(grabberItems))
130+ scheduled = list(scheduler.scheduledTimes(grabberItems[0]))
131+ self.assertEqual(1, len(scheduled))
132+ self.assertTrue(scheduled[0] <= extime.Time())
133+
134+
135+
136 class PersistentControllerTestCase(unittest.TestCase):
137 """
138 Tests for the Axiom-y parts of L{xquotient.grabber.POP3Grabber}.
139 """
140 def setUp(self):
141 self.store = store.Store()
142+ self.config = grabber.GrabberConfiguration(store=self.store)
143 self.grabber = grabber.POP3Grabber(
144 store=self.store,
145+ config=self.config,
146 username=u"testuser",
147 domain=u"example.com",
148 password=u"password")
149@@ -423,3 +484,17 @@
150 self.grabber.shouldRetrieve([(49, '49'), (50, '50'),
151 (51, '51')]),
152 [(49, '49'), (51, '51')])
153+
154+
155+ def test_delete(self):
156+ """
157+ L{POP3Grabber.delete} unschedules the grabber.
158+ """
159+ store = self.grabber.store
160+ iaxiom.IScheduler(store).schedule(self.grabber, extime.Time())
161+ self.grabber.delete()
162+
163+ # Can't query for the TimedEvent directly, but we know nothing *else*
164+ # was scheduled either.
165+ self.assertEqual(
166+ [], list(store.query(scheduler.TimedEvent)))

Subscribers

People subscribed via source and target branches