Merge lp:~james-w/launchpad/soyuz-factory-improvements into lp:launchpad

Proposed by James Westby
Status: Merged
Merged at revision: 11361
Proposed branch: lp:~james-w/launchpad/soyuz-factory-improvements
Merge into: lp:launchpad
Diff against target: 1093 lines (+703/-59)
9 files modified
lib/lp/soyuz/configure.zcml (+2/-1)
lib/lp/soyuz/interfaces/binarypackagename.py (+1/-6)
lib/lp/soyuz/model/binarypackagename.py (+11/-17)
lib/lp/soyuz/scripts/tests/test_ppa_apache_log_parser.py (+2/-2)
lib/lp/soyuz/tests/test_binarypackagename.py (+217/-0)
lib/lp/testing/factory.py (+80/-20)
lib/lp/testing/matchers.py (+39/-1)
lib/lp/testing/tests/test_factory.py (+314/-8)
lib/lp/testing/tests/test_matchers.py (+37/-4)
To merge this branch: bzr merge lp:~james-w/launchpad/soyuz-factory-improvements
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+31890@code.launchpad.net

Commit message

Improve the Soyuz parts of the factory.

Description of the change

Hi,

This makes some improvements to the Soyuz parts of the factory.

There are a couple of bugfixes, but mostly it is the addition of
new features.

There is also a change to make distributions and distroseries have
less generic names, which helped make some test failures more
readable.

This branch is laying the groundwork for my next, which will make
SoyuzTestPublisher use the factory.

No lint.

Thanks,

James

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Oh, the first changes in the diff are to actually get the objects to
pass verifyObject.

isAutoSyncUpload had no permission specified, so it stopped verifyObject
from passing. It now as zope.Public.

The other changes are unimplemented or broken implementations of unused
attributes, so I just deleted them.

There are also some lint cleanups, and I fixed a copy paste comment in a
test that I found.

Thanks,

James

Revision history for this message
Abel Deuring (adeuring) wrote :
Download full text (4.1 KiB)

Hi James,

overall, a very nice branch! I have just two issues:

