~launchpad-pqm/launchpad/devel

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
# Copyright 2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

__metaclass__ = type

from zope.security.proxy import removeSecurityProxy

from lp.services.features.testing import FeatureFixture
from lp.services.webapp import canonical_url
from lp.soyuz.enums import PackagePublishingStatus
from lp.testing import TestCaseWithFactory
from lp.testing.layers import DatabaseFunctionalLayer
from lp.testing.pages import get_feedback_messages


class TestBugAlsoAffectsDistribution(TestCaseWithFactory):

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestBugAlsoAffectsDistribution, self).setUp()
        self.distribution = self.factory.makeDistribution()
        removeSecurityProxy(self.distribution).official_malone = True

    def openBugPage(self, bug):
        browser = self.getUserBrowser()
        browser.open(canonical_url(bug))
        return browser

    def test_bug_alsoaffects_spn_exists(self):
        # If the source package name exists, there is no error.
        bug = self.factory.makeBug()
        spn = self.factory.makeSourcePackageName()
        browser = self.openBugPage(bug)
        browser.getLink(url='+distrotask').click()
        browser.getControl('Distribution').value = [self.distribution.name]
        browser.getControl('Source Package Name').value = spn.name
        browser.getControl('Continue').click()
        self.assertEqual([], get_feedback_messages(browser.contents))

    def test_bug_alsoaffects_spn_exists_dsp_picker_feature_flag(self):
        # If the distribution source package for an spn is official,
        # there is no error.
        bug = self.factory.makeBug()
        distribution, dsp = self.factory.makeDSPCache(
            distro_name=self.distribution.name, package_name='snarf',
            make_distro=False)
        with FeatureFixture({u"disclosure.dsp_picker.enabled": u"on"}):
            browser = self.openBugPage(bug)
            browser.getLink(url='+distrotask').click()
            browser.getControl('Distribution').value = [distribution.name]
            browser.getControl('Source Package Name').value = (
                dsp.sourcepackagename.name)
            browser.getControl('Continue').click()
        self.assertEqual([], get_feedback_messages(browser.contents))

    def test_bug_alsoaffects_dsp_exists_dsp_picker_feature_flag(self):
        # If the distribution source package is official, there is no error.
        bug = self.factory.makeBug()
        distribution, dsp = self.factory.makeDSPCache(
            distro_name=self.distribution.name, package_name='snarf',
            make_distro=False)
        with FeatureFixture({u"disclosure.dsp_picker.enabled": u"on"}):
            browser = self.openBugPage(bug)
            browser.getLink(url='+distrotask').click()
            browser.getControl('Distribution').value = [distribution.name]
            browser.getControl('Source Package Name').value = (
                '%s/%s' % (distribution.name, dsp.name))
            browser.getControl('Continue').click()
        self.assertEqual([], get_feedback_messages(browser.contents))

    def test_bug_alsoaffects_spn_not_exists_with_published_binaries(self):
        # When the distribution has published binaries, we search both
        # source and binary package names.
        bug = self.factory.makeBug()
        distroseries = self.factory.makeDistroSeries(
            distribution=self.distribution)
        das = self.factory.makeDistroArchSeries(distroseries=distroseries)
        self.factory.makeBinaryPackagePublishingHistory(
            distroarchseries=das, status=PackagePublishingStatus.PUBLISHED)
        self.assertTrue(self.distribution.has_published_binaries)
        browser = self.openBugPage(bug)
        browser.getLink(url='+distrotask').click()
        browser.getControl('Distribution').value = [self.distribution.name]
        browser.getControl('Source Package Name').value = 'does-not-exist'
        browser.getControl('Continue').click()
        expected = [
            u'There is 1 error.',
            u'There is no package in %s named "does-not-exist".' % (
                self.distribution.displayname)]
        self.assertEqual(expected, get_feedback_messages(browser.contents))

    def test_bug_alsoaffects_spn_not_exists_with_no_binaries(self):
        # When the distribution has no binary packages published, we can't.
        bug = self.factory.makeBug()
        browser = self.openBugPage(bug)
        browser.getLink(url='+distrotask').click()
        browser.getControl('Distribution').value = [self.distribution.name]
        browser.getControl('Source Package Name').value = 'does-not-exist'
        browser.getControl('Continue').click()
        expected = [
            u'There is 1 error.',
            u'There is no package in %s named "does-not-exist". Launchpad '
            'does not track binary package names in %s.' % (
                self.distribution.displayname,
                self.distribution.displayname)]
        self.assertEqual(expected, get_feedback_messages(browser.contents))