1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test SourcePackageRelease."""
__metaclass__ = type
from textwrap import dedent
import transaction
from zope.component import getUtility
from canonical.testing.layers import (
LaunchpadFunctionalLayer,
LaunchpadZopelessLayer,
ZopelessDatabaseLayer,
)
from lp.buildmaster.enums import BuildStatus
from lp.registry.interfaces.pocket import PackagePublishingPocket
from lp.services.tarfile_helpers import LaunchpadWriteTarFile
from lp.soyuz.enums import SourcePackageFormat
from lp.soyuz.interfaces.sourcepackageformat import (
ISourcePackageFormatSelectionSet,
)
from lp.soyuz.scripts.packagecopier import do_copy
from lp.testing import (
person_logged_in,
TestCaseWithFactory,
)
from lp.testing.dbuser import dbuser
from lp.translations.interfaces.translationimportqueue import (
ITranslationImportQueue,
)
class TestSourcePackageRelease(TestCaseWithFactory):
layer = LaunchpadFunctionalLayer
def test_uploader_no_uploader(self):
spr = self.factory.makeSourcePackageRelease()
self.assertIs(None, spr.uploader)
def test_uploader_dsc_package(self):
owner = self.factory.makePerson()
key = self.factory.makeGPGKey(owner)
spr = self.factory.makeSourcePackageRelease(dscsigningkey=key)
self.assertEqual(owner, spr.uploader)
def test_uploader_recipe(self):
recipe_build = self.factory.makeSourcePackageRecipeBuild()
spr = self.factory.makeSourcePackageRelease(
source_package_recipe_build=recipe_build)
self.assertEqual(recipe_build.requester, spr.uploader)
def test_user_defined_fields(self):
release = self.factory.makeSourcePackageRelease(
user_defined_fields=[
("Python-Version", ">= 2.4"),
("Other", "Bla")])
self.assertEquals([
["Python-Version", ">= 2.4"],
["Other", "Bla"]], release.user_defined_fields)
def test_homepage_default(self):
# By default, no homepage is set.
spr = self.factory.makeSourcePackageRelease()
self.assertEquals(None, spr.homepage)
def test_homepage_empty(self):
# The homepage field can be empty.
spr = self.factory.makeSourcePackageRelease(homepage="")
self.assertEquals("", spr.homepage)
def test_homepage_set_invalid(self):
# As the homepage field is inherited from the DSCFile, the URL
# does not have to be valid.
spr = self.factory.makeSourcePackageRelease(homepage="<invalid<url")
self.assertEquals("<invalid<url", spr.homepage)
def test_aggregate_changelog(self):
# If since_version is passed the "changelog" entry returned
# should contain the changelogs for all releases *since*
# that version and up to and including the context SPR.
changelog = self.factory.makeChangelog(
spn="foo", versions=["1.3", "1.2", "1.1", "1.0"])
expected_changelog = dedent(u"""\
foo (1.3) unstable; urgency=low
* 1.3.
foo (1.2) unstable; urgency=low
* 1.2.
foo (1.1) unstable; urgency=low
* 1.1.""")
spph = self.factory.makeSourcePackagePublishingHistory(
sourcepackagename="foo", version="1.3", changelog=changelog)
transaction.commit() # Yay, librarian.
observed = spph.sourcepackagerelease.aggregate_changelog(
since_version="1.0")
self.assertEqual(expected_changelog, observed)
class TestSourcePackageReleaseGetBuildByArch(TestCaseWithFactory):
"""Tests for SourcePackageRelease.getBuildByArch()."""
layer = ZopelessDatabaseLayer
def test_can_find_build_in_derived_distro_parent(self):
# If a derived distribution inherited its binaries from its
# parent then getBuildByArch() should look in the parent to find
# the build.
dsp = self.factory.makeDistroSeriesParent()
parent_archive = dsp.parent_series.main_archive
# Create a built, published package in the parent archive.
spr = self.factory.makeSourcePackageRelease(
architecturehintlist='any')
parent_source_pub = self.factory.makeSourcePackagePublishingHistory(
sourcepackagerelease=spr, archive=parent_archive,
distroseries=dsp.parent_series)
das = self.factory.makeDistroArchSeries(
distroseries=dsp.parent_series, supports_virtualized=True)
orig_build = spr.createBuild(
das, PackagePublishingPocket.RELEASE, parent_archive,
status=BuildStatus.FULLYBUILT)
bpr = self.factory.makeBinaryPackageRelease(build=orig_build)
self.factory.makeBinaryPackagePublishingHistory(
binarypackagerelease=bpr, distroarchseries=das,
archive=parent_archive)
# Make an architecture in the derived series with the same
# archtag as the parent.
das_derived = self.factory.makeDistroArchSeries(
dsp.derived_series, architecturetag=das.architecturetag,
processorfamily=das.processorfamily, supports_virtualized=True)
# Now copy the package to the derived series, with binary.
derived_archive = dsp.derived_series.main_archive
getUtility(ISourcePackageFormatSelectionSet).add(
dsp.derived_series, SourcePackageFormat.FORMAT_1_0)
do_copy(
[parent_source_pub], derived_archive, dsp.derived_series,
PackagePublishingPocket.RELEASE, include_binaries=True,
check_permissions=False)
# Searching for the build in the derived series architecture
# should automatically pick it up from the parent.
found_build = spr.getBuildByArch(das_derived, derived_archive)
self.assertEqual(orig_build, found_build)
class TestSourcePackageReleaseTranslationFiles(TestCaseWithFactory):
"""Tests for attachTranslationFiles on a different layer."""
layer = LaunchpadZopelessLayer
def makeTranslationsLFA(self):
"""Create an LibraryFileAlias containing dummy translation data."""
test_tar_content = {
'source/po/foo.pot': 'Foo template',
'source/po/eo.po': 'Foo translation',
}
tarfile_content = LaunchpadWriteTarFile.files_to_string(
test_tar_content)
return self.factory.makeLibraryFileAlias(content=tarfile_content)
def test_attachTranslationFiles__no_translation_sharing(self):
# If translation sharing is disabled,
# SourcePackageRelease.attachTranslationFiles() creates a job
# in the translation import queue.
spr = self.factory.makeSourcePackageRelease()
self.assertFalse(spr.sourcepackage.has_sharing_translation_templates)
lfa = self.makeTranslationsLFA()
transaction.commit()
with dbuser('queued'):
spr.attachTranslationFiles(lfa, True, spr.maintainer)
translation_import_queue = getUtility(ITranslationImportQueue)
entries_in_queue = translation_import_queue.getAllEntries(
target=spr.sourcepackage).count()
self.assertEqual(2, entries_in_queue)
def test_attachTranslationFiles__translation_sharing(self):
# If translation sharing is enabled,
# SourcePackageRelease.attachTranslationFiles() only attaches
# templates.
spr = self.factory.makeSourcePackageRelease()
sourcepackage = spr.sourcepackage
productseries = self.factory.makeProductSeries()
self.factory.makePOTemplate(productseries=productseries)
with person_logged_in(sourcepackage.distroseries.owner):
sourcepackage.setPackaging(
productseries, sourcepackage.distroseries.owner)
self.assertTrue(sourcepackage.has_sharing_translation_templates)
lfa = self.makeTranslationsLFA()
transaction.commit()
with dbuser('queued'):
spr.attachTranslationFiles(lfa, True, spr.maintainer)
translation_import_queue = getUtility(ITranslationImportQueue)
entries = translation_import_queue.getAllEntries(
target=sourcepackage)
self.assertEqual(1, entries.count())
self.assertTrue(entries[0].path.endswith('.pot'))
|