Merge lp:~jelmer/launchpad/nascentuploadfile-tests into lp:launchpad

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 11400
Proposed branch: lp:~jelmer/launchpad/nascentuploadfile-tests
Merge into: lp:launchpad
Diff against target: 493 lines (+395/-13)
5 files modified
lib/lp/archiveuploader/changesfile.py (+11/-3)
lib/lp/archiveuploader/dscfile.py (+1/-0)
lib/lp/archiveuploader/nascentuploadfile.py (+6/-4)
lib/lp/archiveuploader/tests/test_changesfile.py (+134/-6)
lib/lp/archiveuploader/tests/test_nascentuploadfile.py (+243/-0)
To merge this branch: bzr merge lp:~jelmer/launchpad/nascentuploadfile-tests
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+32874@code.launchpad.net

Commit message

Add more tests for ChangesFile, DebBinaryUploadFile, DSCFile, CustomUploadFile in the archiveuploader. Make Changed-By and Date field mandatory in ChangesFile.

Description of the change

This branch adds a bunch of tests and testinfrastructure for ChangesFile, DSCFile and two of the classes in nascentuploadfile. I'm adding these tests in preparation of adding some more fields (bug 613468).

While writing the tests I noticed that we seem to unconditionally require the "Changed-By" and "Date" files in the Changes file but don't reject uploads with these fields, so I've added them to the list of mandatory fields (bug filed & linked).

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :
Download full text (18.3 KiB)

Hi Jelmer,

Thanks for adding tests; always a good thing.

This is a good branch, but it suffers from a lot of issues w.r.t our
coding standards. All of the tests should have a leading comment
explaining the behaviour that they test. Also, the formatting of
callsites is inconsistent and should be changed to match our standards.

> === modified file 'lib/lp/archiveuploader/changesfile.py'
> --- lib/lp/archiveuploader/changesfile.py 2010-08-01 06:59:04 +0000
> +++ lib/lp/archiveuploader/changesfile.py 2010-08-17 13:21:05 +0000
> @@ -148,7 +152,7 @@
> def isCustom(self, component_and_section):
> """Check if given 'component_and_section' matches a custom upload.
>
> - We recognize an upload as custom if it is taget to a section like
> + We recognize an upload as custom if it is targetted at a section like

Targeted has only two 't's.

> 'raw-<something>'.
> Further checks will be performed in CustomUploadFile class.
> """
> @@ -215,6 +219,10 @@
> if len(self.files) == 0:
> yield UploadError("No files found in the changes")
>
> + if not 'urgency' in self._dict:

This should be expressed as:

    if 'urgency' not in self._dict:

The current condition confused me.

> + # Urgency is recommended but not mandatory. Default to 'low'
> + self._dict['urgency'] = "low"
> +
> raw_urgency = self._dict['urgency'].lower()
> if raw_urgency not in self.urgency_map:
> yield UploadWarning(
>
> === modified file 'lib/lp/archiveuploader/tests/test_changesfile.py'
> --- lib/lp/archiveuploader/tests/test_changesfile.py 2010-08-01 06:59:04 +0000
> +++ lib/lp/archiveuploader/tests/test_changesfile.py 2010-08-17 13:21:05 +0000
> @@ -5,14 +5,20 @@
>
> __metaclass__ = type
>
> -from testtools import TestCase
> +from debian.deb822 import Changes
> +import os
> +
> +from canonical.launchpad.scripts.logger import BufferLogger
> +from canonical.testing import LaunchpadZopelessLayer
>
> from lp.archiveuploader.changesfile import (CannotDetermineFileTypeError,
> - determine_file_class_and_name)
> + ChangesFile, determine_file_class_and_name)

Since you're here, you can tidy this up into the new one-line-per-import
format.

