~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/browser/tests/test_sourcepackagerecipe.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-31 12:25:29 UTC
  • mfrom: (13824.2.5 bug-836932)
  • Revision ID: launchpad@pqm.canonical.com-20110831122529-mkmvmwcnb4dhiifu
[r=jtv][bug=836932] Catch TooManyBuilds exception and show an error
 to the user.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from zope.security.proxy import removeSecurityProxy
24
24
 
25
25
from canonical.database.constants import UTC_NOW
 
26
from canonical.launchpad.ftests import LaunchpadFormHarness
26
27
from canonical.launchpad.testing.pages import (
27
28
    extract_text,
28
29
    find_main_content,
43
44
from lp.code.browser.sourcepackagerecipe import (
44
45
    SourcePackageRecipeEditView,
45
46
    SourcePackageRecipeRequestBuildsView,
 
47
    SourcePackageRecipeRequestDailyBuildView,
46
48
    SourcePackageRecipeView,
47
49
    )
48
50
from lp.code.browser.sourcepackagerecipebuild import (
232
234
        # If the initial name exists, a generator is used to find an unused
233
235
        # name by appending a numbered suffix on the end.
234
236
        owner = self.factory.makePerson()
235
 
        self.factory.makeSourcePackageRecipe(owner=owner, name=u'widget-daily')
 
237
        self.factory.makeSourcePackageRecipe(
 
238
            owner=owner, name=u'widget-daily')
236
239
        widget = self.factory.makeProduct(name='widget')
237
240
        branch = self.factory.makeProductBranch(widget)
238
241
        with person_logged_in(owner):
1095
1098
        self.assertTextMatchesExpressionIgnoreWhitespace("""\
1096
1099
            Latest builds
1097
1100
            Status .* Archive
1098
 
            Successful build on 2010-03-16 buildlog \(.*\) Secret Squirrel Secret PPA
 
1101
            Successful build on 2010-03-16 buildlog \(.*\)
 
1102
                Secret Squirrel Secret PPA
1099
1103
            Request build\(s\)""", self.getMainText(recipe))
1100
1104
 
1101
1105
    def test_index_success_with_binary_builds(self):
1125
1129
        self.assertTextMatchesExpressionIgnoreWhitespace("""\
1126
1130
            Latest builds
1127
1131
            Status .* Archive
1128
 
            Successful build on 2010-03-16 buildlog \(.*\) Secret Squirrel Secret PPA
1129
 
              chocolate - 0\+r42 in .* \(estimated\) i386
 
1132
            Successful build on 2010-03-16 buildlog \(.*\)
 
1133
               Secret Squirrel Secret PPA chocolate - 0\+r42 in .*
 
1134
               \(estimated\) i386
1130
1135
            Request build\(s\)""", self.getMainText(recipe))
1131
1136
 
1132
1137
    def test_index_success_with_completed_binary_build(self):
1160
1165
        self.assertTextMatchesExpressionIgnoreWhitespace("""\
1161
1166
            Latest builds
1162
1167
            Status .* Archive
1163
 
            Successful build on 2010-03-16 buildlog \(.*\) Secret Squirrel Secret PPA
1164
 
              chocolate - 0\+r42 on 2010-04-16 buildlog \(.*\) i386
 
1168
            Successful build on 2010-03-16 buildlog \(.*\) Secret Squirrel
 
1169
              Secret PPA chocolate - 0\+r42 on 2010-04-16 buildlog \(.*\) i386
1165
1170
            Request build\(s\)""", self.getMainText(recipe))
1166
1171
 
1167
1172
    def test_index_no_builds(self):
1338
1343
            set([2505]),
1339
1344
            set(build.buildqueue_record.lastscore for build in builds))
1340
1345
 
 
1346
    def test_request_daily_builds_action_over_quota(self):
 
1347
        recipe = self.factory.makeSourcePackageRecipe(
 
1348
            owner=self.chef, daily_build_archive=self.ppa,
 
1349
            name=u'julia', is_stale=True, build_daily=True)
 
1350
        # Create some previous builds.
 
1351
        series = list(recipe.distroseries)[0]
 
1352
        for x in xrange(5):
 
1353
            build = recipe.requestBuild(
 
1354
                self.ppa, self.chef, series, PackagePublishingPocket.RELEASE)
 
1355
            removeSecurityProxy(build).status = BuildStatus.FULLYBUILT
 
1356
        harness = LaunchpadFormHarness(
 
1357
            recipe, SourcePackageRecipeRequestDailyBuildView)
 
1358
        harness.submit('build', {})
 
1359
        self.assertEqual(
 
1360
            "You have exceeded your quota for recipe chef/julia "
 
1361
            "for distroseries ubuntu warty",
 
1362
            harness.view.request.notifications[0].message)
 
1363
 
1341
1364
    def test_request_builds_page(self):
1342
1365
        """Ensure the +request-builds page is sane."""
1343
1366
        recipe = self.makeRecipe()
1675
1698
        self.assertIn('Logs have no tails!', main_text)
1676
1699
 
1677
1700
    def getMainText(self, build, view_name=None):
1678
 
        """"Return the main text of a view's web page."""
 
1701
        """Return the main text of a view's web page."""
1679
1702
        browser = self.getViewBrowser(build, '+index')
1680
1703
        return extract_text(find_main_content(browser.contents))
1681
1704