~launchpad-pqm/launchpad/devel

7675.899.1 by Paul Hummer
Added end-to-end script for getting to the queue index
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""Tests for the branch merge queue view classes and templates."""
5
6
from __future__ import with_statement
7
8
__metaclass__ = type
9
14550.1.1 by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad
10
import re
11
7675.899.10 by Paul Hummer
Added tests for creating merge queues.
12
from mechanize import LinkNotFoundError
7675.899.11 by Paul Hummer
SOUPMATCHERS!!1!
13
import soupmatchers
14
14550.1.1 by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad
15
from lp.services.features.model import (
16
    FeatureFlag,
17
    getFeatureStore,
7675.899.1 by Paul Hummer
Added end-to-end script for getting to the queue index
18
    )
14612.2.1 by William Grant
format-imports on lib/. So many imports.
19
from lp.services.webapp import canonical_url
7675.899.1 by Paul Hummer
Added end-to-end script for getting to the queue index
20
from lp.testing import (
21
    ANONYMOUS,
22
    BrowserTestCase,
23
    person_logged_in,
24
    )
14612.2.1 by William Grant
format-imports on lib/. So many imports.
25
from lp.testing.layers import DatabaseFunctionalLayer
7675.899.1 by Paul Hummer
Added end-to-end script for getting to the queue index
26
27
7675.899.3 by Paul Hummer
Working out an index page
28
class TestBranchMergeQueue(BrowserTestCase):
7675.899.1 by Paul Hummer
Added end-to-end script for getting to the queue index
29
    """Test the Branch Merge Queue index page."""
30
31
    layer = DatabaseFunctionalLayer
32
7675.899.13 by Paul Hummer
Used a feature flag
33
    def enable_queue_flag(self):
34
        getFeatureStore().add(FeatureFlag(
35
            scope=u'default', flag=u'code.branchmergequeue',
36
            value=u'on', priority=1))
37
7675.899.1 by Paul Hummer
Added end-to-end script for getting to the queue index
38
    def test_index(self):
39
        """Test the index page of a branch merge queue."""
40
        with person_logged_in(ANONYMOUS):
41
            queue = self.factory.makeBranchMergeQueue()
7675.899.6 by Paul Hummer
Got a working test
42
            queue_owner = queue.owner.displayname
43
            queue_registrant = queue.registrant.displayname
44
            queue_description = queue.description
7675.899.1 by Paul Hummer
Added end-to-end script for getting to the queue index
45
            queue_url = canonical_url(queue)
46
7675.899.6 by Paul Hummer
Got a working test
47
            branch = self.factory.makeBranch()
48
            branch_name = branch.bzr_identity
49
            with person_logged_in(branch.owner):
50
                branch.addToQueue(queue)
51
7675.899.11 by Paul Hummer
SOUPMATCHERS!!1!
52
        # XXX: rockstar - bug #666979 - The text argument should really ignore
53
        # whitespace, but it currently doesn't.  Now I have two problems.
54
        queue_matcher = soupmatchers.HTMLContains(
55
            soupmatchers.Tag(
56
                'Page title', 'h1',
57
                text=re.compile('\w*%s queue owned by %s\w*' % (
58
                    queue.name, queue.owner.displayname))),
59
            soupmatchers.Tag(
60
                'Description Label', 'dt',
61
                text=re.compile('\w*Description\w*')),
62
            soupmatchers.Tag(
63
                'Description Value', 'dd',
64
                text=re.compile('\w*%s\w*' % queue.description)),
65
            soupmatchers.Tag(
66
                'Branch link', 'a',
67
                text=re.compile('\w*%s\w*' % branch.bzr_identity)))
68
7675.899.1 by Paul Hummer
Added end-to-end script for getting to the queue index
69
        browser = self.getUserBrowser(canonical_url(queue), user=queue.owner)
7675.899.4 by Paul Hummer
Got a working test
70
7675.899.11 by Paul Hummer
SOUPMATCHERS!!1!
71
        self.assertThat(browser.contents, queue_matcher)
7675.899.10 by Paul Hummer
Added tests for creating merge queues.
72
73
    def test_create(self):
74
        """Test that branch merge queues can be created from a branch."""
7675.899.13 by Paul Hummer
Used a feature flag
75
        self.enable_queue_flag()
7675.899.10 by Paul Hummer
Added tests for creating merge queues.
76
        with person_logged_in(ANONYMOUS):
77
            rockstar = self.factory.makePerson(name='rockstar')
78
            branch = self.factory.makeBranch(owner=rockstar)
79
            self.factory.makeBranch(product=branch.product)
80
            owner_name = branch.owner.name
81
82
        browser = self.getUserBrowser(canonical_url(branch), user=rockstar)
7675.899.18 by Paul Hummer
Added test for 'This branch is not managed by a queue'
83
84
        # There shouldn't be a merge queue linked here.
85
        noqueue_matcher = soupmatchers.HTMLContains(
86
            soupmatchers.Tag(
87
                'Not managed', 'div',
88
                text=re.compile(
89
                    '\w*This branch is not managed by a queue.\w*')))
90
        self.assertThat(browser.contents, noqueue_matcher)
91
7675.899.10 by Paul Hummer
Added tests for creating merge queues.
92
        browser.getLink('Create a new queue').click()
93
94
        browser.getControl('Name').value = 'libbob-queue'
95
        browser.getControl('Description').value = (
96
            'This is a queue for the libbob projects.')
97
        browser.getControl('Create Queue').click()
98
99
        self.assertEqual(
100
            'http://code.launchpad.dev/~rockstar/+merge-queues/libbob-queue',
101
            browser.url)
102
103
    def test_create_unauthorized(self):
104
        """Test that queues can't be created by unauthorized users."""
7675.899.13 by Paul Hummer
Used a feature flag
105
        self.enable_queue_flag()
7675.899.10 by Paul Hummer
Added tests for creating merge queues.
106
        with person_logged_in(ANONYMOUS):
107
            branch = self.factory.makeBranch()
108
            self.factory.makeBranch(product=branch.product)
109
110
        browser = self.getUserBrowser(canonical_url(branch))
111
        self.assertRaises(
112
            LinkNotFoundError,
113
            browser.getLink,
114
            'Create a new queue')
7675.899.17 by Paul Hummer
Added test for feature flag
115
116
    def test_create_featureflag(self):
117
        """Test that the feature flag hides the "create" link."""
118
        with person_logged_in(ANONYMOUS):
119
            rockstar = self.factory.makePerson(name='rockstar')
120
            branch = self.factory.makeBranch(owner=rockstar)
121
            self.factory.makeBranch(product=branch.product)
122
            owner_name = branch.owner.name
123
124
        browser = self.getUserBrowser(canonical_url(branch), user=rockstar)
125
        self.assertRaises(
126
            LinkNotFoundError,
127
            browser.getLink,
128
            'Create a new queue')