> from lp.archiveuploader.dscfile import DSCFile
> from lp.archiveuploader.nascentuploadfile import (
> DebBinaryUploadFile, DdebBinaryUploadFile, SourceUploadFile,
> - UdebBinaryUploadFile)
> + UdebBinaryUploadFile, UploadError)

Same here.

> +from lp.archiveuploader.uploadpolicy import AbsolutelyAnythingGoesUploadPolicy
> +from lp.testing import TestCase
>
>
> class TestDetermineFileClassAndName(TestCase):
> @@ -52,3 +58,104 @@
> CannotDetermineFileTypeError,
> determine_file_class_and_name,
> 'foo')
> +
> +
> +class ChangesFileTests(TestCase):
> + """Tests for ChangesFile."""
> +
> + layer = LaunchpadZopelessLayer
> +
> + def setUp(self):
> + super(ChangesFileTests, self).setUp()
> + self.logger = BufferLogger()
> + self.policy = AbsolutelyAnythingGoesUploadPolicy()
> +
> + def createChangesFile(self, filename, cha...

review: Needs Fixing (code)
Revision history for this message
Graham Binns (gmb) wrote :

Hi Jelmer,

Thanks for those changes. Everything looks good, but you need to change the comments you've added to the start of the tests from the "Test that.." form to a straight statement of the expected behaviour.

So, instead of " # Test that unknown priorities automatically get changed to 'extra'," the comment should read " # Unknown priorities automatically get changed to 'extra'." This is a carry-over from doctest land, but being able to glance at a comment and know that foo should do bar rather than having to parse out the 'test that...' is nice. We know it's testing something because the method name starts with test_.

Other than that, this branch is good to land, so I'll mark it approved. No need to ping me about any subsequent changes unless they're not in-scope for this review.

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/archiveuploader/changesfile.py'
2--- lib/lp/archiveuploader/changesfile.py 2010-08-01 06:59:04 +0000
3+++ lib/lp/archiveuploader/changesfile.py 2010-08-19 15:51:44 +0000
4@@ -41,7 +41,11 @@
5
6 mandatory_fields = set([
7 "source", "binary", "architecture", "version", "distribution",
8- "maintainer", "files", "changes"])
9+ "maintainer", "files", "changes", "date",
10+ # Changed-By is not technically mandatory according to
11+ # Debian policy but Soyuz relies on it being set in
12+ # various places.
13+ "changed-by"])
14
15 # Map urgencies to their dbschema values.
16 # Debian policy only permits low, medium, high, emergency.
17@@ -148,7 +152,7 @@
18 def isCustom(self, component_and_section):
19 """Check if given 'component_and_section' matches a custom upload.
20
21- We recognize an upload as custom if it is taget to a section like
22+ We recognize an upload as custom if it is targeted at a section like
23 'raw-<something>'.
24 Further checks will be performed in CustomUploadFile class.
25 """
26@@ -215,6 +219,10 @@
27 if len(self.files) == 0:
28 yield UploadError("No files found in the changes")
29
30+ if 'urgency' not in self._dict:
31+ # Urgency is recommended but not mandatory. Default to 'low'
32+ self._dict['urgency'] = "low"
33+
34 raw_urgency = self._dict['urgency'].lower()
35 if raw_urgency not in self.urgency_map:
36 yield UploadWarning(
37@@ -321,7 +329,7 @@
38
39 @property
40 def source(self):
41- """Return changesfiel claimed source name"""
42+ """Return changesfile claimed source name."""
43 return self._dict['source']
44
45 @property
46
47=== modified file 'lib/lp/archiveuploader/dscfile.py'
48--- lib/lp/archiveuploader/dscfile.py 2010-08-03 08:49:19 +0000
49+++ lib/lp/archiveuploader/dscfile.py 2010-08-19 15:51:44 +0000
50@@ -740,6 +740,7 @@
51 logger.debug("Copying copyright contents.")
52 dsc_file.copyright = open(copyright_file).read().strip()
53
54+
55 def findChangelog(dsc_file, source_dir, logger):
56 """Find and move any debian/changelog.
57
58
59=== modified file 'lib/lp/archiveuploader/nascentuploadfile.py'
60--- lib/lp/archiveuploader/nascentuploadfile.py 2010-07-21 11:13:19 +0000
61+++ lib/lp/archiveuploader/nascentuploadfile.py 2010-08-19 15:51:44 +0000
62@@ -321,7 +321,6 @@
63 "%s: Unknown component %r" % (
64 self.filename, self.component_name))
65
66-
67 @property
68 def component(self):
69 """Return an IComponent for self.component.name."""
70@@ -492,12 +491,15 @@
71 yield UploadError(
72 "%s: control file lacks mandatory field %r"
73 % (self.filename, mandatory_field))
74+ control = {}
75+ for key in control_lines.keys():
76+ control[key] = control_lines.Find(key)
77+ self.parseControl(control)
78
79+ def parseControl(self, control):
80 # XXX kiko 2007-02-15: We never use the Maintainer information in
81 # the control file for anything. Should we? --
82- self.control = {}
83- for key in control_lines.keys():
84- self.control[key] = control_lines.Find(key)
85+ self.control = control
86
87 control_source = self.control.get("Source", None)
88 if control_source is not None:
89
90=== modified file 'lib/lp/archiveuploader/tests/test_changesfile.py'
91--- lib/lp/archiveuploader/tests/test_changesfile.py 2010-08-01 06:59:04 +0000
92+++ lib/lp/archiveuploader/tests/test_changesfile.py 2010-08-19 15:51:44 +0000
93@@ -5,14 +5,27 @@
94
95 __metaclass__ = type
96
97-from testtools import TestCase
98-
99-from lp.archiveuploader.changesfile import (CannotDetermineFileTypeError,
100- determine_file_class_and_name)
101+from debian.deb822 import Changes
102+import os
103+
104+from canonical.launchpad.scripts.logger import BufferLogger
105+from canonical.testing import LaunchpadZopelessLayer
106+
107+from lp.archiveuploader.changesfile import (
108+ CannotDetermineFileTypeError,
109+ ChangesFile,
110+ determine_file_class_and_name,
111+ )
112 from lp.archiveuploader.dscfile import DSCFile
113 from lp.archiveuploader.nascentuploadfile import (
114- DebBinaryUploadFile, DdebBinaryUploadFile, SourceUploadFile,
115- UdebBinaryUploadFile)
116+ DebBinaryUploadFile,
117+ DdebBinaryUploadFile,
118+ SourceUploadFile,
119+ UdebBinaryUploadFile,
120+ UploadError,
121+ )
122+from lp.archiveuploader.tests import AbsolutelyAnythingGoesUploadPolicy
123+from lp.testing import TestCase
124
125
126 class TestDetermineFileClassAndName(TestCase):
127@@ -52,3 +65,118 @@
128 CannotDetermineFileTypeError,
129 determine_file_class_and_name,
130 'foo')
131+
132+
133+class ChangesFileTests(TestCase):
134+ """Tests for ChangesFile."""
135+
136+ layer = LaunchpadZopelessLayer
137+
138+ def setUp(self):
139+ super(ChangesFileTests, self).setUp()
140+ self.logger = BufferLogger()
141+ self.policy = AbsolutelyAnythingGoesUploadPolicy()
142+
143+ def createChangesFile(self, filename, changes):
144+ tempdir = self.makeTemporaryDirectory()
145+ path = os.path.join(tempdir, filename)
146+ changes_fd = open(path, "w")
147+ try:
148+ changes.dump(changes_fd)
149+ finally:
150+ changes_fd.close()
151+ return ChangesFile(path, self.policy, self.logger)
152+
153+ def getBaseChanges(self):
154+ contents = Changes()
155+ contents["Source"] = "mypkg"
156+ contents["Binary"] = "binary"
157+ contents["Date"] = "Fri, 25 Jun 2010 11:20:22 -0600"
158+ contents["Architecture"] = "i386"
159+ contents["Version"] = "0.1"
160+ contents["Distribution"] = "nifty"
161+ contents["Maintainer"] = "Somebody"
162+ contents["Changes"] = "Something changed"
163+ contents["Description"] = "\n An awesome package."
164+ contents["Changed-By"] = "Somebody <somebody@ubuntu.com>"
165+ contents["Files"] = [{
166+ "md5sum": "d2bd347b3fed184fe28e112695be491c",
167+ "size": "1791",
168+ "section": "python",
169+ "priority": "optional",
170+ "name": "dulwich_0.4.1-1.dsc"}]
171+ return contents
172+
173+ def test_checkFileName(self):
174+ # checkFileName() yields an UploadError if the filename is invalid.
175+ contents = self.getBaseChanges()
176+ changes = self.createChangesFile("mypkg_0.1_i386.changes", contents)
177+ self.assertEquals([], list(changes.checkFileName()))
178+ changes = self.createChangesFile("mypkg_0.1.changes", contents)
179+ errors = list(changes.checkFileName())
180+ self.assertIsInstance(errors[0], UploadError)
181+ self.assertEquals(1, len(errors))
182+
183+ def test_filename(self):
184+ # Filename gets set to the basename of the changes file on disk.
185+ changes = self.createChangesFile(
186+ "mypkg_0.1_i386.changes", self.getBaseChanges())
187+ self.assertEquals("mypkg_0.1_i386.changes", changes.filename)
188+
189+ def test_suite_name(self):
190+ # The suite name gets extracted from the changes file.
191+ changes = self.createChangesFile(
192+ "mypkg_0.1_i386.changes", self.getBaseChanges())
193+ self.assertEquals("nifty", changes.suite_name)
194+
195+ def test_version(self):
196+ # The version gets extracted from the changes file.
197+ changes = self.createChangesFile(
198+ "mypkg_0.1_i386.changes", self.getBaseChanges())
199+ self.assertEquals("0.1", changes.version)
200+
201+ def test_architectures(self):
202+ # The architectures get extracted from the changes file
203+ # and parsed correctly.
204+ changes = self.createChangesFile(
205+ "mypkg_0.1_i386.changes", self.getBaseChanges())
206+ self.assertEquals("i386", changes.architecture_line)
207+ self.assertEquals(set(["i386"]), changes.architectures)
208+
209+ def test_source(self):
210+ # The source package name gets extracted from the changes file.
211+ changes = self.createChangesFile(
212+ "mypkg_0.1_i386.changes", self.getBaseChanges())
213+ self.assertEquals("mypkg", changes.source)
214+
215+ def test_processAddresses(self):
216+ # processAddresses parses the changes file and sets the
217+ # changed_by field.
218+ contents = self.getBaseChanges()
219+ changes = self.createChangesFile(
220+ "mypkg_0.1_i386.changes", contents)
221+ self.assertEquals(None, changes.changed_by)
222+ errors = list(changes.processAddresses())
223+ self.assertEquals(0, len(errors), "Errors: %r" % errors)
224+ self.assertEquals(
225+ "Somebody <somebody@ubuntu.com>", changes.changed_by['rfc822'])
226+
227+ def test_simulated_changelog(self):
228+ # The simulated_changelog property returns a changelog entry based on
229+ # the control fields.
230+ contents = self.getBaseChanges()
231+ changes = self.createChangesFile(
232+ "mypkg_0.1_i386.changes", contents)
233+ self.assertEquals([], list(changes.processAddresses()))
234+ self.assertEquals(
235+ "Something changed\n"
236+ " -- Somebody <somebody@ubuntu.com> Fri, 25 Jun 2010 11:20:22 -0600",
237+ changes.simulated_changelog)
238+
239+ def test_requires_changed_by(self):
240+ # A changes file is rejected if it does not have a Changed-By field.
241+ contents = self.getBaseChanges()
242+ del contents["Changed-By"]
243+ self.assertRaises(
244+ UploadError,
245+ self.createChangesFile, "mypkg_0.1_i386.changes", contents)
246
247=== added file 'lib/lp/archiveuploader/tests/test_nascentuploadfile.py'
248--- lib/lp/archiveuploader/tests/test_nascentuploadfile.py 1970-01-01 00:00:00 +0000
249+++ lib/lp/archiveuploader/tests/test_nascentuploadfile.py 2010-08-19 15:51:44 +0000
250@@ -0,0 +1,243 @@
251+# Copyright 2010 Canonical Ltd. This software is licensed under the
252+# GNU Affero General Public License version 3 (see the file LICENSE).
253+
254+"""Test NascentUploadFile functionality."""
255+
256+__metaclass__ = type
257+
258+from debian.deb822 import Changes, Dsc
259+import hashlib
260+import os
261+
262+from canonical.launchpad.scripts.logger import BufferLogger
263+from canonical.testing import LaunchpadZopelessLayer
264+
265+from lp.archiveuploader.changesfile import ChangesFile
266+from lp.archiveuploader.dscfile import DSCFile
267+from lp.archiveuploader.nascentuploadfile import (
268+ CustomUploadFile,
269+ DebBinaryUploadFile,
270+ )
271+from lp.archiveuploader.tests import AbsolutelyAnythingGoesUploadPolicy
272+from lp.soyuz.interfaces.queue import PackageUploadCustomFormat
273+from lp.testing import TestCaseWithFactory
274+
275+
276+class NascentUploadFileTestCase(TestCaseWithFactory):
277+ """Base class for all tests of classes deriving from NascentUploadFile."""
278+
279+ def setUp(self):
280+ super(NascentUploadFileTestCase, self).setUp()
281+ self.logger = BufferLogger()
282+ self.policy = AbsolutelyAnythingGoesUploadPolicy()
283+ self.distro = self.factory.makeDistribution()
284+ self.policy.archive = self.factory.makeArchive(
285+ distribution=self.distro)
286+
287+ def writeUploadFile(self, filename, contents):
288+ """Write a temporary file but with a specific filename.
289+
290+ :param filename: Filename to use
291+ :param contents: Contents of the file
292+ :return: Tuple with path, digest and size
293+ """
294+ path = os.path.join(self.makeTemporaryDirectory(), filename)
295+ f = open(path, 'w')
296+ try:
297+ f.write(contents)
298+ finally:
299+ f.close()
300+ return (path, hashlib.sha1(contents), len(contents))
301+
302+
303+class CustomUploadFileTests(NascentUploadFileTestCase):
304+ """Tests for CustomUploadFile."""
305+
306+ layer = LaunchpadZopelessLayer
307+
308+ def createCustomUploadFile(self, filename, contents,
309+ component_and_section, priority_name):
310+ """Simple wrapper to create a CustomUploadFile."""
311+ (path, digest, size) = self.writeUploadFile(filename, contents)
312+ uploadfile = CustomUploadFile(
313+ path, digest, size, component_and_section, priority_name,
314+ self.policy, self.logger)
315+ return uploadfile
316+
317+ def test_custom_type(self):
318+ # The mime type gets set according to PackageUploadCustomFormat.
319+ uploadfile = self.createCustomUploadFile(
320+ "bla.txt", "data", "main/raw-installer", "extra")
321+ self.assertEquals(
322+ PackageUploadCustomFormat.DEBIAN_INSTALLER,
323+ uploadfile.custom_type)
324+
325+ def test_storeInDatabase(self):
326+ # storeInDatabase creates a library file.
327+ uploadfile = self.createCustomUploadFile(
328+ "bla.txt", "data", "main/raw-installer", "extra")
329+ self.assertEquals("application/octet-stream", uploadfile.content_type)
330+ libraryfile = uploadfile.storeInDatabase()
331+ self.assertEquals("bla.txt", libraryfile.filename)
332+ self.assertEquals("application/octet-stream", libraryfile.mimetype)
333+
334+
335+class PackageUploadFileTestCase(NascentUploadFileTestCase):
336+ """Base class for all tests of classes deriving from PackageUploadFile."""
337+
338+ def setUp(self):
339+ super(PackageUploadFileTestCase, self).setUp()
340+ self.policy.distroseries = self.factory.makeDistroSeries(
341+ distribution=self.distro)
342+
343+ def getBaseChanges(self):
344+ contents = Changes()
345+ contents["Source"] = "mypkg"
346+ contents["Binary"] = "binary"
347+ contents["Architecture"] = "i386"
348+ contents["Version"] = "0.1"
349+ contents["Distribution"] = "nifty"
350+ contents["Description"] = "\n Foo"
351+ contents["Maintainer"] = "Somebody"
352+ contents["Changes"] = "Something changed"
353+ contents["Date"] = "Fri, 25 Jun 2010 11:20:22 -0600"
354+ contents["Urgency"] = "low"
355+ contents["Changed-By"] = "Seombody Else <somebody@example.com>"
356+ contents["Files"] = [{
357+ "md5sum": "d2bd347b3fed184fe28e112695be491c",
358+ "size": "1791",
359+ "section": "python",
360+ "priority": "optional",
361+ "name": "dulwich_0.4.1-1.dsc"}]
362+ return contents
363+
364+ def createChangesFile(self, filename, changes):
365+ tempdir = self.makeTemporaryDirectory()
366+ path = os.path.join(tempdir, filename)
367+ changes_fd = open(path, "w")
368+ try:
369+ changes.dump(changes_fd)
370+ finally:
371+ changes_fd.close()
372+ return ChangesFile(path, self.policy, self.logger)
373+
374+
375+class DSCFileTests(PackageUploadFileTestCase):
376+ """Tests for DSCFile."""
377+
378+ layer = LaunchpadZopelessLayer
379+
380+ def getBaseDsc(self):
381+ dsc = Dsc()
382+ dsc["Architecture"] = "all"
383+ dsc["Version"] = "0.42"
384+ dsc["Source"] = "dulwich"
385+ dsc["Binary"] = "python-dulwich"
386+ dsc["Standards-Version"] = "0.2.2"
387+ dsc["Maintainer"] = "Jelmer Vernooij <jelmer@ubuntu.com>"
388+ dsc["Files"] = [{
389+ "md5sum": "5e8ba79b4074e2f305ddeaf2543afe83",
390+ "size": "182280",
391+ "name": "dulwich_0.42.tar.gz"}]
392+ return dsc
393+
394+ def createDSCFile(self, filename, dsc, component_and_section,
395+ priority_name, package, version, changes):
396+ (path, digest, size) = self.writeUploadFile(filename, dsc.dump())
397+ if changes:
398+ self.assertEquals([], list(changes.processAddresses()))
399+ return DSCFile(
400+ path, digest, size, component_and_section, priority_name, package,
401+ version, changes, self.policy, self.logger)
402+
403+ def test_filetype(self):
404+ # The filetype attribute is set based on the file extension.
405+ dsc = self.getBaseDsc()
406+ uploadfile = self.createDSCFile(
407+ "foo.dsc", dsc, "main/net", "extra", "dulwich", "0.42", None)
408+ self.assertEquals(
409+ "text/x-debian-source-package", uploadfile.content_type)
410+
411+ def test_storeInDatabase(self):
412+ # storeInDatabase creates a SourcePackageRelease.
413+ dsc = self.getBaseDsc()
414+ dsc["Build-Depends"] = "dpkg, bzr"
415+ changes = self.getBaseChanges()
416+ uploadfile = self.createDSCFile(
417+ "foo.dsc", dsc, "main/net", "extra", "dulwich", "0.42",
418+ self.createChangesFile("foo.changes", changes))
419+ (uploadfile.changelog_path, changelog_digest, changelog_size) = (
420+ self.writeUploadFile("changelog", "DUMMY"))
421+ uploadfile.files = []
422+ release = uploadfile.storeInDatabase(None)
423+ self.assertEquals("0.42", release.version)
424+ self.assertEquals("dpkg, bzr", release.builddepends)
425+
426+
427+class DebBinaryUploadFileTests(PackageUploadFileTestCase):
428+ """Tests for DebBinaryUploadFile."""
429+
430+ layer = LaunchpadZopelessLayer
431+
432+ def getBaseControl(self):
433+ return {
434+ "Package": "python-dulwich",
435+ "Source": "dulwich",
436+ "Version": "0.42",
437+ "Architecture": "i386",
438+ "Maintainer": "Jelmer Vernooij <jelmer@debian.org>",
439+ "Installed-Size": "524",
440+ "Depends": "python (<< 2.7), python (>= 2.5)",
441+ "Provides": "python2.5-dulwich, python2.6-dulwich",
442+ "Section": "python",
443+ "Priority": "optional",
444+ "Homepage": "http://samba.org/~jelmer/dulwich",
445+ "Description": "Pure-python Git library\n"
446+ "Dulwich is a Python implementation of the file formats and "
447+ "protocols"
448+ }
449+
450+ def createDebBinaryUploadFile(self, filename, component_and_section,
451+ priority_name, package, version, changes):
452+ """Create a DebBinaryUploadFile."""
453+ (path, digest, size) = self.writeUploadFile(filename, "DUMMY DATA")
454+ return DebBinaryUploadFile(
455+ path, digest, size, component_and_section, priority_name, package,
456+ version, changes, self.policy, self.logger)
457+
458+ def test_unknown_priority(self):
459+ # Unknown priorities automatically get changed to 'extra'.
460+ uploadfile = self.createDebBinaryUploadFile(
461+ "foo_0.42_i386.deb", "main/net", "unknown", "mypkg", "0.42", None)
462+ self.assertEquals("extra", uploadfile.priority_name)
463+
464+ def test_parseControl(self):
465+ # parseControl sets various fields on DebBinaryUploadFile.
466+ uploadfile = self.createDebBinaryUploadFile(
467+ "foo_0.42_i386.deb", "main/python", "unknown", "mypkg", "0.42",
468+ None)
469+ control = self.getBaseControl()
470+ uploadfile.parseControl(control)
471+ self.assertEquals("python", uploadfile.section_name)
472+ self.assertEquals("dulwich", uploadfile.source_name)
473+ self.assertEquals("0.42", uploadfile.source_version)
474+ self.assertEquals("0.42", uploadfile.control_version)
475+
476+ def test_storeInDatabase(self):
477+ # storeInDatabase creates a BinaryPackageRelease.
478+ uploadfile = self.createDebBinaryUploadFile(
479+ "foo_0.42_i386.deb", "main/python", "unknown", "mypkg", "0.42",
480+ None)
481+ control = self.getBaseControl()
482+ uploadfile.parseControl(control)
483+ build = self.factory.makeBinaryPackageBuild()
484+ bpr = uploadfile.storeInDatabase(build)
485+ self.assertEquals(u'python (<< 2.7), python (>= 2.5)', bpr.depends)
486+ self.assertEquals(
487+ u"Dulwich is a Python implementation of the file formats "
488+ u"and protocols", bpr.description)
489+ self.assertEquals(False, bpr.essential)
490+ self.assertEquals(524, bpr.installedsize)
491+ self.assertEquals(True, bpr.architecturespecific)
492+ self.assertEquals(u"", bpr.recommends)
493+ self.assertEquals("0.42", bpr.version)