1
# Copyright 2010 Canonical Ltd. This software is licensed under the
1
# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
4
"""Unit tests for TranslationTemplatesBuildBehavior."""
73
74
Anything that might communicate with build slaves and such
74
75
(which we can't really do here) is mocked up.
76
specific_job = self.factory.makeTranslationTemplatesBuildJob(
78
behavior = IBuildFarmJobBehavior(specific_job)
79
slave = WaitingSlave()
80
behavior._builder = removeSecurityProxy(self.factory.makeBuilder())
81
behavior._builder.setSlaveForTesting(slave)
83
lf = self.factory.makeLibraryFileAlias()
84
self.layer.txn.commit()
85
behavior._getChroot = lambda: lf
77
with BuilddManagerTestFixture.extraSetUp():
78
specific_job = self.factory.makeTranslationTemplatesBuildJob(
80
behavior = IBuildFarmJobBehavior(specific_job)
81
slave = WaitingSlave()
82
behavior._builder = removeSecurityProxy(
83
self.factory.makeBuilder())
84
behavior._builder.setSlaveForTesting(slave)
86
lf = self.factory.makeLibraryFileAlias()
87
self.layer.txn.commit()
88
behavior._getChroot = lambda: lf
88
91
def makeProductSeriesWithBranchForTranslation(self):
89
productseries = self.factory.makeProductSeries()
90
branch = self.factory.makeProductBranch(
91
productseries.product)
92
productseries.branch = branch
93
productseries.translations_autoimport_mode = (
94
TranslationsBranchImportMode.IMPORT_TEMPLATES)
92
with BuilddManagerTestFixture.extraSetUp():
93
productseries = self.factory.makeProductSeries()
94
branch = self.factory.makeProductBranch(
95
productseries.product)
96
productseries.branch = branch
97
productseries.translations_autoimport_mode = (
98
TranslationsBranchImportMode.IMPORT_TEMPLATES)
98
102
class TestTranslationTemplatesBuildBehavior(
106
110
super(TestTranslationTemplatesBuildBehavior, self).setUp()
107
111
self.slave_helper = self.useFixture(SlaveTestHelpers())
112
self.useFixture(BuilddManagerTestFixture())
109
114
def _becomeBuilddMaster(self):
110
115
"""Log into the database as the buildd master."""
145
150
# _getChroot produces the current chroot for the current Ubuntu
146
151
# release, on the nominated architecture for
147
152
# architecture-independent builds.
148
ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
149
current_ubuntu = ubuntu.currentseries
150
distroarchseries = current_ubuntu.nominatedarchindep
152
# Set an arbitrary chroot file.
153
fake_chroot_file = getUtility(ILibraryFileAliasSet)[1]
154
distroarchseries.addOrUpdateChroot(fake_chroot_file)
153
with BuilddManagerTestFixture.extraSetUp():
154
ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
155
current_ubuntu = ubuntu.currentseries
156
distroarchseries = current_ubuntu.nominatedarchindep
157
# Set an arbitrary chroot file.
158
fake_chroot_file = getUtility(ILibraryFileAliasSet)[1]
159
distroarchseries.addOrUpdateChroot(fake_chroot_file)
156
161
behavior = self.makeBehavior(use_fake_chroot=False)
157
162
chroot = behavior._getChroot()
181
186
def test_updateBuild_WAITING_OK(self):
182
187
# Hopefully, a build will succeed and produce a tarball.
183
behavior = self.makeBehavior()
184
behavior._uploadTarball = FakeMethod()
185
queue_item = FakeBuildQueue(behavior)
186
builder = behavior._builder
188
with BuilddManagerTestFixture.extraSetUp():
189
behavior = self.makeBehavior()
190
behavior._uploadTarball = FakeMethod()
191
queue_item = FakeBuildQueue(behavior)
192
builder = behavior._builder
188
194
d = behavior.dispatchBuildToSlave(queue_item, logging)
222
228
def test_updateBuild_WAITING_failed(self):
223
229
# Builds may also fail (and produce no tarball).
224
behavior = self.makeBehavior()
225
behavior._uploadTarball = FakeMethod()
226
queue_item = FakeBuildQueue(behavior)
227
builder = behavior._builder
230
with BuilddManagerTestFixture.extraSetUp():
231
behavior = self.makeBehavior()
232
behavior._uploadTarball = FakeMethod()
233
queue_item = FakeBuildQueue(behavior)
234
builder = behavior._builder
228
236
d = behavior.dispatchBuildToSlave(queue_item, logging)
230
238
def got_dispatch((status, info)):
264
272
def test_updateBuild_WAITING_notarball(self):
265
273
# Even if the build status is "OK," absence of a tarball will
266
274
# not faze the Behavior class.
267
behavior = self.makeBehavior()
268
behavior._uploadTarball = FakeMethod()
269
queue_item = FakeBuildQueue(behavior)
270
builder = behavior._builder
275
with BuilddManagerTestFixture.extraSetUp():
276
behavior = self.makeBehavior()
277
behavior._uploadTarball = FakeMethod()
278
queue_item = FakeBuildQueue(behavior)
279
builder = behavior._builder
271
281
d = behavior.dispatchBuildToSlave(queue_item, logging)
273
283
def got_dispatch((status, info)):
303
313
def test_updateBuild_WAITING_uploads(self):
304
productseries = self.makeProductSeriesWithBranchForTranslation()
305
branch = productseries.branch
306
behavior = self.makeBehavior(branch=branch)
307
queue_item = FakeBuildQueue(behavior)
308
builder = behavior._builder
314
with BuilddManagerTestFixture.extraSetUp():
315
productseries = self.makeProductSeriesWithBranchForTranslation()
316
branch = productseries.branch
317
behavior = self.makeBehavior(branch=branch)
318
queue_item = FakeBuildQueue(behavior)
319
builder = behavior._builder
310
321
d = behavior.dispatchBuildToSlave(queue_item, logging)