1
# Copyright 2009 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Test for links between branches and bugs or specs."""
13
from zope.security.proxy import removeSecurityProxy
15
from canonical.launchpad.windmill.testing import lpuser
16
from canonical.launchpad.windmill.testing.constants import SLEEP
17
from lp.code.windmill.testing import CodeWindmillLayer
18
from lp.testing import WindmillTestCase
21
ADD_COMMENT_BUTTON = (
22
u'//input[@id="field.actions.save" and contains(@class, "button")]')
25
class TestBranchLinks(WindmillTestCase):
26
"""Test the rendering of broken branch links."""
28
layer = CodeWindmillLayer
29
suite_name = "Broken branch links"
31
BUG_TEXT_TEMPLATE = u"""
32
Here is the bug. Which branches are valid?
37
BRANCH_URL_TEMPLATE = "lp:%s"
39
def make_product_and_valid_links(self):
40
branch = self.factory.makeProductBranch()
41
valid_branch_url = self.BRANCH_URL_TEMPLATE % branch.unique_name
42
product = self.factory.makeProduct()
43
product_branch = self.factory.makeProductBranch(product=product)
44
naked_product = removeSecurityProxy(product)
45
naked_product.development_focus.branch = product_branch
46
valid_product_url = self.BRANCH_URL_TEMPLATE % product.name
48
return (naked_product, [
53
def make_invalid_links(self):
55
self.BRANCH_URL_TEMPLATE % 'foo',
56
self.BRANCH_URL_TEMPLATE % 'bar',
59
def test_invalid_url_rendering(self):
60
"""Link a bug from the branch page."""
63
lpuser.FOO_BAR.ensure_login(client)
65
naked_product, valid_links = self.make_product_and_valid_links()
66
invalid_links = self.make_invalid_links()
67
bug_description = self.BUG_TEXT_TEMPLATE % (
68
', '.join(valid_links), ', '.join(invalid_links))
69
bug = self.factory.makeBug(product=naked_product,
70
title="The meaning of life is broken",
71
description=bug_description)
75
windmill.settings['TEST_URL'] + '%s/+bug/%s'
76
% (naked_product.name, bug.id))
77
client.open(url=bug_url)
78
client.waits.forElement(xpath=ADD_COMMENT_BUTTON)
80
# Let the Ajax call run
81
client.waits.sleep(milliseconds=SLEEP)
84
var good_a = windmill.testWin().document.getElementsByClassName(
85
'branch-short-link', 'a');
87
for( i=0; i<good_a.length; i++ ) {
88
good_links.push(good_a[i].innerHTML);
91
var bad_a = windmill.testWin().document.getElementsByClassName(
94
for( i=0; i<bad_a.length; i++ ) {
95
bad_links.push(bad_a[i].innerHTML);
100
result.good = good_links;
101
result.bad = bad_links;
104
raw_result = self.client.commands.execJS(js=code)
105
result = raw_result['result']
106
result_valid_links = result['good']
107
result_invalid_links = result['bad']
108
self.assertEqual(set(invalid_links), set(result_invalid_links))
109
self.assertEqual(set(valid_links), set(result_valid_links))
113
return unittest.TestLoader().loadTestsFromName(__name__)