~mars/launchpad/test-ghost-update

« back to all changes in this revision

Viewing changes to lib/lp/bugs/tests/test_bugsupervisor_bugnomination.py

[r=abentley][ui=none][bug=114766] Restrict the ability to nominate
        bugs for a release to bug supervisors, owners or drivers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Tests related to bug nominations for an object with a bug supervisor."""
 
5
 
 
6
__metaclass__ = type
 
7
 
 
8
from canonical.launchpad.ftests import (
 
9
    login,
 
10
    login_person,
 
11
    logout,
 
12
    )
 
13
from canonical.testing.layers import DatabaseFunctionalLayer
 
14
 
 
15
from lp.bugs.interfaces.bugnomination import NominationError
 
16
from lp.testing import TestCaseWithFactory
 
17
 
 
18
 
 
19
class AddNominationTestMixin:
 
20
    """Test case mixin for IBug.addNomination."""
 
21
 
 
22
    layer = DatabaseFunctionalLayer
 
23
 
 
24
    def setUp(self):
 
25
        super(AddNominationTestMixin, self).setUp()
 
26
        login('foo.bar@canonical.com')
 
27
        self.user = self.factory.makePerson(name='ordinary-user')
 
28
        self.bug_supervisor = self.factory.makePerson(name='no-ordinary-user')
 
29
        self.owner = self.factory.makePerson(name='extraordinary-user')
 
30
        self.setUpTarget()
 
31
        logout()
 
32
 
 
33
    def tearDown(self):
 
34
        logout()
 
35
        super(AddNominationTestMixin, self).tearDown()
 
36
 
 
37
    def test_user_addNominationFor_series(self):
 
38
        # A bug may not be nominated for a series of a product with an
 
39
        # existing task by just anyone.
 
40
        login_person(self.user)
 
41
        self.assertRaises(NominationError,
 
42
            self.bug.addNomination, self.user, self.series)
 
43
 
 
44
    def test_bugsupervisor_addNominationFor_series(self):
 
45
        # A bug may be nominated for a series of a product with an
 
46
        # exisiting task by the product's bug supervisor.
 
47
        login_person(self.bug_supervisor)
 
48
        self.bug.addNomination(self.bug_supervisor, self.series)
 
49
        self.assertTrue(len(self.bug.getNominations()), 1)
 
50
 
 
51
    def test_owner_addNominationFor_series(self):
 
52
        # A bug may be nominated for a series of a product with an
 
53
        # exisiting task by the product's owner.
 
54
        login_person(self.owner)
 
55
        self.bug.addNomination(self.owner, self.series)
 
56
        self.assertTrue(len(self.bug.getNominations()), 1)
 
57
 
 
58
 
 
59
class TestBugAddNominationProductSeries(
 
60
    AddNominationTestMixin, TestCaseWithFactory):
 
61
    """Test IBug.addNomination for IProductSeries nominations."""
 
62
 
 
63
    def setUpTarget(self):
 
64
        self.product = self.factory.makeProduct(official_malone = True,
 
65
            bug_supervisor=self.bug_supervisor,
 
66
            owner=self.owner)
 
67
        self.series = self.factory.makeProductSeries(product=self.product)
 
68
        self.bug = self.factory.makeBug(product=self.product)
 
69
        self.milestone = self.factory.makeMilestone(productseries=self.series)
 
70
 
 
71
 
 
72
class TestBugAddNominationDistroSeries(
 
73
    AddNominationTestMixin, TestCaseWithFactory):
 
74
    """Test IBug.addNomination for IDistroSeries nominations."""
 
75
 
 
76
    def setUpTarget(self):
 
77
        self.distro = self.factory.makeDistribution(
 
78
            bug_supervisor=self.bug_supervisor,
 
79
            owner=self.owner)
 
80
        self.series = self.factory.makeDistroRelease(distribution=self.distro)
 
81
        # The factory can't create a distro bug directly.
 
82
        self.bug = self.factory.makeBug()
 
83
        self.bug.addTask(self.bug_supervisor, self.distro)
 
84
        self.milestone = self.factory.makeMilestone(
 
85
            distribution=self.distro)