Merge lp:~james-w/launchpad-work-items-tracker/more-launchpad into lp:~linaro-automation/launchpad-work-items-tracker/linaro
- more-launchpad
- Merge into linaro
Proposed by
James Westby
Status: | Merged |
---|---|
Merged at revision: | 344 |
Proposed branch: | lp:~james-w/launchpad-work-items-tracker/more-launchpad |
Merge into: | lp:~linaro-automation/launchpad-work-items-tracker/linaro |
Diff against target: |
845 lines (+680/-50) 5 files modified
lpworkitems/fake_launchpad.py (+182/-2) lpworkitems/testing.py (+75/-0) lpworkitems/tests/test_factory.py (+7/-48) lpworkitems/tests/test_fake_launchpad.py (+415/-0) tests.py (+1/-0) |
To merge this branch: | bzr merge lp:~james-w/launchpad-work-items-tracker/more-launchpad |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Paul Sokolovsky | Approve | ||
Review via email: mp+63797@code.launchpad.net |
Commit message
Description of the change
Hi,
This branch improves the mock launchpadlib that we use for testing, and
adds a bunch of tests to it.
Thanks,
James
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lpworkitems/fake_launchpad.py' |
2 | --- lpworkitems/fake_launchpad.py 2011-03-23 16:16:50 +0000 |
3 | +++ lpworkitems/fake_launchpad.py 2011-06-08 02:19:22 +0000 |
4 | @@ -1,12 +1,20 @@ |
5 | class LaunchpadAPIObject(object): |
6 | |
7 | + RESOURCE_TYPE = None |
8 | + |
9 | def __init__(self): |
10 | self.self_link = None |
11 | self.web_link = None |
12 | |
13 | + @property |
14 | + def resource_type_link(self): |
15 | + return "some_url#%s" % self.RESOURCE_TYPE |
16 | + |
17 | |
18 | class LaunchpadMilestone(LaunchpadAPIObject): |
19 | |
20 | + RESOURCE_TYPE = "milestone" |
21 | + |
22 | def __init__(self, name, date_targeted, target): |
23 | super(LaunchpadMilestone, self).__init__() |
24 | self.name = name |
25 | @@ -16,13 +24,27 @@ |
26 | |
27 | class LaunchpadProject(LaunchpadAPIObject): |
28 | |
29 | + RESOURCE_TYPE = "project" |
30 | + |
31 | def __init__(self, name): |
32 | super(LaunchpadProject, self).__init__() |
33 | self.name = name |
34 | |
35 | |
36 | +class LaunchpadProjectSeries(LaunchpadAPIObject): |
37 | + |
38 | + RESOURCE_TYPE = "project_series" |
39 | + |
40 | + def __init__(self): |
41 | + super(LaunchpadProjectSeries, self).__init__() |
42 | + self.name = None |
43 | + self.project = None |
44 | + |
45 | + |
46 | class LaunchpadBlueprint(LaunchpadAPIObject): |
47 | |
48 | + RESOURCE_TYPE = "blueprint" |
49 | + |
50 | def __init__(self): |
51 | super(LaunchpadBlueprint, self).__init__() |
52 | self.priority = None |
53 | @@ -39,11 +61,83 @@ |
54 | |
55 | class LaunchpadPerson(LaunchpadAPIObject): |
56 | |
57 | + RESOURCE_TYPE = "person" |
58 | + |
59 | def __init__(self): |
60 | super(LaunchpadPerson, self).__init__() |
61 | self.name = None |
62 | |
63 | |
64 | +class LaunchpadBug(LaunchpadAPIObject): |
65 | + |
66 | + RESOURCE_TYPE = "bug" |
67 | + |
68 | + def __init__(self): |
69 | + super(LaunchpadBug, self).__init__() |
70 | + self.id = None |
71 | + self.title = None |
72 | + self.bug_tasks = [] |
73 | + |
74 | + |
75 | +class LaunchpadBugTask(LaunchpadAPIObject): |
76 | + |
77 | + RESOURCE_TYPE = "bug_task" |
78 | + |
79 | + def __init__(self): |
80 | + super(LaunchpadBugTask, self).__init__() |
81 | + self.status = None |
82 | + self.target = None |
83 | + self.bug = None |
84 | + self.assignee = None |
85 | + self.milestone = None |
86 | + self.related_tasks = [] |
87 | + |
88 | + |
89 | +class LaunchpadDistribution(LaunchpadAPIObject): |
90 | + |
91 | + RESOURCE_TYPE = "distribution" |
92 | + |
93 | + def __init__(self): |
94 | + super(LaunchpadDistribution, self).__init__() |
95 | + self.name = None |
96 | + |
97 | + |
98 | +class LaunchpadDistributionSeries(LaunchpadAPIObject): |
99 | + |
100 | + RESOURCE_TYPE = "distro_series" |
101 | + |
102 | + def __init__(self): |
103 | + super(LaunchpadDistributionSeries, self).__init__() |
104 | + self.name = None |
105 | + self.distribution = None |
106 | + |
107 | + |
108 | +class LaunchpadDistributionSourcePackage(LaunchpadAPIObject): |
109 | + """A source package in a distribution (not series-specific.)""" |
110 | + |
111 | + RESOURCE_TYPE = "distribution_source_package" |
112 | + |
113 | + def __init__(self): |
114 | + super(LaunchpadDistributionSourcePackage, self).__init__() |
115 | + self.distribution = None |
116 | + self.name = None |
117 | + |
118 | + |
119 | +class LaunchpadSourcePackage(LaunchpadAPIObject): |
120 | + """A source in a particular release of a distribution.""" |
121 | + |
122 | + RESOURCE_TYPE = "source_package" |
123 | + |
124 | + def __init__(self): |
125 | + super(LaunchpadSourcePackage, self).__init__() |
126 | + self.distroseries = None |
127 | + self.name = None |
128 | + |
129 | + @property |
130 | + def distribution(self): |
131 | + return self.distroseries.distribution |
132 | + |
133 | + |
134 | class FakeLaunchpad(object): |
135 | |
136 | def __init__(self, factory): |
137 | @@ -52,7 +146,7 @@ |
138 | self.people = {} |
139 | |
140 | def load(self, url): |
141 | - assert url in self._urls, "Loading unkonwn URL: %s" % url |
142 | + assert url in self._urls, "Loading unknown URL: %s" % url |
143 | return self._urls[url] |
144 | |
145 | def set_load_result(self, url, result): |
146 | @@ -78,9 +172,21 @@ |
147 | self.register_object(project) |
148 | return project |
149 | |
150 | + def make_project_series(self, name=None, project=None): |
151 | + if project is None: |
152 | + project = self.make_project() |
153 | + if name is None: |
154 | + name = self._factory.getUniqueUnicode( |
155 | + prefix="%s_series" % project.name) |
156 | + project_series = LaunchpadProjectSeries() |
157 | + project_series.name = name |
158 | + project_series.project = project |
159 | + self.register_object(project_series) |
160 | + return project_series |
161 | + |
162 | def make_milestone(self, name=None, date_targeted=None, target=None): |
163 | if name is None: |
164 | - name = self._factory.getUniqueUnicode(prefix="name") |
165 | + name = self._factory.getUniqueUnicode(prefix="lpmilestone") |
166 | if target is None: |
167 | target = self.make_project() |
168 | milestone = LaunchpadMilestone(name, date_targeted, target) |
169 | @@ -118,3 +224,77 @@ |
170 | self.register_object(person) |
171 | self.people[name] = person |
172 | return person |
173 | + |
174 | + def make_bug(self, id_=None, title=None): |
175 | + if id_ is None: |
176 | + id_ = self._factory.getUniqueInteger() |
177 | + if title is None: |
178 | + title = self._factory.getUniqueUnicode( |
179 | + prefix="bug_%d_description" % id_) |
180 | + bug = LaunchpadBug() |
181 | + bug.id = id_ |
182 | + bug.title = title |
183 | + self.register_object(bug) |
184 | + return bug |
185 | + |
186 | + def make_bug_task(self, bug=None, status=None, target=None, |
187 | + assignee=None, milestone=None): |
188 | + if bug is None: |
189 | + bug = self.make_bug() |
190 | + if target is None: |
191 | + target = self.make_project() |
192 | + if status is None: |
193 | + status = u"Expired" |
194 | + bug_task = LaunchpadBugTask() |
195 | + bug_task.bug = bug |
196 | + bug_task.status = status |
197 | + bug_task.target = target |
198 | + bug_task.assignee = assignee |
199 | + bug_task.milestone = milestone |
200 | + self.register_object(bug_task) |
201 | + bug.bug_tasks.append(bug_task) |
202 | + return bug_task |
203 | + |
204 | + def make_distribution(self, name=None): |
205 | + if name is None: |
206 | + name = self._factory.getUniqueUnicode(prefix="lpdistribution") |
207 | + distribution = LaunchpadDistribution() |
208 | + distribution.name = name |
209 | + self.register_object(distribution) |
210 | + return distribution |
211 | + |
212 | + def make_distro_series(self, distribution=None, name=None): |
213 | + if distribution is None: |
214 | + distribution = self.make_distribution() |
215 | + if name is None: |
216 | + name = self._factory.getUniqueUnicode( |
217 | + prefix="%s_release" % distribution.name) |
218 | + distro_series = LaunchpadDistributionSeries() |
219 | + distro_series.name = name |
220 | + distro_series.distribution = distribution |
221 | + self.register_object(distro_series) |
222 | + return distro_series |
223 | + |
224 | + def make_distribution_source_package(self, distribution=None, name=None): |
225 | + if distribution is None: |
226 | + distribution = self.make_distribution() |
227 | + if name is None: |
228 | + name = self._factory.getUniqueUnicode( |
229 | + prefix="%s_package" % distribution.name) |
230 | + distribution_source_package = LaunchpadDistributionSourcePackage() |
231 | + distribution_source_package.distribution = distribution |
232 | + distribution_source_package.name = name |
233 | + self.register_object(distribution_source_package) |
234 | + return distribution_source_package |
235 | + |
236 | + def make_source_package(self, distroseries=None, name=None): |
237 | + if distroseries is None: |
238 | + distroseries = self.make_distro_series() |
239 | + if name is None: |
240 | + name = self._factory.getUniqueUnicode( |
241 | + prefix="%s_package" % distroseries.name) |
242 | + source_package = LaunchpadSourcePackage() |
243 | + source_package.distroseries = distroseries |
244 | + source_package.name = name |
245 | + self.register_object(source_package) |
246 | + return source_package |
247 | |
248 | === modified file 'lpworkitems/testing.py' |
249 | --- lpworkitems/testing.py 2011-03-24 16:54:15 +0000 |
250 | +++ lpworkitems/testing.py 2011-06-08 02:19:22 +0000 |
251 | @@ -1,5 +1,6 @@ |
252 | from storm.locals import create_database, Store |
253 | from testtools import TestCase |
254 | +from testtools.matchers import Annotate, Matcher, Mismatch |
255 | |
256 | from lpworkitems.database import create_tables |
257 | from lpworkitems.factory import Factory |
258 | @@ -21,3 +22,77 @@ |
259 | def setUp(self): |
260 | super(TestCaseWithFakeLaunchpad, self).setUp() |
261 | self.lp = FakeLaunchpad(self.factory) |
262 | + |
263 | + |
264 | +class FactoryTestCaseMixin(TestCase): |
265 | + |
266 | + def assert_with_and_without(self, method, param, value, without_matcher=None, |
267 | + attribute_name=None): |
268 | + """Test the result of calling method with and without a parameter. |
269 | + |
270 | + This method checks that calling `method` with and without |
271 | + `param` gives the correct results. |
272 | + |
273 | + First `method` is called with `param` set to `value`, and the result |
274 | + is checked to see that the attribute with the same name as `param` |
275 | + is set to `value`. |
276 | + |
277 | + If `attribute_name` is not `None` that that attribute will be |
278 | + used instead of the one with the same name as `param`. |
279 | + |
280 | + Then `method` is called again with `param=None` and the result returned. |
281 | + If `without_matcher` is not None then it is checked that the |
282 | + attribute of the result with the same name as `param` satisfies the |
283 | + `matches` method of `without_matcher`. |
284 | + |
285 | + :param method: the method under test |
286 | + :type method: a function object |
287 | + :param param: the name of the paramater and attribute to test. |
288 | + :type param: str |
289 | + :param value: the value to pass as the value for `param` |
290 | + and to check against the result. |
291 | + :type value: anything |
292 | + :param without_matcher: a `Matcher` to use to test the result |
293 | + attribute when `None` is passed, or `None` to skip that test. |
294 | + :type without_matcher: `Matcher` or `None`. |
295 | + :param attribute_name: the name of the attribute to test, if |
296 | + different from `param`. |
297 | + :type attribute_name: str |
298 | + """ |
299 | + if attribute_name is None: |
300 | + attribute_name = param |
301 | + kwargs = {param: value} |
302 | + ret = method(**kwargs) |
303 | + self.assertEqual( |
304 | + value, getattr(ret, attribute_name), |
305 | + "%s returned an object with the wrong value for %s" |
306 | + " when called with %s=%s" % (method, attribute_name, param, value)) |
307 | + kwargs = {param: None} |
308 | + ret = method(**kwargs) |
309 | + if without_matcher: |
310 | + self.assertThat( |
311 | + getattr(ret, attribute_name), |
312 | + Annotate("%s returned an object with the wrong value " |
313 | + "for %s when called with %s=None" |
314 | + % (method, attribute_name, param), |
315 | + without_matcher)) |
316 | + return ret |
317 | + |
318 | + |
319 | +class IsNotInstanceMismatch(Mismatch): |
320 | + |
321 | + def describe(self): |
322 | + return "Is not an instance" |
323 | + |
324 | + |
325 | +class IsInstance(Matcher): |
326 | + |
327 | + def __init__(self, klass): |
328 | + self.klass = klass |
329 | + |
330 | + def match(self, matchee): |
331 | + if not isinstance(matchee, self.klass): |
332 | + return IsNotInstanceMismatch() |
333 | + |
334 | + def __str__(self): |
335 | + return "Is an instance of %s" % self.klass |
336 | |
337 | === modified file 'lpworkitems/tests/test_factory.py' |
338 | --- lpworkitems/tests/test_factory.py 2011-06-04 18:45:34 +0000 |
339 | +++ lpworkitems/tests/test_factory.py 2011-06-08 02:19:22 +0000 |
340 | @@ -1,17 +1,19 @@ |
341 | import datetime |
342 | |
343 | from testtools.matchers import ( |
344 | - Annotate, |
345 | Equals, |
346 | Not, |
347 | StartsWith, |
348 | ) |
349 | |
350 | from lpworkitems import models |
351 | -from lpworkitems.testing import TestCaseWithFactory |
352 | - |
353 | - |
354 | -class FactoryTestCase(TestCaseWithFactory): |
355 | +from lpworkitems.testing import ( |
356 | + FactoryTestCaseMixin, |
357 | + TestCaseWithFactory, |
358 | +) |
359 | + |
360 | + |
361 | +class FactoryTestCase(FactoryTestCaseMixin, TestCaseWithFactory): |
362 | |
363 | def assert_stores_result(self, method, klass): |
364 | """Assert that the method adds the result to the store. |
365 | @@ -38,49 +40,6 @@ |
366 | "The instance of %s stored by %s didn't match the " |
367 | "one it returned" % (klass, method)) |
368 | |
369 | - def assert_with_and_without(self, method, param, value, without_matcher=None): |
370 | - """Test the result of calling method with and without a parameter. |
371 | - |
372 | - This method checks that calling `method` with and without |
373 | - `param` gives the correct results. |
374 | - |
375 | - First `method` is called with `param` set to `value`, and the result |
376 | - is checked to see that the attribute with the same name as `param` |
377 | - is set to `value`. |
378 | - |
379 | - Then `method` is called again with `param=None` and the result returned. |
380 | - If `without_matcher` is not None then it is checked that the |
381 | - attribute of the result with the same name as `param` satisfies the |
382 | - `matches` method of `without_matcher`. |
383 | - |
384 | - :param method: the method under test |
385 | - :type method: a function object |
386 | - :param param: the name of the paramater and attribute to test. |
387 | - :type param: str |
388 | - :param value: the value to pass as the value for `param` |
389 | - and to check against the result. |
390 | - :type value: anything |
391 | - :param without_matcher: a `Matcher` to use to test the result |
392 | - attribute when `None` is passed, or `None` to skip that test. |
393 | - :type without_matcher: `Matcher` or `None`. |
394 | - """ |
395 | - kwargs = {param: value} |
396 | - ret = method(**kwargs) |
397 | - self.assertEqual( |
398 | - value, getattr(ret, param), |
399 | - "%s returned an object with the wrong value for %s" |
400 | - " when called with %s=%s" % (method, param, param, value)) |
401 | - kwargs = {param: None} |
402 | - ret = method(**kwargs) |
403 | - if without_matcher: |
404 | - self.assertThat( |
405 | - getattr(ret, param), |
406 | - Annotate("%s returned an object with the wrong value " |
407 | - "for %s when called with %s=None" |
408 | - % (method, param, param), |
409 | - without_matcher)) |
410 | - return ret |
411 | - |
412 | |
413 | class FactoryTests(TestCaseWithFactory): |
414 | |
415 | |
416 | === added file 'lpworkitems/tests/test_fake_launchpad.py' |
417 | --- lpworkitems/tests/test_fake_launchpad.py 1970-01-01 00:00:00 +0000 |
418 | +++ lpworkitems/tests/test_fake_launchpad.py 2011-06-08 02:19:22 +0000 |
419 | @@ -0,0 +1,415 @@ |
420 | +from testtools import TestCase |
421 | +from testtools.matchers import EndsWith, Equals, StartsWith |
422 | + |
423 | +from lpworkitems import fake_launchpad |
424 | +from lpworkitems.testing import ( |
425 | + FactoryTestCaseMixin, |
426 | + IsInstance, |
427 | + TestCaseWithFakeLaunchpad, |
428 | +) |
429 | + |
430 | + |
431 | +class LaunchpadAPIObjectTests(TestCase): |
432 | + |
433 | + def test_resource_type_link_ends_with_resource_type(self): |
434 | + person = fake_launchpad.LaunchpadPerson() |
435 | + self.assertThat( |
436 | + person.resource_type_link, |
437 | + EndsWith("#%s" % person.RESOURCE_TYPE)) |
438 | + |
439 | + |
440 | +class FakeLaunchpadTests(TestCaseWithFakeLaunchpad): |
441 | + |
442 | + def test_set_and_load(self): |
443 | + url = self.factory.getUniqueUnicode() |
444 | + result = fake_launchpad.LaunchpadPerson() |
445 | + self.lp.set_load_result(url, result) |
446 | + self.assertEqual(result, self.lp.load(url)) |
447 | + |
448 | + def test_register_object_sets_self_link(self): |
449 | + obj = fake_launchpad.LaunchpadPerson() |
450 | + self.assertEqual(None, obj.self_link) |
451 | + self.lp.register_object(obj) |
452 | + self.assertNotEqual(None, obj.self_link) |
453 | + |
454 | + def test_register_object_sets_web_link(self): |
455 | + obj = fake_launchpad.LaunchpadPerson() |
456 | + self.assertEqual(None, obj.web_link) |
457 | + self.lp.register_object(obj) |
458 | + self.assertNotEqual(None, obj.web_link) |
459 | + |
460 | + def test_register_object_registers(self): |
461 | + obj = fake_launchpad.LaunchpadPerson() |
462 | + self.lp.register_object(obj) |
463 | + self.assertEqual(obj, self.lp.load(obj.self_link)) |
464 | + |
465 | + def test_register_object_uses_existing_self_link(self): |
466 | + self_link = self.factory.getUniqueUnicode() |
467 | + obj = fake_launchpad.LaunchpadPerson() |
468 | + obj.self_link = self_link |
469 | + self.lp.register_object(obj) |
470 | + self.assertEqual(self_link, obj.self_link) |
471 | + self.assertEqual(obj, self.lp.load(self_link)) |
472 | + |
473 | + def test_make_self_link_returns_unicode(self): |
474 | + self_link = self.lp.make_self_link() |
475 | + self.assertIsInstance(self_link, unicode) |
476 | + |
477 | + def test_make_self_link_starts_with_self_link(self): |
478 | + self_link = self.lp.make_self_link() |
479 | + self.assertThat(self_link, StartsWith(u"self_link")) |
480 | + |
481 | + def test_make_web_link_returns_unicode(self): |
482 | + web_link = self.lp.make_web_link() |
483 | + self.assertIsInstance(web_link, unicode) |
484 | + |
485 | + def test_make_web_link_starts_with_web_link(self): |
486 | + web_link = self.lp.make_web_link() |
487 | + self.assertThat(web_link, StartsWith(u"web_link")) |
488 | + |
489 | + |
490 | +class FakeLaunchpadMakeProjectTests(FactoryTestCaseMixin, |
491 | + TestCaseWithFakeLaunchpad): |
492 | + |
493 | + def test_returns_project(self): |
494 | + project = self.lp.make_project() |
495 | + self.assertIsInstance( |
496 | + project, fake_launchpad.LaunchpadProject) |
497 | + |
498 | + def test_uses_name(self): |
499 | + name = self.factory.getUniqueUnicode(prefix="testproject") |
500 | + self.assert_with_and_without( |
501 | + self.lp.make_project, "name", name, StartsWith(u"lpproject")) |
502 | + |
503 | + def test_registers_project(self): |
504 | + project = self.lp.make_project() |
505 | + self.assertEqual(project, self.lp.load(project.self_link)) |
506 | + |
507 | + |
508 | +class FakeLaunchpadMakeProjectSeriesTests(FactoryTestCaseMixin, |
509 | + TestCaseWithFakeLaunchpad): |
510 | + |
511 | + def test_series_returns_project_series(self): |
512 | + project_series = self.lp.make_project_series() |
513 | + self.assertIsInstance( |
514 | + project_series, fake_launchpad.LaunchpadProjectSeries) |
515 | + |
516 | + def test_series_uses_project(self): |
517 | + project = self.lp.make_project() |
518 | + self.assert_with_and_without( |
519 | + self.lp.make_project_series, "project", project, |
520 | + IsInstance(fake_launchpad.LaunchpadProject)) |
521 | + |
522 | + def test_series_uses_name(self): |
523 | + name = self.factory.getUniqueUnicode() |
524 | + series = self.assert_with_and_without( |
525 | + self.lp.make_project_series, "name", name) |
526 | + self.assertThat( |
527 | + series.name, |
528 | + StartsWith("%s_series" % series.project.name)) |
529 | + |
530 | + def test_registers_object(self): |
531 | + series = self.lp.make_project_series() |
532 | + self.assertEqual(series, self.lp.load(series.self_link)) |
533 | + |
534 | + |
535 | +class FakeLaunchpadMakeMilestoneTests(FactoryTestCaseMixin, |
536 | + TestCaseWithFakeLaunchpad): |
537 | + |
538 | + def test_returns_milestone(self): |
539 | + milestone = self.lp.make_milestone() |
540 | + self.assertIsInstance( |
541 | + milestone, fake_launchpad.LaunchpadMilestone) |
542 | + |
543 | + def test_uses_name(self): |
544 | + name = self.factory.getUniqueUnicode() |
545 | + self.assert_with_and_without( |
546 | + self.lp.make_milestone, "name", name, |
547 | + StartsWith(u"lpmilestone")) |
548 | + |
549 | + def test_uses_target(self): |
550 | + target = self.lp.make_distribution() |
551 | + self.assert_with_and_without( |
552 | + self.lp.make_milestone, "target", target, |
553 | + IsInstance(fake_launchpad.LaunchpadProject)) |
554 | + |
555 | + def test_uses_date_targeted(self): |
556 | + date_targeted = self.factory.getUniqueDate() |
557 | + self.assert_with_and_without( |
558 | + self.lp.make_milestone, "date_targeted", date_targeted, |
559 | + Equals(None)) |
560 | + |
561 | + def test_registers_milestone(self): |
562 | + milestone = self.lp.make_milestone() |
563 | + self.assertEqual(milestone, self.lp.load(milestone.self_link)) |
564 | + |
565 | + |
566 | +class FakeLaunchpadMakeBlueprintTests(FactoryTestCaseMixin, |
567 | + TestCaseWithFakeLaunchpad): |
568 | + |
569 | + def test_returns_blueprint(self): |
570 | + blueprint = self.lp.make_blueprint() |
571 | + self.assertIsInstance(blueprint, fake_launchpad.LaunchpadBlueprint) |
572 | + |
573 | + def test_uses_name(self): |
574 | + name = self.factory.getUniqueUnicode(prefix=u"testbp") |
575 | + self.assert_with_and_without( |
576 | + self.lp.make_blueprint, "name", name, |
577 | + StartsWith(u"lpblueprint")) |
578 | + |
579 | + def test_uses_priority(self): |
580 | + priority = u"High" |
581 | + self.assert_with_and_without( |
582 | + self.lp.make_blueprint, "priority", priority, |
583 | + Equals(None)) |
584 | + |
585 | + def test_uses_definition_status(self): |
586 | + definition_status = u"Drafting" |
587 | + self.assert_with_and_without( |
588 | + self.lp.make_blueprint, "definition_status", definition_status, |
589 | + Equals(None)) |
590 | + |
591 | + def test_uses_implementation_status(self): |
592 | + implementation_status = u"Implemented" |
593 | + self.assert_with_and_without( |
594 | + self.lp.make_blueprint, "implementation_status", implementation_status, |
595 | + Equals(None)) |
596 | + |
597 | + def test_uses_approver(self): |
598 | + approver = self.lp.make_person() |
599 | + self.assert_with_and_without( |
600 | + self.lp.make_blueprint, "approver", approver, Equals(None)) |
601 | + |
602 | + def test_uses_drafter(self): |
603 | + drafter = self.lp.make_person() |
604 | + self.assert_with_and_without( |
605 | + self.lp.make_blueprint, "drafter", drafter, Equals(None)) |
606 | + |
607 | + def test_uses_assignee(self): |
608 | + assignee = self.lp.make_person() |
609 | + self.assert_with_and_without( |
610 | + self.lp.make_blueprint, "assignee", assignee, Equals(None)) |
611 | + |
612 | + def test_uses_milestone(self): |
613 | + milestone = self.lp.make_milestone() |
614 | + self.assert_with_and_without( |
615 | + self.lp.make_blueprint, "milestone", milestone, Equals(None)) |
616 | + |
617 | + def test_uses_whiteboard(self): |
618 | + whiteboard = self.factory.getUniqueUnicode() |
619 | + self.assert_with_and_without( |
620 | + self.lp.make_blueprint, "whiteboard", whiteboard, Equals(None)) |
621 | + |
622 | + def test_uses_specification_url(self): |
623 | + specification_url = self.factory.getUniqueUnicode() |
624 | + self.assert_with_and_without( |
625 | + self.lp.make_blueprint, "specification_url", specification_url, |
626 | + Equals(None)) |
627 | + |
628 | + def test_uses_summary(self): |
629 | + summary = self.factory.getUniqueUnicode() |
630 | + self.assert_with_and_without( |
631 | + self.lp.make_blueprint, "summary", summary, Equals(None)) |
632 | + |
633 | + def test_registers_blueprint(self): |
634 | + blueprint = self.lp.make_blueprint() |
635 | + self.assertEqual(blueprint, self.lp.load(blueprint.self_link)) |
636 | + |
637 | + |
638 | +class FakeLaunchpadMakePersonTests(FactoryTestCaseMixin, |
639 | + TestCaseWithFakeLaunchpad): |
640 | + |
641 | + def test_returns_person(self): |
642 | + person = self.lp.make_person() |
643 | + self.assertIsInstance(person, fake_launchpad.LaunchpadPerson) |
644 | + |
645 | + |
646 | + def test_uses_name(self): |
647 | + name = self.factory.getUniqueUnicode(prefix=u"testperson") |
648 | + self.assert_with_and_without( |
649 | + self.lp.make_person, "name", name, StartsWith(u"lpperson")) |
650 | + |
651 | + def test_registers_person(self): |
652 | + person = self.lp.make_person() |
653 | + self.assertEqual(person, self.lp.load(person.self_link)) |
654 | + |
655 | + def test_adds_to_people(self): |
656 | + person = self.lp.make_person() |
657 | + self.assertEqual(person, self.lp.people[person.name]) |
658 | + |
659 | + |
660 | +class FakeLaunchpadMakeBugTests(FactoryTestCaseMixin, |
661 | + TestCaseWithFakeLaunchpad): |
662 | + |
663 | + def test_returns_bug(self): |
664 | + bug = self.lp.make_bug() |
665 | + self.assertIsInstance(bug, fake_launchpad.LaunchpadBug) |
666 | + |
667 | + def test_uses_id(self): |
668 | + id_ = self.factory.getUniqueInteger() |
669 | + self.assert_with_and_without( |
670 | + self.lp.make_bug, "id_", id_, IsInstance(int), |
671 | + attribute_name="id") |
672 | + |
673 | + def test_uses_title(self): |
674 | + title = self.factory.getUniqueUnicode(prefix=u"testtitle") |
675 | + bug = self.assert_with_and_without( |
676 | + self.lp.make_bug, "title", title) |
677 | + self.assertThat( |
678 | + bug.title, |
679 | + StartsWith("bug_%d_description" % bug.id)) |
680 | + |
681 | + def test_registers_bug(self): |
682 | + bug = self.lp.make_bug() |
683 | + self.assertEqual(bug, self.lp.load(bug.self_link)) |
684 | + |
685 | + |
686 | +class FakeLaunchpadMakeBugTaskTests(FactoryTestCaseMixin, |
687 | + TestCaseWithFakeLaunchpad): |
688 | + |
689 | + def test_returns_bug_task(self): |
690 | + bug_task = self.lp.make_bug_task() |
691 | + self.assertIsInstance(bug_task, fake_launchpad.LaunchpadBugTask) |
692 | + |
693 | + def test_uses_bug(self): |
694 | + bug = self.lp.make_bug() |
695 | + self.assert_with_and_without( |
696 | + self.lp.make_bug_task, "bug", bug, |
697 | + IsInstance(fake_launchpad.LaunchpadBug)) |
698 | + |
699 | + def test_uses_target(self): |
700 | + target = self.lp.make_distribution() |
701 | + self.assert_with_and_without( |
702 | + self.lp.make_bug_task, "target", target, |
703 | + IsInstance(fake_launchpad.LaunchpadProject)) |
704 | + |
705 | + def test_uses_assignee(self): |
706 | + assignee = self.lp.make_person() |
707 | + self.assert_with_and_without( |
708 | + self.lp.make_bug_task, "assignee", assignee, Equals(None)) |
709 | + |
710 | + def test_uses_milestone(self): |
711 | + milestone = self.lp.make_milestone() |
712 | + self.assert_with_and_without( |
713 | + self.lp.make_bug_task, "milestone", milestone, Equals(None)) |
714 | + |
715 | + def test_uses_status(self): |
716 | + status = u"Opinion" |
717 | + self.assert_with_and_without( |
718 | + self.lp.make_bug_task, "status", status, Equals(u"Expired")) |
719 | + |
720 | + def test_registers_bug_task(self): |
721 | + bug_task = self.lp.make_bug_task() |
722 | + self.assertEqual(bug_task, self.lp.load(bug_task.self_link)) |
723 | + |
724 | + def test_adds_task_to_bug(self): |
725 | + bug_task = self.lp.make_bug_task() |
726 | + self.assertEqual(1, len(bug_task.bug.bug_tasks)) |
727 | + self.assertEqual(bug_task, bug_task.bug.bug_tasks[0]) |
728 | + |
729 | + |
730 | +class FakeLaunchpadMakeDistributionTests(FactoryTestCaseMixin, |
731 | + TestCaseWithFakeLaunchpad): |
732 | + |
733 | + def test_returns_distribution(self): |
734 | + distribution = self.lp.make_distribution() |
735 | + self.assertIsInstance( |
736 | + distribution, fake_launchpad.LaunchpadDistribution) |
737 | + |
738 | + def test_uses_name(self): |
739 | + name = self.factory.getUniqueUnicode( |
740 | + prefix=u"testdistribuition") |
741 | + self.assert_with_and_without( |
742 | + self.lp.make_distribution, "name", name, |
743 | + StartsWith(u"lpdistribution")) |
744 | + |
745 | + def test_registers_distribution(self): |
746 | + distribution = self.lp.make_distribution() |
747 | + self.assertEqual(distribution, self.lp.load(distribution.self_link)) |
748 | + |
749 | + |
750 | +class FakeLaunchpadMakeDistroSeriesTests(FactoryTestCaseMixin, |
751 | + TestCaseWithFakeLaunchpad): |
752 | + |
753 | + def test_returns_distro_series(self): |
754 | + distro_series = self.lp.make_distro_series() |
755 | + self.assertIsInstance( |
756 | + distro_series, fake_launchpad.LaunchpadDistributionSeries) |
757 | + |
758 | + def test_uses_distribution(self): |
759 | + distribution = self.lp.make_distribution() |
760 | + self.assert_with_and_without( |
761 | + self.lp.make_distro_series, "distribution", distribution, |
762 | + IsInstance(fake_launchpad.LaunchpadDistribution)) |
763 | + |
764 | + def test_uses_name(self): |
765 | + name = self.factory.getUniqueUnicode(prefix="testdistroseries") |
766 | + distro_series = self.assert_with_and_without( |
767 | + self.lp.make_distro_series, "name", name) |
768 | + self.assertThat( |
769 | + distro_series.name, |
770 | + StartsWith("%s_release" % distro_series.distribution.name)) |
771 | + |
772 | + def test_registers_distribution(self): |
773 | + distribution = self.lp.make_distribution() |
774 | + self.assertEqual(distribution, self.lp.load(distribution.self_link)) |
775 | + |
776 | + |
777 | +class FakeLaunchpadMakeDistributionSourcePackage(FactoryTestCaseMixin, |
778 | + TestCaseWithFakeLaunchpad): |
779 | + |
780 | + def test_returns_distribution_source_package(self): |
781 | + distribution_source_package = ( |
782 | + self.lp.make_distribution_source_package()) |
783 | + self.assertIsInstance( |
784 | + distribution_source_package, |
785 | + fake_launchpad.LaunchpadDistributionSourcePackage) |
786 | + |
787 | + def test_uses_distribution(self): |
788 | + distribution = self.lp.make_distribution() |
789 | + self.assert_with_and_without( |
790 | + self.lp.make_distribution_source_package, "distribution", |
791 | + distribution, IsInstance(fake_launchpad.LaunchpadDistribution)) |
792 | + |
793 | + def test_uses_name(self): |
794 | + name = self.factory.getUniqueUnicode(prefix=u"testdsp") |
795 | + dsp = self.assert_with_and_without( |
796 | + self.lp.make_distribution_source_package, "name", name) |
797 | + self.assertThat( |
798 | + dsp.name, |
799 | + StartsWith("%s_package" % dsp.distribution.name)) |
800 | + |
801 | + def test_registers_distribution_source_package(self): |
802 | + distribution_source_package = ( |
803 | + self.lp.make_distribution_source_package()) |
804 | + self.assertEqual( |
805 | + distribution_source_package, |
806 | + self.lp.load(distribution_source_package.self_link)) |
807 | + |
808 | + |
809 | +class FakeLaunchpadMakeSourcePackageTests(FactoryTestCaseMixin, |
810 | + TestCaseWithFakeLaunchpad): |
811 | + |
812 | + def test_returns_source_package(self): |
813 | + source_package = self.lp.make_source_package() |
814 | + self.assertIsInstance( |
815 | + source_package, fake_launchpad.LaunchpadSourcePackage) |
816 | + |
817 | + def test_uses_distroseries(self): |
818 | + distroseries = self.lp.make_distro_series() |
819 | + self.assert_with_and_without( |
820 | + self.lp.make_source_package, "distroseries", distroseries, |
821 | + IsInstance(fake_launchpad.LaunchpadDistributionSeries)) |
822 | + |
823 | + def test_uses_name(self): |
824 | + name = self.factory.getUniqueUnicode(prefix=u"testpackage") |
825 | + source_package = self.assert_with_and_without( |
826 | + self.lp.make_source_package, "name", name) |
827 | + self.assertThat( |
828 | + source_package.name, |
829 | + StartsWith(u"%s_package" % source_package.distroseries.name)) |
830 | + |
831 | + def test_registers_source_package(self): |
832 | + source_package = self.lp.make_source_package() |
833 | + self.assertEqual( |
834 | + source_package, self.lp.load(source_package.self_link)) |
835 | |
836 | === modified file 'tests.py' |
837 | --- tests.py 2011-05-31 16:20:49 +0000 |
838 | +++ tests.py 2011-06-08 02:19:22 +0000 |
839 | @@ -170,5 +170,6 @@ |
840 | suite.addTests(loader.loadTestsFromName("lpworkitems.tests.test_collect")) |
841 | suite.addTests(loader.loadTestsFromName("lpworkitems.tests.test_error_collector")) |
842 | suite.addTests(loader.loadTestsFromName("lpworkitems.tests.test_factory")) |
843 | + suite.addTests(loader.loadTestsFromName("lpworkitems.tests.test_fake_launchpad")) |
844 | suite.addTests(loader.loadTestsFromName("lpworkitems.tests.test_models")) |
845 | return suite |
Seems like good refactors and test coverage extension.