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
=== 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-19 15:51:44 +0000
@@ -41,7 +41,11 @@
4141
42 mandatory_fields = set([42 mandatory_fields = set([
43 "source", "binary", "architecture", "version", "distribution",43 "source", "binary", "architecture", "version", "distribution",
44 "maintainer", "files", "changes"])44 "maintainer", "files", "changes", "date",
45 # Changed-By is not technically mandatory according to
46 # Debian policy but Soyuz relies on it being set in
47 # various places.
48 "changed-by"])
4549
46 # Map urgencies to their dbschema values.50 # Map urgencies to their dbschema values.
47 # Debian policy only permits low, medium, high, emergency.51 # Debian policy only permits low, medium, high, emergency.
@@ -148,7 +152,7 @@
148 def isCustom(self, component_and_section):152 def isCustom(self, component_and_section):
149 """Check if given 'component_and_section' matches a custom upload.153 """Check if given 'component_and_section' matches a custom upload.
150154
151 We recognize an upload as custom if it is taget to a section like155 We recognize an upload as custom if it is targeted at a section like
152 'raw-<something>'.156 'raw-<something>'.
153 Further checks will be performed in CustomUploadFile class.157 Further checks will be performed in CustomUploadFile class.
154 """158 """
@@ -215,6 +219,10 @@
215 if len(self.files) == 0:219 if len(self.files) == 0:
216 yield UploadError("No files found in the changes")220 yield UploadError("No files found in the changes")
217221
222 if 'urgency' not in self._dict:
223 # Urgency is recommended but not mandatory. Default to 'low'
224 self._dict['urgency'] = "low"
225
218 raw_urgency = self._dict['urgency'].lower()226 raw_urgency = self._dict['urgency'].lower()
219 if raw_urgency not in self.urgency_map:227 if raw_urgency not in self.urgency_map:
220 yield UploadWarning(228 yield UploadWarning(
@@ -321,7 +329,7 @@
321329
322 @property330 @property
323 def source(self):331 def source(self):
324 """Return changesfiel claimed source name"""332 """Return changesfile claimed source name."""
325 return self._dict['source']333 return self._dict['source']
326334
327 @property335 @property
328336
=== modified file 'lib/lp/archiveuploader/dscfile.py'
--- lib/lp/archiveuploader/dscfile.py 2010-08-03 08:49:19 +0000
+++ lib/lp/archiveuploader/dscfile.py 2010-08-19 15:51:44 +0000
@@ -740,6 +740,7 @@
740 logger.debug("Copying copyright contents.")740 logger.debug("Copying copyright contents.")
741 dsc_file.copyright = open(copyright_file).read().strip()741 dsc_file.copyright = open(copyright_file).read().strip()
742742
743
743def findChangelog(dsc_file, source_dir, logger):744def findChangelog(dsc_file, source_dir, logger):
744 """Find and move any debian/changelog.745 """Find and move any debian/changelog.
745746
746747
=== modified file 'lib/lp/archiveuploader/nascentuploadfile.py'
--- lib/lp/archiveuploader/nascentuploadfile.py 2010-07-21 11:13:19 +0000
+++ lib/lp/archiveuploader/nascentuploadfile.py 2010-08-19 15:51:44 +0000
@@ -321,7 +321,6 @@
321 "%s: Unknown component %r" % (321 "%s: Unknown component %r" % (
322 self.filename, self.component_name))322 self.filename, self.component_name))
323323
324
325 @property324 @property
326 def component(self):325 def component(self):
327 """Return an IComponent for self.component.name."""326 """Return an IComponent for self.component.name."""
@@ -492,12 +491,15 @@
492 yield UploadError(491 yield UploadError(
493 "%s: control file lacks mandatory field %r"492 "%s: control file lacks mandatory field %r"
494 % (self.filename, mandatory_field))493 % (self.filename, mandatory_field))
494 control = {}
495 for key in control_lines.keys():
496 control[key] = control_lines.Find(key)
497 self.parseControl(control)
495498
499 def parseControl(self, control):
496 # XXX kiko 2007-02-15: We never use the Maintainer information in500 # XXX kiko 2007-02-15: We never use the Maintainer information in
497 # the control file for anything. Should we? --501 # the control file for anything. Should we? --
498 self.control = {}502 self.control = control
499 for key in control_lines.keys():
500 self.control[key] = control_lines.Find(key)
501503
502 control_source = self.control.get("Source", None)504 control_source = self.control.get("Source", None)
503 if control_source is not None:505 if control_source is not None:
504506
=== 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-19 15:51:44 +0000
@@ -5,14 +5,27 @@
55
6__metaclass__ = type6__metaclass__ = type
77
8from testtools import TestCase8from debian.deb822 import Changes
99import os
10from lp.archiveuploader.changesfile import (CannotDetermineFileTypeError,10
11 determine_file_class_and_name)11from canonical.launchpad.scripts.logger import BufferLogger
12from canonical.testing import LaunchpadZopelessLayer
13
14from lp.archiveuploader.changesfile import (
15 CannotDetermineFileTypeError,
16 ChangesFile,
17 determine_file_class_and_name,
18 )
12from lp.archiveuploader.dscfile import DSCFile19from lp.archiveuploader.dscfile import DSCFile
13from lp.archiveuploader.nascentuploadfile import (20from lp.archiveuploader.nascentuploadfile import (
14 DebBinaryUploadFile, DdebBinaryUploadFile, SourceUploadFile,21 DebBinaryUploadFile,
15 UdebBinaryUploadFile)22 DdebBinaryUploadFile,
23 SourceUploadFile,
24 UdebBinaryUploadFile,
25 UploadError,
26 )
27from lp.archiveuploader.tests import AbsolutelyAnythingGoesUploadPolicy
28from lp.testing import TestCase
1629
1730
18class TestDetermineFileClassAndName(TestCase):31class TestDetermineFileClassAndName(TestCase):
@@ -52,3 +65,118 @@
52 CannotDetermineFileTypeError,65 CannotDetermineFileTypeError,
53 determine_file_class_and_name,66 determine_file_class_and_name,
54 'foo')67 'foo')
68
69
70class ChangesFileTests(TestCase):
71 """Tests for ChangesFile."""
72
73 layer = LaunchpadZopelessLayer
74
75 def setUp(self):
76 super(ChangesFileTests, self).setUp()
77 self.logger = BufferLogger()
78 self.policy = AbsolutelyAnythingGoesUploadPolicy()
79
80 def createChangesFile(self, filename, changes):
81 tempdir = self.makeTemporaryDirectory()
82 path = os.path.join(tempdir, filename)
83 changes_fd = open(path, "w")
84 try:
85 changes.dump(changes_fd)
86 finally:
87 changes_fd.close()
88 return ChangesFile(path, self.policy, self.logger)
89
90 def getBaseChanges(self):
91 contents = Changes()
92 contents["Source"] = "mypkg"
93 contents["Binary"] = "binary"
94 contents["Date"] = "Fri, 25 Jun 2010 11:20:22 -0600"
95 contents["Architecture"] = "i386"
96 contents["Version"] = "0.1"
97 contents["Distribution"] = "nifty"
98 contents["Maintainer"] = "Somebody"
99 contents["Changes"] = "Something changed"
100 contents["Description"] = "\n An awesome package."
101 contents["Changed-By"] = "Somebody <somebody@ubuntu.com>"
102 contents["Files"] = [{
103 "md5sum": "d2bd347b3fed184fe28e112695be491c",
104 "size": "1791",
105 "section": "python",
106 "priority": "optional",
107 "name": "dulwich_0.4.1-1.dsc"}]
108 return contents
109
110 def test_checkFileName(self):
111 # checkFileName() yields an UploadError if the filename is invalid.
112 contents = self.getBaseChanges()
113 changes = self.createChangesFile("mypkg_0.1_i386.changes", contents)
114 self.assertEquals([], list(changes.checkFileName()))
115 changes = self.createChangesFile("mypkg_0.1.changes", contents)
116 errors = list(changes.checkFileName())
117 self.assertIsInstance(errors[0], UploadError)
118 self.assertEquals(1, len(errors))
119
120 def test_filename(self):
121 # Filename gets set to the basename of the changes file on disk.
122 changes = self.createChangesFile(
123 "mypkg_0.1_i386.changes", self.getBaseChanges())
124 self.assertEquals("mypkg_0.1_i386.changes", changes.filename)
125
126 def test_suite_name(self):
127 # The suite name gets extracted from the changes file.
128 changes = self.createChangesFile(
129 "mypkg_0.1_i386.changes", self.getBaseChanges())
130 self.assertEquals("nifty", changes.suite_name)
131
132 def test_version(self):
133 # The version gets extracted from the changes file.
134 changes = self.createChangesFile(
135 "mypkg_0.1_i386.changes", self.getBaseChanges())
136 self.assertEquals("0.1", changes.version)
137
138 def test_architectures(self):
139 # The architectures get extracted from the changes file
140 # and parsed correctly.
141 changes = self.createChangesFile(
142 "mypkg_0.1_i386.changes", self.getBaseChanges())
143 self.assertEquals("i386", changes.architecture_line)
144 self.assertEquals(set(["i386"]), changes.architectures)
145
146 def test_source(self):
147 # The source package name gets extracted from the changes file.
148 changes = self.createChangesFile(
149 "mypkg_0.1_i386.changes", self.getBaseChanges())
150 self.assertEquals("mypkg", changes.source)
151
152 def test_processAddresses(self):
153 # processAddresses parses the changes file and sets the
154 # changed_by field.
155 contents = self.getBaseChanges()
156 changes = self.createChangesFile(
157 "mypkg_0.1_i386.changes", contents)
158 self.assertEquals(None, changes.changed_by)
159 errors = list(changes.processAddresses())
160 self.assertEquals(0, len(errors), "Errors: %r" % errors)
161 self.assertEquals(
162 "Somebody <somebody@ubuntu.com>", changes.changed_by['rfc822'])
163
164 def test_simulated_changelog(self):
165 # The simulated_changelog property returns a changelog entry based on
166 # the control fields.
167 contents = self.getBaseChanges()
168 changes = self.createChangesFile(
169 "mypkg_0.1_i386.changes", contents)
170 self.assertEquals([], list(changes.processAddresses()))
171 self.assertEquals(
172 "Something changed\n"
173 " -- Somebody <somebody@ubuntu.com> Fri, 25 Jun 2010 11:20:22 -0600",
174 changes.simulated_changelog)
175
176 def test_requires_changed_by(self):
177 # A changes file is rejected if it does not have a Changed-By field.
178 contents = self.getBaseChanges()
179 del contents["Changed-By"]
180 self.assertRaises(
181 UploadError,
182 self.createChangesFile, "mypkg_0.1_i386.changes", contents)
55183
=== added file 'lib/lp/archiveuploader/tests/test_nascentuploadfile.py'
--- lib/lp/archiveuploader/tests/test_nascentuploadfile.py 1970-01-01 00:00:00 +0000
+++ lib/lp/archiveuploader/tests/test_nascentuploadfile.py 2010-08-19 15:51:44 +0000
@@ -0,0 +1,243 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Test NascentUploadFile functionality."""
5
6__metaclass__ = type
7
8from debian.deb822 import Changes, Dsc
9import hashlib
10import os
11
12from canonical.launchpad.scripts.logger import BufferLogger
13from canonical.testing import LaunchpadZopelessLayer
14
15from lp.archiveuploader.changesfile import ChangesFile
16from lp.archiveuploader.dscfile import DSCFile
17from lp.archiveuploader.nascentuploadfile import (
18 CustomUploadFile,
19 DebBinaryUploadFile,
20 )
21from lp.archiveuploader.tests import AbsolutelyAnythingGoesUploadPolicy
22from lp.soyuz.interfaces.queue import PackageUploadCustomFormat
23from lp.testing import TestCaseWithFactory
24
25
26class NascentUploadFileTestCase(TestCaseWithFactory):
27 """Base class for all tests of classes deriving from NascentUploadFile."""
28
29 def setUp(self):
30 super(NascentUploadFileTestCase, self).setUp()
31 self.logger = BufferLogger()
32 self.policy = AbsolutelyAnythingGoesUploadPolicy()
33 self.distro = self.factory.makeDistribution()
34 self.policy.archive = self.factory.makeArchive(
35 distribution=self.distro)
36
37 def writeUploadFile(self, filename, contents):
38 """Write a temporary file but with a specific filename.
39
40 :param filename: Filename to use
41 :param contents: Contents of the file
42 :return: Tuple with path, digest and size
43 """
44 path = os.path.join(self.makeTemporaryDirectory(), filename)
45 f = open(path, 'w')
46 try:
47 f.write(contents)
48 finally:
49 f.close()
50 return (path, hashlib.sha1(contents), len(contents))
51
52
53class CustomUploadFileTests(NascentUploadFileTestCase):
54 """Tests for CustomUploadFile."""
55
56 layer = LaunchpadZopelessLayer
57
58 def createCustomUploadFile(self, filename, contents,
59 component_and_section, priority_name):
60 """Simple wrapper to create a CustomUploadFile."""
61 (path, digest, size) = self.writeUploadFile(filename, contents)
62 uploadfile = CustomUploadFile(
63 path, digest, size, component_and_section, priority_name,
64 self.policy, self.logger)
65 return uploadfile
66
67 def test_custom_type(self):
68 # The mime type gets set according to PackageUploadCustomFormat.
69 uploadfile = self.createCustomUploadFile(
70 "bla.txt", "data", "main/raw-installer", "extra")
71 self.assertEquals(
72 PackageUploadCustomFormat.DEBIAN_INSTALLER,
73 uploadfile.custom_type)
74
75 def test_storeInDatabase(self):
76 # storeInDatabase creates a library file.
77 uploadfile = self.createCustomUploadFile(
78 "bla.txt", "data", "main/raw-installer", "extra")
79 self.assertEquals("application/octet-stream", uploadfile.content_type)
80 libraryfile = uploadfile.storeInDatabase()
81 self.assertEquals("bla.txt", libraryfile.filename)
82 self.assertEquals("application/octet-stream", libraryfile.mimetype)
83
84
85class PackageUploadFileTestCase(NascentUploadFileTestCase):
86 """Base class for all tests of classes deriving from PackageUploadFile."""
87
88 def setUp(self):
89 super(PackageUploadFileTestCase, self).setUp()
90 self.policy.distroseries = self.factory.makeDistroSeries(
91 distribution=self.distro)
92
93 def getBaseChanges(self):
94 contents = Changes()
95 contents["Source"] = "mypkg"
96 contents["Binary"] = "binary"
97 contents["Architecture"] = "i386"
98 contents["Version"] = "0.1"
99 contents["Distribution"] = "nifty"
100 contents["Description"] = "\n Foo"
101 contents["Maintainer"] = "Somebody"
102 contents["Changes"] = "Something changed"
103 contents["Date"] = "Fri, 25 Jun 2010 11:20:22 -0600"
104 contents["Urgency"] = "low"
105 contents["Changed-By"] = "Seombody Else <somebody@example.com>"
106 contents["Files"] = [{
107 "md5sum": "d2bd347b3fed184fe28e112695be491c",
108 "size": "1791",
109 "section": "python",
110 "priority": "optional",
111 "name": "dulwich_0.4.1-1.dsc"}]
112 return contents
113
114 def createChangesFile(self, filename, changes):
115 tempdir = self.makeTemporaryDirectory()
116 path = os.path.join(tempdir, filename)
117 changes_fd = open(path, "w")
118 try:
119 changes.dump(changes_fd)
120 finally:
121 changes_fd.close()
122 return ChangesFile(path, self.policy, self.logger)
123
124
125class DSCFileTests(PackageUploadFileTestCase):
126 """Tests for DSCFile."""
127
128 layer = LaunchpadZopelessLayer
129
130 def getBaseDsc(self):
131 dsc = Dsc()
132 dsc["Architecture"] = "all"
133 dsc["Version"] = "0.42"
134 dsc["Source"] = "dulwich"
135 dsc["Binary"] = "python-dulwich"
136 dsc["Standards-Version"] = "0.2.2"
137 dsc["Maintainer"] = "Jelmer Vernooij <jelmer@ubuntu.com>"
138 dsc["Files"] = [{
139 "md5sum": "5e8ba79b4074e2f305ddeaf2543afe83",
140 "size": "182280",
141 "name": "dulwich_0.42.tar.gz"}]
142 return dsc
143
144 def createDSCFile(self, filename, dsc, component_and_section,
145 priority_name, package, version, changes):
146 (path, digest, size) = self.writeUploadFile(filename, dsc.dump())
147 if changes:
148 self.assertEquals([], list(changes.processAddresses()))
149 return DSCFile(
150 path, digest, size, component_and_section, priority_name, package,
151 version, changes, self.policy, self.logger)
152
153 def test_filetype(self):
154 # The filetype attribute is set based on the file extension.
155 dsc = self.getBaseDsc()
156 uploadfile = self.createDSCFile(
157 "foo.dsc", dsc, "main/net", "extra", "dulwich", "0.42", None)
158 self.assertEquals(
159 "text/x-debian-source-package", uploadfile.content_type)
160
161 def test_storeInDatabase(self):
162 # storeInDatabase creates a SourcePackageRelease.
163 dsc = self.getBaseDsc()
164 dsc["Build-Depends"] = "dpkg, bzr"
165 changes = self.getBaseChanges()
166 uploadfile = self.createDSCFile(
167 "foo.dsc", dsc, "main/net", "extra", "dulwich", "0.42",
168 self.createChangesFile("foo.changes", changes))
169 (uploadfile.changelog_path, changelog_digest, changelog_size) = (
170 self.writeUploadFile("changelog", "DUMMY"))
171 uploadfile.files = []
172 release = uploadfile.storeInDatabase(None)
173 self.assertEquals("0.42", release.version)
174 self.assertEquals("dpkg, bzr", release.builddepends)
175
176
177class DebBinaryUploadFileTests(PackageUploadFileTestCase):
178 """Tests for DebBinaryUploadFile."""
179
180 layer = LaunchpadZopelessLayer
181
182 def getBaseControl(self):
183 return {
184 "Package": "python-dulwich",
185 "Source": "dulwich",
186 "Version": "0.42",
187 "Architecture": "i386",
188 "Maintainer": "Jelmer Vernooij <jelmer@debian.org>",
189 "Installed-Size": "524",
190 "Depends": "python (<< 2.7), python (>= 2.5)",
191 "Provides": "python2.5-dulwich, python2.6-dulwich",
192 "Section": "python",
193 "Priority": "optional",
194 "Homepage": "http://samba.org/~jelmer/dulwich",
195 "Description": "Pure-python Git library\n"
196 "Dulwich is a Python implementation of the file formats and "
197 "protocols"
198 }
199
200 def createDebBinaryUploadFile(self, filename, component_and_section,
201 priority_name, package, version, changes):
202 """Create a DebBinaryUploadFile."""
203 (path, digest, size) = self.writeUploadFile(filename, "DUMMY DATA")
204 return DebBinaryUploadFile(
205 path, digest, size, component_and_section, priority_name, package,
206 version, changes, self.policy, self.logger)
207
208 def test_unknown_priority(self):
209 # Unknown priorities automatically get changed to 'extra'.
210 uploadfile = self.createDebBinaryUploadFile(
211 "foo_0.42_i386.deb", "main/net", "unknown", "mypkg", "0.42", None)
212 self.assertEquals("extra", uploadfile.priority_name)
213
214 def test_parseControl(self):
215 # parseControl sets various fields on DebBinaryUploadFile.
216 uploadfile = self.createDebBinaryUploadFile(
217 "foo_0.42_i386.deb", "main/python", "unknown", "mypkg", "0.42",
218 None)
219 control = self.getBaseControl()
220 uploadfile.parseControl(control)
221 self.assertEquals("python", uploadfile.section_name)
222 self.assertEquals("dulwich", uploadfile.source_name)
223 self.assertEquals("0.42", uploadfile.source_version)
224 self.assertEquals("0.42", uploadfile.control_version)
225
226 def test_storeInDatabase(self):
227 # storeInDatabase creates a BinaryPackageRelease.
228 uploadfile = self.createDebBinaryUploadFile(
229 "foo_0.42_i386.deb", "main/python", "unknown", "mypkg", "0.42",
230 None)
231 control = self.getBaseControl()
232 uploadfile.parseControl(control)
233 build = self.factory.makeBinaryPackageBuild()
234 bpr = uploadfile.storeInDatabase(build)
235 self.assertEquals(u'python (<< 2.7), python (>= 2.5)', bpr.depends)
236 self.assertEquals(
237 u"Dulwich is a Python implementation of the file formats "
238 u"and protocols", bpr.description)
239 self.assertEquals(False, bpr.essential)
240 self.assertEquals(524, bpr.installedsize)
241 self.assertEquals(True, bpr.architecturespecific)
242 self.assertEquals(u"", bpr.recommends)
243 self.assertEquals("0.42", bpr.version)