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
"""Tests for the lp.soyuz.browser.builder module."""
8
from testtools.matchers import LessThan
9
from zope.component import getUtility
10
from zope.security.proxy import removeSecurityProxy
12
from lp.buildmaster.interfaces.builder import IBuilderSet
13
from lp.buildmaster.interfaces.buildqueue import IBuildQueueSet
8
14
from lp.services.webapp import canonical_url
9
from lp.testing import TestCaseWithFactory
10
from lp.testing.layers import DatabaseFunctionalLayer
15
from lp.soyuz.browser.tests.test_builder_views import BuildCreationMixin
16
from lp.testing import (
20
from lp.testing.layers import (
21
DatabaseFunctionalLayer,
22
LaunchpadFunctionalLayer,
24
from lp.testing.matchers import HasQueryCount
11
25
from lp.testing.publication import test_traverse
26
from lp.testing.views import create_initialized_view
27
from lp.translations.interfaces.translationtemplatesbuildjob import (
28
ITranslationTemplatesBuildJobSource,
14
32
class TestBuildersNavigation(TestCaseWithFactory):
39
57
canonical_url(build),
40
58
request.response.getHeader('location'))
61
def builders_homepage_render():
62
builders = getUtility(IBuilderSet)
63
create_initialized_view(builders, "+index").render()
66
class TestBuildersHomepage(TestCaseWithFactory, BuildCreationMixin):
68
layer = LaunchpadFunctionalLayer
70
# XXX rvb: the 3 additional queries per build are the result of the calls
72
# - builder.currentjob
73
# - buildqueue.specific_job
74
# These could be converted into cachedproperty and pre-populated in
75
# bulk but several tests assert that the value returned by these
76
# these properties are up to date. Since they are not really expensive
77
# to compute I'll leave them as regular properties for now.
79
def test_builders_binary_package_build_query_count(self):
81
build = self.createBinaryPackageBuild()
82
queue = build.queueBuild()
83
queue.markAsBuilding(build.builder)
85
recorder1, recorder2 = record_two_runs(
86
builders_homepage_render, create_build, 2)
90
HasQueryCount(LessThan(recorder1.count + 3 * 2 + 1)))
92
def test_builders_recipe_build_query_count(self):
94
build = self.createRecipeBuildWithBuilder()
95
queue = build.queueBuild()
96
queue.markAsBuilding(build.builder)
98
recorder1, recorder2 = record_two_runs(
99
builders_homepage_render, create_build, 2)
103
HasQueryCount(LessThan(recorder1.count + 3 * 2 + 1)))
105
def test_builders_translation_template_build_query_count(self):
107
jobset = getUtility(ITranslationTemplatesBuildJobSource)
108
branch = self.factory.makeBranch()
109
specific_job = jobset.create(branch)
110
queueset = getUtility(IBuildQueueSet)
111
# Using rSP is required to get the job id.
112
naked_job = removeSecurityProxy(specific_job.job)
113
job_id = naked_job.id
114
queue = queueset.get(job_id)
115
queue.markAsBuilding(self.factory.makeBuilder())
117
recorder1, recorder2 = record_two_runs(
118
builders_homepage_render, create_build, 2)
122
HasQueryCount(LessThan(recorder1.count + 3 * 2 + 1)))