> === modified file 'lib/lp/soyuz/model/binarypackagename.py'
> --- lib/lp/soyuz/model/binarypackagename.py 2010-08-02 02:13:52 +0000
> +++ lib/lp/soyuz/model/binarypackagename.py 2010-08-05 20:54:49 +0000
> @@ -8,7 +8,7 @@
> 'BinaryPackageName',
> 'BinaryPackageNameSet',
> 'BinaryPackageNameVocabulary',
> - 'getBinaryPackageDescriptions'
> + 'getBinaryPackageDescriptions',
> ]
>
> # Zope imports
> @@ -17,7 +17,7 @@
>
> # SQLObject/SQLBase
> from sqlobject import (
> - SQLObjectNotFound, StringCol, SQLMultipleJoin, CONTAINSSTRING)
> + SQLObjectNotFound, StringCol, CONTAINSSTRING)
>
> from storm.store import EmptyResultSet
>
> @@ -39,10 +39,6 @@
> name = StringCol(dbName='name', notNull=True, unique=True,
> alternateID=True)
>
> - binarypackages = SQLMultipleJoin(
> - 'BinaryPackage', joinColumn='binarypackagename'
> - )
> -
> def __unicode__(self):
> return self.name
>
> @@ -125,6 +121,7 @@
>
> Builds descriptions based on releases of that binary package name.
> """
> +
> def getTermsWithDescriptions(self, results):
> # Prefill the descriptions dictionary with the latest
> # description uploaded for that package name.
> @@ -165,11 +162,10 @@
>
> for release in releases:
> binarypackagename = release.binarypackagename.name
> - if not descriptions.has_key(binarypackagename):
> + if binarypackagename in descriptions:

I think this should be "if binarypackagename not in descriptions:" ;)
It seemes to me that the function getBinaryPackageDescriptions() deserves a test. Would you mind to add one?

> description = release.description.strip().replace("\n", " ")
> if len(description) > max_title_length:
> description = (release.description[:max_title_length]
> + "...")
> descriptions[binarypackagename] = description
> return descriptions
> -
>

[...]

> === modified file 'lib/lp/testing/factory.py'
> --- lib/lp/testing/factory.py 2010-08-04 00:47:20 +0000
> +++ lib/lp/testing/factory.py 2010-08-05 20:54:49 +0000
[...]
> @@ -2267,6 +2267,35 @@
> def getAnySourcePackageUrgency(self):
> return SourcePackageUrgency.MEDIUM
>
> + def makePackageUpload(self, distroseries=None, archive=None,
> + pocket=None, changes_filename=None,
> + changes_file_content=None,
> + signing_key=None, status=None):
> + if archive is None:
> + archive = self.makeArchive()
> + if distroseries is None:
> + distroseries = self.makeDistroSeries(
> + distribution=archive.distribution)
> + if changes_filename is None:
> + changes_filename = self.getUniqueString("changesfilename")
> + if changes_file_content is None:
> + changes_file_content = self.getUniqueString("changesfilecontent")
> + if pocket is None:
> + pocket = PackagePublishingPocket.RELEASE
> + packag...

Read more...

review: Approve (code)
Revision history for this message
Abel Deuring (adeuring) wrote :

Hi James,

the additional changes look good too. Many thanks especially for the very thorough tests!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/configure.zcml'
2--- lib/lp/soyuz/configure.zcml 2010-08-06 03:27:00 +0000
3+++ lib/lp/soyuz/configure.zcml 2010-08-16 21:55:59 +0000
4@@ -188,7 +188,8 @@
5 displayversion
6 is_delayed_copy
7 isPPA
8- components"/>
9+ components
10+ isAutoSyncUpload"/>
11 <require
12 permission="launchpad.Edit"
13 attributes="
14
15=== modified file 'lib/lp/soyuz/interfaces/binarypackagename.py'
16--- lib/lp/soyuz/interfaces/binarypackagename.py 2010-01-12 19:02:09 +0000
17+++ lib/lp/soyuz/interfaces/binarypackagename.py 2010-08-16 21:55:59 +0000
18@@ -14,7 +14,7 @@
19 ]
20
21 from zope.schema import Int, TextLine
22-from zope.interface import Interface, Attribute
23+from zope.interface import Interface
24
25 from canonical.launchpad import _
26 from canonical.launchpad.validators.name import name_validator
27@@ -26,11 +26,6 @@
28 name = TextLine(title=_('Valid Binary package name'),
29 required=True, constraint=name_validator)
30
31- binarypackages = Attribute('binarypackages')
32-
33- def nameSelector(sourcepackage=None, selected=None):
34- """Return browser-ready HTML to select a Binary Package Name"""
35-
36 def __unicode__():
37 """Return the name"""
38
39
40=== modified file 'lib/lp/soyuz/model/binarypackagename.py'
41--- lib/lp/soyuz/model/binarypackagename.py 2010-08-02 02:13:52 +0000
42+++ lib/lp/soyuz/model/binarypackagename.py 2010-08-16 21:55:59 +0000
43@@ -8,7 +8,7 @@
44 'BinaryPackageName',
45 'BinaryPackageNameSet',
46 'BinaryPackageNameVocabulary',
47- 'getBinaryPackageDescriptions'
48+ 'getBinaryPackageDescriptions',
49 ]
50
51 # Zope imports
52@@ -17,7 +17,7 @@
53
54 # SQLObject/SQLBase
55 from sqlobject import (
56- SQLObjectNotFound, StringCol, SQLMultipleJoin, CONTAINSSTRING)
57+ SQLObjectNotFound, StringCol, CONTAINSSTRING)
58
59 from storm.store import EmptyResultSet
60
61@@ -39,10 +39,6 @@
62 name = StringCol(dbName='name', notNull=True, unique=True,
63 alternateID=True)
64
65- binarypackages = SQLMultipleJoin(
66- 'BinaryPackage', joinColumn='binarypackagename'
67- )
68-
69 def __unicode__(self):
70 return self.name
71
72@@ -72,12 +68,6 @@
73 def new(self, name):
74 return BinaryPackageName(name=name)
75
76- def getOrCreateByName(self, name):
77- try:
78- return self[name]
79- except NotFoundError:
80- return self.new(name)
81-
82 def ensure(self, name):
83 """Ensure that the given BinaryPackageName exists, creating it
84 if necessary.
85@@ -85,9 +75,11 @@
86 Returns the BinaryPackageName
87 """
88 try:
89- return BinaryPackageName.byName(name)
90- except SQLObjectNotFound:
91- return BinaryPackageName(name=name)
92+ return self[name]
93+ except NotFoundError:
94+ return self.new(name)
95+
96+ getOrCreateByName = ensure
97
98 def getNotNewByNames(self, name_ids, distroseries, archive_ids):
99 """See `IBinaryPackageNameSet`."""
100@@ -125,6 +117,7 @@
101
102 Builds descriptions based on releases of that binary package name.
103 """
104+
105 def getTermsWithDescriptions(self, results):
106 # Prefill the descriptions dictionary with the latest
107 # description uploaded for that package name.
108@@ -148,6 +141,8 @@
109
110 See sourcepackage.py:getSourcePackageDescriptions, which is analogous.
111 """
112+ if len(list(results)) < 1:
113+ return {}
114 if use_names:
115 clause = ("BinaryPackageName.name in %s" %
116 sqlvalues([pn.name for pn in results]))
117@@ -165,11 +160,10 @@
118
119 for release in releases:
120 binarypackagename = release.binarypackagename.name
121- if not descriptions.has_key(binarypackagename):
122+ if binarypackagename not in descriptions:
123 description = release.description.strip().replace("\n", " ")
124 if len(description) > max_title_length:
125 description = (release.description[:max_title_length]
126 + "...")
127 descriptions[binarypackagename] = description
128 return descriptions
129-
130
131=== modified file 'lib/lp/soyuz/scripts/tests/test_ppa_apache_log_parser.py'
132--- lib/lp/soyuz/scripts/tests/test_ppa_apache_log_parser.py 2010-07-20 12:06:36 +0000
133+++ lib/lp/soyuz/scripts/tests/test_ppa_apache_log_parser.py 2010-08-16 21:55:59 +0000
134@@ -40,8 +40,8 @@
135 self.assertIs(None, get_ppa_file_key('/foo'))
136
137 def test_get_ppa_file_key_ignores_non_binary_path(self):
138- # A path with extra path segments returns None, to indicate that
139- # it should be ignored.
140+ # A path pointing to a file not from a binary package returns
141+ # None to indicate that it should be ignored.
142 self.assertIs(None, get_ppa_file_key(
143 '/cprov/ppa/ubuntu/pool/main/f/foo/foo_1.2.3-4.dsc'))
144
145
146=== added file 'lib/lp/soyuz/tests/test_binarypackagename.py'
147--- lib/lp/soyuz/tests/test_binarypackagename.py 1970-01-01 00:00:00 +0000
148+++ lib/lp/soyuz/tests/test_binarypackagename.py 2010-08-16 21:55:59 +0000
149@@ -0,0 +1,217 @@
150+# Copyright 2010 Canonical Ltd. This software is licensed under the
151+# GNU Affero General Public License version 3 (see the file LICENSE).
152+
153+"""Test BinaryPackageName."""
154+
155+__metaclass__ = type
156+
157+from datetime import datetime
158+
159+import pytz
160+from zope.component import getUtility
161+
162+from canonical.testing import DatabaseFunctionalLayer
163+from lp.app.errors import NotFoundError
164+from lp.soyuz.interfaces.binarypackagename import IBinaryPackageNameSet
165+from lp.soyuz.interfaces.publishing import PackagePublishingStatus
166+from lp.soyuz.model.binarypackagename import getBinaryPackageDescriptions
167+from lp.testing import TestCaseWithFactory
168+
169+
170+class TestBinaryPackageNameSet(TestCaseWithFactory):
171+
172+ layer = DatabaseFunctionalLayer
173+
174+ def setUp(self):
175+ super(TestBinaryPackageNameSet, self).setUp()
176+ self.name_set = getUtility(IBinaryPackageNameSet)
177+
178+ def test___getitem__found(self):
179+ name = self.factory.makeBinaryPackageName()
180+ self.assertEqual(name, self.name_set[name.name])
181+
182+ def test___getitem__not_found(self):
183+ self.assertRaises(
184+ NotFoundError, lambda name: self.name_set[name], "notfound")
185+
186+ def test_getAll_contains_one(self):
187+ name = self.factory.makeBinaryPackageName()
188+ self.assertIn(name, self.name_set.getAll())
189+
190+ def test_findByName_not_found(self):
191+ self.assertEqual([], list(self.name_set.findByName("notfound")))
192+
193+ def test_findByName_found(self):
194+ name1 = self.factory.makeBinaryPackageName("prefixname")
195+ name2 = self.factory.makeBinaryPackageName("name")
196+ name3 = self.factory.makeBinaryPackageName("namesuffix")
197+ name4 = self.factory.makeBinaryPackageName("other")
198+ self.assertEqual(
199+ [name1, name2, name3], list(self.name_set.findByName("name")))
200+
201+ def test_queryByName_not_found(self):
202+ self.assertEqual(None, self.name_set.queryByName("notfound"))
203+
204+ def test_queryByName_found(self):
205+ name = self.factory.makeBinaryPackageName()
206+ self.assertEqual(name, self.name_set.queryByName(name.name))
207+
208+ def test_new(self):
209+ name = self.name_set.new("apackage")
210+ self.assertEqual("apackage", name.name)
211+
212+ def test_getOrCreateByName_get(self):
213+ name = self.factory.makeBinaryPackageName()
214+ self.assertEqual(name, self.name_set.getOrCreateByName(name.name))
215+
216+ def test_getOrCreateByName_create(self):
217+ self.assertEqual(
218+ "apackage", self.name_set.getOrCreateByName("apackage").name)
219+
220+ def test_ensure_get(self):
221+ name = self.factory.makeBinaryPackageName()
222+ self.assertEqual(name, self.name_set.ensure(name.name))
223+
224+ def test_ensure_create(self):
225+ self.assertEqual(
226+ "apackage", self.name_set.ensure("apackage").name)
227+
228+ def createPublishingRecords(self, status=None):
229+ distroseries = self.factory.makeDistroSeries()
230+ distroarchseries = self.factory.makeDistroArchSeries(
231+ distroseries=distroseries)
232+ archives = [
233+ self.factory.makeArchive(distribution=distroseries.distribution),
234+ self.factory.makeArchive(distribution=distroseries.distribution),
235+ ]
236+ names = [
237+ self.factory.makeBinaryPackageName(),
238+ self.factory.makeBinaryPackageName(),
239+ self.factory.makeBinaryPackageName(),
240+ ]
241+ for i in range(2):
242+ bpr = self.factory.makeBinaryPackageRelease(
243+ binarypackagename=names[i])
244+ self.factory.makeBinaryPackagePublishingHistory(
245+ binarypackagerelease=bpr,
246+ status=PackagePublishingStatus.PUBLISHED,
247+ archive=archives[i],
248+ distroarchseries=distroarchseries,
249+ )
250+ return names, distroarchseries, archives
251+
252+ def test_getNotNewByNames_excludes_unpublished(self):
253+ names, distroarchseries, archives = self.createPublishingRecords()
254+ self.assertEqual(
255+ sorted([names[0], names[1]]),
256+ sorted(self.name_set.getNotNewByNames(
257+ [name.id for name in names], distroarchseries.distroseries,
258+ [archive.id for archive in archives])))
259+
260+ def test_getNotNewByNames_excludes_by_status(self):
261+ names, distroarchseries, archives = self.createPublishingRecords()
262+ bpr = self.factory.makeBinaryPackageRelease(
263+ binarypackagename=names[2])
264+ self.factory.makeBinaryPackagePublishingHistory(
265+ binarypackagerelease=bpr,
266+ status=PackagePublishingStatus.DELETED,
267+ archive=archives[0], distroarchseries=distroarchseries)
268+ self.assertEqual(
269+ sorted([names[0], names[1]]),
270+ sorted(self.name_set.getNotNewByNames(
271+ [name.id for name in names], distroarchseries.distroseries,
272+ [archive.id for archive in archives])))
273+
274+ def test_getNotNewByNames_excludes_by_name_id(self):
275+ names, distroarchseries, archives = self.createPublishingRecords()
276+ self.assertEqual(
277+ [names[1]],
278+ list(self.name_set.getNotNewByNames(
279+ [name.id for name in names[1:]],
280+ distroarchseries.distroseries,
281+ [archive.id for archive in archives])))
282+
283+ def test_getNotNewByNames_excludes_by_distroseries(self):
284+ names, distroarchseries, archives = self.createPublishingRecords()
285+ bpr = self.factory.makeBinaryPackageRelease(
286+ binarypackagename=names[2])
287+ self.factory.makeBinaryPackagePublishingHistory(
288+ binarypackagerelease=bpr,
289+ status=PackagePublishingStatus.PUBLISHED,
290+ archive=archives[0])
291+ self.assertEqual(
292+ sorted([names[0], names[1]]),
293+ sorted(self.name_set.getNotNewByNames(
294+ [name.id for name in names], distroarchseries.distroseries,
295+ [archive.id for archive in archives])))
296+
297+ def test_getNotNewByNames_excludes_by_archive(self):
298+ names, distroarchseries, archives = self.createPublishingRecords()
299+ self.assertEqual(
300+ [names[0]],
301+ list(self.name_set.getNotNewByNames(
302+ [name.id for name in names], distroarchseries.distroseries,
303+ [archive.id for archive in archives[:1]])))
304+
305+ def test_getBinaryPackageDescriptions_none(self):
306+ self.assertEqual({}, getBinaryPackageDescriptions([]))
307+
308+ def test_getBinaryPackageDescriptions_no_release(self):
309+ name = self.factory.makeBinaryPackageName()
310+ self.assertEqual({}, getBinaryPackageDescriptions([name]))
311+
312+ def test_getBinaryPackageDescriptions_one_release(self):
313+ name = self.factory.makeBinaryPackageName()
314+ self.factory.makeBinaryPackageRelease(
315+ binarypackagename=name, description="foo")
316+ self.assertEqual(
317+ {name.name: "foo"},
318+ getBinaryPackageDescriptions([name], max_title_length=3))
319+
320+ def test_getBinaryPackageDescriptions_shortens_names(self):
321+ name = self.factory.makeBinaryPackageName()
322+ self.factory.makeBinaryPackageRelease(
323+ binarypackagename=name, description="foot")
324+ self.assertEqual(
325+ {name.name: "foo..."},
326+ getBinaryPackageDescriptions([name], max_title_length=3))
327+
328+ def test_getBinaryPackageDescriptions_uses_latest(self):
329+ name = self.factory.makeBinaryPackageName()
330+ self.factory.makeBinaryPackageRelease(
331+ binarypackagename=name, description="foo",
332+ date_created=datetime(1980, 01, 01, tzinfo=pytz.UTC))
333+ self.factory.makeBinaryPackageRelease(
334+ binarypackagename=name, description="bar",
335+ date_created=datetime(2000, 01, 01, tzinfo=pytz.UTC))
336+ self.assertEqual(
337+ {name.name: "bar"},
338+ getBinaryPackageDescriptions([name], max_title_length=3))
339+
340+ def test_getBinaryPackageDescriptions_two_packages(self):
341+ name1 = self.factory.makeBinaryPackageName()
342+ name2 = self.factory.makeBinaryPackageName()
343+ self.factory.makeBinaryPackageRelease(
344+ binarypackagename=name1, description="foo")
345+ self.factory.makeBinaryPackageRelease(
346+ binarypackagename=name2, description="bar")
347+ self.assertEqual(
348+ {name1.name: "foo", name2.name: "bar"},
349+ getBinaryPackageDescriptions([name1, name2], max_title_length=3))
350+
351+ def test_getBinaryPackageDescriptions_strips_newlines(self):
352+ name = self.factory.makeBinaryPackageName()
353+ self.factory.makeBinaryPackageRelease(
354+ binarypackagename=name, description="f\no")
355+ self.assertEqual(
356+ {name.name: "f o"},
357+ getBinaryPackageDescriptions([name], max_title_length=3))
358+
359+ def test_getBinaryPackageDescriptions_use_names(self):
360+ name = self.factory.makeBinaryPackageName()
361+ self.factory.makeBinaryPackageRelease(
362+ binarypackagename=name, description="foo")
363+ self.assertEqual(
364+ {name.name: "foo"},
365+ getBinaryPackageDescriptions(
366+ [name], use_names=True, max_title_length=3))
367
368=== modified file 'lib/lp/testing/factory.py'
369--- lib/lp/testing/factory.py 2010-08-16 20:07:06 +0000
370+++ lib/lp/testing/factory.py 2010-08-16 21:55:59 +0000
371@@ -143,6 +143,7 @@
372 from lp.soyuz.interfaces.archive import (
373 default_name_by_purpose, IArchiveSet, ArchivePurpose)
374 from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet
375+from lp.soyuz.interfaces.binarypackagename import IBinaryPackageNameSet
376 from lp.soyuz.interfaces.binarypackagerelease import (
377 BinaryPackageFileType, BinaryPackageFormat)
378 from lp.soyuz.interfaces.component import IComponentSet
379@@ -150,9 +151,8 @@
380 from lp.soyuz.interfaces.processor import IProcessorFamilySet
381 from lp.soyuz.interfaces.publishing import (
382 IPublishingSet, PackagePublishingPriority, PackagePublishingStatus)
383+from lp.soyuz.interfaces.queue import PackageUploadStatus
384 from lp.soyuz.interfaces.section import ISectionSet
385-from lp.soyuz.model.binarypackagename import BinaryPackageName
386-from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
387 from lp.soyuz.model.files import BinaryPackageFile, SourcePackageReleaseFile
388 from lp.soyuz.model.processor import ProcessorFamilySet
389 from lp.testing import (
390@@ -1671,9 +1671,9 @@
391 members=None, title=None, aliases=None):
392 """Make a new distribution."""
393 if name is None:
394- name = self.getUniqueString()
395+ name = self.getUniqueString(prefix="distribution")
396 if displayname is None:
397- displayname = self.getUniqueString()
398+ displayname = name.capitalize()
399 if title is None:
400 title = self.getUniqueString()
401 description = self.getUniqueString()
402@@ -1697,7 +1697,7 @@
403 if distribution is None:
404 distribution = self.makeDistribution()
405 if name is None:
406- name = self.getUniqueString()
407+ name = self.getUniqueString(prefix="distroseries")
408 if displayname is None:
409 displayname = name.capitalize()
410 if version is None:
411@@ -2277,6 +2277,34 @@
412 def getAnySourcePackageUrgency(self):
413 return SourcePackageUrgency.MEDIUM
414
415+ def makePackageUpload(self, distroseries=None, archive=None,
416+ pocket=None, changes_filename=None,
417+ changes_file_content=None,
418+ signing_key=None, status=None):
419+ if archive is None:
420+ archive = self.makeArchive()
421+ if distroseries is None:
422+ distroseries = self.makeDistroSeries(
423+ distribution=archive.distribution)
424+ if changes_filename is None:
425+ changes_filename = self.getUniqueString("changesfilename")
426+ if changes_file_content is None:
427+ changes_file_content = self.getUniqueString("changesfilecontent")
428+ if pocket is None:
429+ pocket = PackagePublishingPocket.RELEASE
430+ package_upload = distroseries.createQueueEntry(
431+ pocket, changes_filename, changes_file_content, archive,
432+ signing_key=signing_key)
433+ if status is not None:
434+ naked_package_upload = removeSecurityProxy(package_upload)
435+ status_changers = {
436+ PackageUploadStatus.DONE: naked_package_upload.setDone,
437+ PackageUploadStatus.ACCEPTED:
438+ naked_package_upload.setAccepted,
439+ }
440+ status_changers[status]()
441+ return package_upload
442+
443 def makeSourcePackageRelease(self, archive=None, sourcepackagename=None,
444 distroseries=None, maintainer=None,
445 creator=None, component=None,
446@@ -2323,9 +2351,10 @@
447 if maintainer is None:
448 maintainer = self.makePerson()
449
450- maintainer_email = '%s <%s>' % (
451- maintainer.displayname,
452- maintainer.preferredemail.email)
453+ if dsc_maintainer_rfc822 is None:
454+ dsc_maintainer_rfc822 = '%s <%s>' % (
455+ maintainer.displayname,
456+ maintainer.preferredemail.email)
457
458 if creator is None:
459 creator = self.makePerson()
460@@ -2351,7 +2380,7 @@
461 dsc=None,
462 copyright=self.getUniqueString(),
463 dscsigningkey=dscsigningkey,
464- dsc_maintainer_rfc822=maintainer_email,
465+ dsc_maintainer_rfc822=dsc_maintainer_rfc822,
466 dsc_standards_version=dsc_standards_version,
467 dsc_format=dsc_format,
468 dsc_binaries=dsc_binaries,
469@@ -2491,6 +2520,8 @@
470 naked_spph.datecreated = date_uploaded
471 naked_spph.dateremoved = dateremoved
472 naked_spph.scheduleddeletiondate = scheduleddeletiondate
473+ if status == PackagePublishingStatus.PUBLISHED:
474+ naked_spph.datepublished = UTC_NOW
475 return spph
476
477 def makeBinaryPackagePublishingHistory(self, binarypackagerelease=None,
478@@ -2539,12 +2570,25 @@
479 naked_bpph.dateremoved = dateremoved
480 naked_bpph.scheduleddeletiondate = scheduleddeletiondate
481 naked_bpph.priority = priority
482+ if status == PackagePublishingStatus.PUBLISHED:
483+ naked_bpph.datepublished = UTC_NOW
484 return bpph
485
486 def makeBinaryPackageName(self, name=None):
487+ """Make an `IBinaryPackageName`."""
488 if name is None:
489 name = self.getUniqueString("binarypackage")
490- return BinaryPackageName(name=name)
491+ return getUtility(IBinaryPackageNameSet).new(name)
492+
493+ def getOrMakeBinaryPackageName(self, name=None):
494+ """Get an existing `IBinaryPackageName` or make a new one.
495+
496+ This method encapsulates getOrCreateByName so that tests can be kept
497+ free of the getUtility(IBinaryPackageNameSet) noise.
498+ """
499+ if name is None:
500+ return self.makeBinaryPackageName()
501+ return getUtility(IBinaryPackageNameSet).getOrCreateByName(name)
502
503 def makeBinaryPackageFile(self, binarypackagerelease=None,
504 library_file=None, filetype=None):
505@@ -2563,32 +2607,48 @@
506 binpackageformat=None, component=None,
507 section_name=None, priority=None,
508 architecturespecific=False,
509- summary=None, description=None):
510+ summary=None, description=None,
511+ shlibdeps=None, depends=None,
512+ recommends=None, suggests=None,
513+ conflicts=None, replaces=None,
514+ provides=None, pre_depends=None,
515+ enhances=None, breaks=None,
516+ essential=False, installed_size=None,
517+ date_created=None, debug_package=None):
518 """Make a `BinaryPackageRelease`."""
519+ if build is None:
520+ build = self.makeBinaryPackageBuild()
521 if binarypackagename is None:
522 binarypackagename = self.makeBinaryPackageName()
523 if version is None:
524- version = self.getUniqueString("version")
525- if build is None:
526- build = self.makeBinaryPackageBuild()
527+ version = build.source_package_release.version
528 if binpackageformat is None:
529 binpackageformat = BinaryPackageFormat.DEB
530 if component is None:
531- component = self.makeComponent()
532- section = self.makeSection(name=section_name)
533+ component = build.source_package_release.component
534+ section = build.source_package_release.section
535 if priority is None:
536 priority = PackagePublishingPriority.OPTIONAL
537 if summary is None:
538 summary = self.getUniqueString("summary")
539 if description is None:
540 description = self.getUniqueString("description")
541- return ProxyFactory(
542- BinaryPackageRelease(
543+ if installed_size is None:
544+ installed_size = self.getUniqueInteger()
545+ bpr = build.createBinaryPackageRelease(
546 binarypackagename=binarypackagename, version=version,
547- build=build, binpackageformat=binpackageformat,
548+ binpackageformat=binpackageformat,
549 component=component, section=section, priority=priority,
550 summary=summary, description=description,
551- architecturespecific=architecturespecific))
552+ architecturespecific=architecturespecific,
553+ shlibdeps=shlibdeps, depends=depends, recommends=recommends,
554+ suggests=suggests, conflicts=conflicts, replaces=replaces,
555+ provides=provides, pre_depends=pre_depends,
556+ enhances=enhances, breaks=breaks, essential=essential,
557+ installedsize=installed_size, debug_package=debug_package)
558+ if date_created is not None:
559+ removeSecurityProxy(bpr).datecreated = date_created
560+ return bpr
561
562 def makeSection(self, name=None):
563 """Make a `Section`."""
564
565=== modified file 'lib/lp/testing/matchers.py'
566--- lib/lp/testing/matchers.py 2010-08-05 09:57:43 +0000
567+++ lib/lp/testing/matchers.py 2010-08-16 21:55:59 +0000
568@@ -3,13 +3,15 @@
569
570 __metaclass__ = type
571 __all__ = [
572+ 'DoesNotCorrectlyProvide',
573 'DoesNotProvide',
574- 'DoesNotCorrectlyProvide',
575+ 'DoesNotStartWith',
576 'HasQueryCount',
577 'IsNotProxied',
578 'IsProxied',
579 'Provides',
580 'ProvidesAndIsProxied',
581+ 'StartsWith',
582 ]
583
584 from zope.interface.verify import verifyObject
585@@ -175,3 +177,39 @@
586 if mismatch is not None:
587 return mismatch
588 return IsProxied().match(matchee)
589+
590+
591+class DoesNotStartWith(Mismatch):
592+
593+ def __init__(self, matchee, expected):
594+ """Create a DoesNotStartWith Mismatch.
595+
596+ :param matchee: the string that did not match.
597+ :param expected: the string that `matchee` was expected to start
598+ with.
599+ """
600+ self.matchee = matchee
601+ self.expected = expected
602+
603+ def describe(self):
604+ return "'%s' does not start with '%s'." % (
605+ self.matchee, self.expected)
606+
607+
608+class StartsWith(Matcher):
609+ """Checks whether one string starts with another."""
610+
611+ def __init__(self, expected):
612+ """Create a StartsWith Matcher.
613+
614+ :param expected: the string that matchees should start with.
615+ """
616+ self.expected = expected
617+
618+ def __str__(self):
619+ return "Starts with '%s'." % self.expected
620+
621+ def match(self, matchee):
622+ if not matchee.startswith(self.expected):
623+ return DoesNotStartWith(matchee, self.expected)
624+ return None
625
626=== modified file 'lib/lp/testing/tests/test_factory.py'
627--- lib/lp/testing/tests/test_factory.py 2010-08-10 03:59:25 +0000
628+++ lib/lp/testing/tests/test_factory.py 2010-08-16 21:55:59 +0000
629@@ -17,31 +17,45 @@
630 DatabaseFunctionalLayer, LaunchpadZopelessLayer)
631 from lp.buildmaster.interfaces.buildbase import BuildStatus
632 from lp.code.enums import BranchType, CodeImportReviewStatus
633+from lp.registry.interfaces.distribution import IDistribution
634+from lp.registry.interfaces.distroseries import IDistroSeries
635 from lp.registry.interfaces.sourcepackage import SourcePackageFileType
636 from lp.registry.interfaces.suitesourcepackage import ISuiteSourcePackage
637 from lp.services.worlddata.interfaces.language import ILanguage
638 from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuild
639+from lp.soyuz.interfaces.binarypackagename import IBinaryPackageName
640 from lp.soyuz.interfaces.binarypackagerelease import (
641- BinaryPackageFileType, IBinaryPackageRelease)
642+ BinaryPackageFileType, BinaryPackageFormat, IBinaryPackageRelease)
643 from lp.soyuz.interfaces.files import (
644 IBinaryPackageFile, ISourcePackageReleaseFile)
645 from lp.soyuz.interfaces.publishing import (
646 IBinaryPackagePublishingHistory, ISourcePackagePublishingHistory,
647- PackagePublishingPriority, PackagePublishingStatus)
648+ PackagePublishingPriority, PackagePublishingPocket,
649+ PackagePublishingStatus)
650+from lp.soyuz.interfaces.queue import IPackageUpload, PackageUploadStatus
651+from lp.soyuz.interfaces.sourcepackagerelease import ISourcePackageRelease
652 from lp.testing import TestCaseWithFactory
653 from lp.testing.factory import is_security_proxied_or_harmless
654-from lp.testing.matchers import IsProxied, Provides, ProvidesAndIsProxied
655+from lp.testing.matchers import (
656+ IsProxied, Provides, ProvidesAndIsProxied, StartsWith)
657
658
659 class TestFactory(TestCaseWithFactory):
660
661 layer = DatabaseFunctionalLayer
662
663- def test_makeBranch_initialMirrorRequest(self):
664- # The default 'next_mirror_time' for a newly created hosted branch
665- # should be None.
666- branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)
667- self.assertIs(None, branch.next_mirror_time)
668+ # getOrMakeBinaryPackageName
669+ def test_getOrMakeBinaryPackageName_returns_proxied_IBPN(self):
670+ binarypackagename = self.factory.getOrMakeBinaryPackageName()
671+ self.assertThat(
672+ binarypackagename, ProvidesAndIsProxied(IBinaryPackageName))
673+
674+ def test_getOrMakeBinaryPackageName_returns_existing_name(self):
675+ binarypackagename1 = self.factory.getOrMakeBinaryPackageName(
676+ name="foo")
677+ binarypackagename2 = self.factory.getOrMakeBinaryPackageName(
678+ name="foo")
679+ self.assertEqual(binarypackagename1, binarypackagename2)
680
681 # loginAsAnyone
682 def test_loginAsAnyone(self):
683@@ -77,6 +91,12 @@
684 status=BuildStatus.FULLYBUILT)
685 self.assertEqual(BuildStatus.FULLYBUILT, bpb.status)
686
687+ # makeBinaryPackageName
688+ def test_makeBinaryPackageName_returns_proxied_IBinaryPackageName(self):
689+ binarypackagename = self.factory.makeBinaryPackageName()
690+ self.assertThat(
691+ binarypackagename, ProvidesAndIsProxied(IBinaryPackageName))
692+
693 # makeBinaryPackagePublishingHistory
694 def test_makeBinaryPackagePublishingHistory_returns_IBPPH(self):
695 bpph = self.factory.makeBinaryPackagePublishingHistory()
696@@ -116,11 +136,177 @@
697 priority=PackagePublishingPriority.EXTRA)
698 self.assertEquals(PackagePublishingPriority.EXTRA, bpph.priority)
699
700+ def test_makeBinaryPackagePublishingHistory_sets_datecreated(self):
701+ bpph = self.factory.makeBinaryPackagePublishingHistory()
702+ self.assertNotEqual(None, bpph.datecreated)
703+
704+ def test_makeBinaryPackagePublishingHistory_sets_datepub_PENDING(self):
705+ bpph = self.factory.makeBinaryPackagePublishingHistory(
706+ status=PackagePublishingStatus.PENDING)
707+ self.assertEqual(None, bpph.datepublished)
708+
709+ def test_makeBinaryPackagePublishingHistory_sets_datepub_PUBLISHED(self):
710+ bpph = self.factory.makeBinaryPackagePublishingHistory(
711+ status=PackagePublishingStatus.PUBLISHED)
712+ self.assertNotEqual(None, bpph.datepublished)
713+
714 # makeBinaryPackageRelease
715 def test_makeBinaryPackageRelease_returns_IBinaryPackageRelease(self):
716 bpr = self.factory.makeBinaryPackageRelease()
717 self.assertThat(bpr, ProvidesAndIsProxied(IBinaryPackageRelease))
718
719+ def test_makeBinaryPackageRelease_uses_build(self):
720+ build = self.factory.makeBinaryPackageBuild()
721+ bpr = self.factory.makeBinaryPackageRelease(build=build)
722+ self.assertEqual(build, bpr.build)
723+
724+ def test_makeBinaryPackageRelease_uses_build_version(self):
725+ build = self.factory.makeBinaryPackageBuild()
726+ bpr = self.factory.makeBinaryPackageRelease(build=build)
727+ self.assertEqual(
728+ build.source_package_release.version, bpr.version)
729+
730+ def test_makeBinaryPackageRelease_uses_build_component(self):
731+ build = self.factory.makeBinaryPackageBuild()
732+ bpr = self.factory.makeBinaryPackageRelease(build=build)
733+ self.assertEqual(
734+ build.source_package_release.component, bpr.component)
735+
736+ def test_makeBinaryPackageRelease_uses_build_section(self):
737+ build = self.factory.makeBinaryPackageBuild()
738+ bpr = self.factory.makeBinaryPackageRelease(build=build)
739+ self.assertEqual(
740+ build.source_package_release.section, bpr.section)
741+
742+ def test_makeBinaryPackageRelease_matches_build_version(self):
743+ bpr = self.factory.makeBinaryPackageRelease()
744+ self.assertEqual(
745+ bpr.build.source_package_release.version, bpr.version)
746+
747+ def test_makeBinaryPackageRelease_matches_build_component(self):
748+ bpr = self.factory.makeBinaryPackageRelease()
749+ self.assertEqual(
750+ bpr.build.source_package_release.component, bpr.component)
751+
752+ def test_makeBinaryPackageRelease_matches_build_section(self):
753+ bpr = self.factory.makeBinaryPackageRelease()
754+ self.assertEqual(
755+ bpr.build.source_package_release.section, bpr.section)
756+
757+ def test_makeBinaryPackageRelease_uses_shlibdeps(self):
758+ bpr = self.factory.makeBinaryPackageRelease(shlibdeps="foo bar")
759+ self.assertEqual("foo bar", bpr.shlibdeps)
760+
761+ def test_makeBinaryPackageRelease_allows_None_shlibdeps(self):
762+ bpr = self.factory.makeBinaryPackageRelease(shlibdeps=None)
763+ self.assertEqual(None, bpr.shlibdeps)
764+
765+ def test_makeBinaryPackageRelease_uses_depends(self):
766+ bpr = self.factory.makeBinaryPackageRelease(depends="apt | bzr")
767+ self.assertEqual("apt | bzr", bpr.depends)
768+
769+ def test_makeBinaryPackageRelease_allows_None_depends(self):
770+ bpr = self.factory.makeBinaryPackageRelease(depends=None)
771+ self.assertEqual(None, bpr.depends)
772+
773+ def test_makeBinaryPackageRelease_uses_recommends(self):
774+ bpr = self.factory.makeBinaryPackageRelease(recommends="ssss")
775+ self.assertEqual("ssss", bpr.recommends)
776+
777+ def test_makeBinaryPackageRelease_allows_None_recommends(self):
778+ bpr = self.factory.makeBinaryPackageRelease(recommends=None)
779+ self.assertEqual(None, bpr.recommends)
780+
781+ def test_makeBinaryPackageRelease_uses_suggests(self):
782+ bpr = self.factory.makeBinaryPackageRelease(suggests="ssss")
783+ self.assertEqual("ssss", bpr.suggests)
784+
785+ def test_makeBinaryPackageRelease_allows_None_suggests(self):
786+ bpr = self.factory.makeBinaryPackageRelease(suggests=None)
787+ self.assertEqual(None, bpr.suggests)
788+
789+ def test_makeBinaryPackageRelease_uses_conflicts(self):
790+ bpr = self.factory.makeBinaryPackageRelease(conflicts="ssss")
791+ self.assertEqual("ssss", bpr.conflicts)
792+
793+ def test_makeBinaryPackageRelease_allows_None_conflicts(self):
794+ bpr = self.factory.makeBinaryPackageRelease(conflicts=None)
795+ self.assertEqual(None, bpr.conflicts)
796+
797+ def test_makeBinaryPackageRelease_uses_replaces(self):
798+ bpr = self.factory.makeBinaryPackageRelease(replaces="ssss")
799+ self.assertEqual("ssss", bpr.replaces)
800+
801+ def test_makeBinaryPackageRelease_allows_None_replaces(self):
802+ bpr = self.factory.makeBinaryPackageRelease(replaces=None)
803+ self.assertEqual(None, bpr.replaces)
804+
805+ def test_makeBinaryPackageRelease_uses_provides(self):
806+ bpr = self.factory.makeBinaryPackageRelease(provides="ssss")
807+ self.assertEqual("ssss", bpr.provides)
808+
809+ def test_makeBinaryPackageRelease_allows_None_provides(self):
810+ bpr = self.factory.makeBinaryPackageRelease(provides=None)
811+ self.assertEqual(None, bpr.provides)
812+
813+ def test_makeBinaryPackageRelease_uses_pre_depends(self):
814+ bpr = self.factory.makeBinaryPackageRelease(pre_depends="ssss")
815+ self.assertEqual("ssss", bpr.pre_depends)
816+
817+ def test_makeBinaryPackageRelease_allows_None_pre_depends(self):
818+ bpr = self.factory.makeBinaryPackageRelease(pre_depends=None)
819+ self.assertEqual(None, bpr.pre_depends)
820+
821+ def test_makeBinaryPackageRelease_uses_enhances(self):
822+ bpr = self.factory.makeBinaryPackageRelease(enhances="ssss")
823+ self.assertEqual("ssss", bpr.enhances)
824+
825+ def test_makeBinaryPackageRelease_allows_None_enhances(self):
826+ bpr = self.factory.makeBinaryPackageRelease(enhances=None)
827+ self.assertEqual(None, bpr.enhances)
828+
829+ def test_makeBinaryPackageRelease_uses_breaks(self):
830+ bpr = self.factory.makeBinaryPackageRelease(breaks="ssss")
831+ self.assertEqual("ssss", bpr.breaks)
832+
833+ def test_makeBinaryPackageRelease_allows_None_breaks(self):
834+ bpr = self.factory.makeBinaryPackageRelease(breaks=None)
835+ self.assertEqual(None, bpr.breaks)
836+
837+ def test_makeBinaryPackageRelease_uses_essential(self):
838+ bpr = self.factory.makeBinaryPackageRelease(essential=True)
839+ self.assertEqual(True, bpr.essential)
840+ bpr = self.factory.makeBinaryPackageRelease(essential=False)
841+ self.assertEqual(False, bpr.essential)
842+
843+ def test_makeBinaryPackageRelease_uses_installed_size(self):
844+ bpr = self.factory.makeBinaryPackageRelease(installed_size=110)
845+ self.assertEqual(110, bpr.installedsize)
846+
847+ def test_makeBinaryPackageName_uses_date_created(self):
848+ date_created = datetime(2000, 01, 01, tzinfo=pytz.UTC)
849+ bpr = self.factory.makeBinaryPackageRelease(
850+ date_created=date_created)
851+ self.assertEqual(date_created, bpr.datecreated)
852+
853+ def test_makeBinaryPackageName_uses_debug_package(self):
854+ debug_package = self.factory.makeBinaryPackageRelease(
855+ binpackageformat=BinaryPackageFormat.DDEB)
856+ bpr = self.factory.makeBinaryPackageRelease(
857+ debug_package=debug_package)
858+ self.assertEqual(debug_package, bpr.debug_package)
859+
860+ def test_makeBinaryPackageName_allows_None_debug_package(self):
861+ bpr = self.factory.makeBinaryPackageRelease(debug_package=None)
862+ self.assertEqual(None, bpr.debug_package)
863+
864+ # makeBranch
865+ def test_makeBranch_initialMirrorRequest(self):
866+ # The default 'next_mirror_time' for a newly created hosted branch
867+ # should be None.
868+ branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED)
869+ self.assertIs(None, branch.next_mirror_time)
870+
871 # makeCodeImport
872 def test_makeCodeImportNoStatus(self):
873 # If makeCodeImport is not given a review status, it defaults to NEW.
874@@ -135,6 +321,52 @@
875 code_import = self.factory.makeCodeImport(review_status=status)
876 self.assertEqual(status, code_import.review_status)
877
878+ # makeDistribution
879+ def test_makeDistribution_returns_IDistribution(self):
880+ distribution = self.factory.makeDistribution()
881+ self.assertThat(
882+ removeSecurityProxy(distribution), Provides(IDistribution))
883+
884+ def test_makeDistribution_returns_proxy(self):
885+ distribution = self.factory.makeDistribution()
886+ self.assertThat(distribution, IsProxied())
887+
888+ def test_makeDistribution_created_name_starts_with_distribution(self):
889+ distribution = self.factory.makeDistribution()
890+ self.assertThat(distribution.name, StartsWith("distribution"))
891+
892+ def test_makeDistribution_created_display_name_starts_Distribution(self):
893+ distribution = self.factory.makeDistribution()
894+ self.assertThat(distribution.displayname, StartsWith("Distribution"))
895+
896+ # makeDistroRelease
897+ def test_makeDistroRelease_returns_IDistroSeries(self):
898+ distroseries = self.factory.makeDistroRelease()
899+ self.assertThat(
900+ removeSecurityProxy(distroseries), Provides(IDistroSeries))
901+
902+ def test_makeDistroRelease_returns_proxy(self):
903+ distroseries = self.factory.makeDistroRelease()
904+ self.assertThat(distroseries, IsProxied())
905+
906+ # makeDistroSeries
907+ def test_makeDistroSeries_returns_IDistroSeries(self):
908+ distroseries = self.factory.makeDistroSeries()
909+ self.assertThat(
910+ removeSecurityProxy(distroseries), Provides(IDistroSeries))
911+
912+ def test_makeDistroSeries_returns_proxy(self):
913+ distroseries = self.factory.makeDistroSeries()
914+ self.assertThat(distroseries, IsProxied())
915+
916+ def test_makeDistroSeries_created_name_starts_with_distroseries(self):
917+ distroseries = self.factory.makeDistroSeries()
918+ self.assertThat(distroseries.name, StartsWith("distroseries"))
919+
920+ def test_makeDistroSeries_created_display_name_starts_Distroseries(self):
921+ distroseries = self.factory.makeDistroSeries()
922+ self.assertThat(distroseries.displayname, StartsWith("Distroseries"))
923+
924 # makeLanguage
925 def test_makeLanguage(self):
926 # Without parameters, makeLanguage creates a language with code
927@@ -205,6 +437,27 @@
928 scheduleddeletiondate=scheduleddeletiondate)
929 self.assertEquals(scheduleddeletiondate, spph.scheduleddeletiondate)
930
931+ def test_makeSourcePackagePublishingHistory_datepublished_PENDING(self):
932+ spph = self.factory.makeSourcePackagePublishingHistory(
933+ status=PackagePublishingStatus.PENDING)
934+ self.assertEquals(None, spph.datepublished)
935+
936+ def test_makeSourcePackagePublishingHistory_datepublished_PUBLISHED(self):
937+ spph = self.factory.makeSourcePackagePublishingHistory(
938+ status=PackagePublishingStatus.PUBLISHED)
939+ self.assertNotEqual(None, spph.datepublished)
940+
941+ # makeSourcePackageRelease
942+ def test_makeSourcePackageRelease_returns_proxied_ISPR(self):
943+ spr = self.factory.makeSourcePackageRelease()
944+ self.assertThat(spr, ProvidesAndIsProxied(ISourcePackageRelease))
945+
946+ def test_makeSourcePackageRelease_uses_dsc_maintainer_rfc822(self):
947+ maintainer = "James Westby <james.westby@canonical.com>"
948+ spr = self.factory.makeSourcePackageRelease(
949+ dsc_maintainer_rfc822=maintainer)
950+ self.assertEqual(maintainer, spr.dsc_maintainer_rfc822)
951+
952 # makeSuiteSourcePackage
953 def test_makeSuiteSourcePackage_returns_ISuiteSourcePackage(self):
954 ssp = self.factory.makeSuiteSourcePackage()
955@@ -240,6 +493,59 @@
956 filetype=BinaryPackageFileType.DDEB)
957 self.assertEqual(BinaryPackageFileType.DDEB, bpf.filetype)
958
959+ # makePackageUpload
960+ def test_makePackageUpload_returns_proxied_IPackageUpload(self):
961+ pu = self.factory.makePackageUpload()
962+ self.assertThat(pu, ProvidesAndIsProxied(IPackageUpload))
963+
964+ def test_makePackageUpload_uses_distroseries(self):
965+ distroseries = self.factory.makeDistroSeries()
966+ pu = self.factory.makePackageUpload(distroseries=distroseries)
967+ self.assertEqual(distroseries, pu.distroseries)
968+
969+ def test_makePackageUpload_uses_archive(self):
970+ archive = self.factory.makeArchive()
971+ pu = self.factory.makePackageUpload(archive=archive)
972+ self.assertEqual(archive, pu.archive)
973+
974+ def test_makePackageUpload_uses_distribution_of_archive(self):
975+ archive = self.factory.makeArchive()
976+ pu = self.factory.makePackageUpload(archive=archive)
977+ self.assertEqual(archive.distribution, pu.distroseries.distribution)
978+
979+ def test_makePackageUpload_uses_changes_filename(self):
980+ changes_filename = "foo"
981+ pu = self.factory.makePackageUpload(changes_filename=changes_filename)
982+ self.assertEqual(
983+ changes_filename, removeSecurityProxy(pu).changesfile.filename)
984+
985+ def test_makePackageUpload_uses_pocket(self):
986+ pu = self.factory.makePackageUpload(
987+ pocket=PackagePublishingPocket.RELEASE)
988+ self.assertEqual(PackagePublishingPocket.RELEASE, pu.pocket)
989+ pu = self.factory.makePackageUpload(
990+ pocket=PackagePublishingPocket.PROPOSED)
991+ self.assertEqual(PackagePublishingPocket.PROPOSED, pu.pocket)
992+
993+ def test_makePackageUpload_uses_signing_key(self):
994+ person = self.factory.makePerson()
995+ signing_key = self.factory.makeGPGKey(person)
996+ pu = self.factory.makePackageUpload(signing_key=signing_key)
997+ self.assertEqual(signing_key, pu.signing_key)
998+
999+ def test_makePackageUpload_allows_None_signing_key(self):
1000+ pu = self.factory.makePackageUpload(signing_key=None)
1001+ self.assertEqual(None, pu.signing_key)
1002+
1003+ def test_makePackageUpload_sets_status_DONE(self):
1004+ pu = self.factory.makePackageUpload(status=PackageUploadStatus.DONE)
1005+ self.assertEqual(PackageUploadStatus.DONE, pu.status)
1006+
1007+ def test_makePackageUpload_sets_status_ACCEPTED(self):
1008+ pu = self.factory.makePackageUpload(
1009+ status=PackageUploadStatus.ACCEPTED)
1010+ self.assertEqual(PackageUploadStatus.ACCEPTED, pu.status)
1011+
1012 # makeSourcePackageReleaseFile
1013 def test_makeSourcePackageReleaseFile_returns_ISPRF(self):
1014 spr_file = self.factory.makeSourcePackageReleaseFile()
1015
1016=== modified file 'lib/lp/testing/tests/test_matchers.py'
1017--- lib/lp/testing/tests/test_matchers.py 2010-08-05 09:57:43 +0000
1018+++ lib/lp/testing/tests/test_matchers.py 2010-08-16 21:55:59 +0000
1019@@ -11,8 +11,8 @@
1020
1021 from lp.testing import TestCase
1022 from lp.testing.matchers import (
1023- DoesNotCorrectlyProvide, DoesNotProvide, HasQueryCount, IsNotProxied,
1024- IsProxied, Provides, ProvidesAndIsProxied)
1025+ DoesNotCorrectlyProvide, DoesNotProvide, DoesNotStartWith, HasQueryCount,
1026+ IsNotProxied, IsProxied, Provides, ProvidesAndIsProxied, StartsWith)
1027 from lp.testing._webservice import QueryCollector
1028
1029 from testtools.matchers import Is, Not, LessThan
1030@@ -92,8 +92,10 @@
1031 self.assertEqual(ITestInterface, mismatch.interface)
1032
1033 def match_does_not_verify(self):
1034+
1035 class BadlyImplementedClass:
1036 implements(ITestInterface)
1037+
1038 obj = BadlyImplementedClass()
1039 matcher = Provides(ITestInterface)
1040 return obj, matcher.match(obj)
1041@@ -158,7 +160,7 @@
1042
1043 def test_match(self):
1044 obj = ProxyFactory(
1045- Implementor(), checker=NamesChecker(names=("doFoo",)))
1046+ Implementor(), checker=NamesChecker(names=("doFoo", )))
1047 matcher = ProvidesAndIsProxied(ITestInterface)
1048 self.assertThat(obj, matcher)
1049 self.assertEqual(None, matcher.match(obj))
1050@@ -185,7 +187,7 @@
1051 def test_match(self):
1052 matcher = HasQueryCount(Is(3))
1053 collector = QueryCollector()
1054- collector.count = 3
1055+ collector.count = 3
1056 # not inspected
1057 del collector.queries
1058 self.assertThat(matcher.match(collector), Is(None))
1059@@ -210,3 +212,34 @@
1060 mismatch.describe())
1061
1062
1063+class DoesNotStartWithTests(TestCase):
1064+
1065+ def test_describe(self):
1066+ mismatch = DoesNotStartWith("foo", "bar")
1067+ self.assertEqual(
1068+ "'foo' does not start with 'bar'.", mismatch.describe())
1069+
1070+
1071+class StartsWithTests(TestCase):
1072+
1073+ def test_str(self):
1074+ matcher = StartsWith("bar")
1075+ self.assertEqual("Starts with 'bar'.", str(matcher))
1076+
1077+ def test_match(self):
1078+ matcher = StartsWith("bar")
1079+ self.assertIs(None, matcher.match("barf"))
1080+
1081+ def test_mismatch_returns_does_not_start_with(self):
1082+ matcher = StartsWith("bar")
1083+ self.assertIsInstance(matcher.match("foo"), DoesNotStartWith)
1084+
1085+ def test_mismatch_sets_matchee(self):
1086+ matcher = StartsWith("bar")
1087+ mismatch = matcher.match("foo")
1088+ self.assertEqual("foo", mismatch.matchee)
1089+
1090+ def test_mismatch_sets_expected(self):
1091+ matcher = StartsWith("bar")
1092+ mismatch = matcher.match("foo")
1093+ self.assertEqual("bar", mismatch.expected)