8687.15.22
by Karl Fogel
Add the copyright header block to the remaining .py files. |
1 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
8537.4.2
by Tim Penhey
Add a test to confirm the precaching of the permissions. |
3 |
|
4 |
"""Tests for classes in the lp.code.browser.bazaar module."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8537.4.6
by Tim Penhey
Updates following review. |
8 |
from zope.security.proxy import removeSecurityProxy |
8537.4.2
by Tim Penhey
Add a test to confirm the precaching of the permissions. |
9 |
|
14612.2.1
by William Grant
format-imports on lib/. So many imports. |
10 |
from lp.code.browser.bazaar import BazaarApplicationView |
14600.2.2
by Curtis Hovey
Moved webapp to lp.services. |
11 |
from lp.services.webapp.authorization import check_permission |
12 |
from lp.services.webapp.servers import LaunchpadTestRequest |
|
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
13 |
from lp.testing import ( |
14 |
ANONYMOUS, |
|
15 |
login, |
|
16 |
login_person, |
|
17 |
TestCaseWithFactory, |
|
18 |
)
|
|
14612.2.1
by William Grant
format-imports on lib/. So many imports. |
19 |
from lp.testing.layers import DatabaseFunctionalLayer |
8537.4.2
by Tim Penhey
Add a test to confirm the precaching of the permissions. |
20 |
|
21 |
||
22 |
class TestBazaarViewPreCacheLaunchpadPermissions(TestCaseWithFactory): |
|
23 |
"""Test the precaching of launchpad.View permissions."""
|
|
24 |
||
25 |
layer = DatabaseFunctionalLayer |
|
26 |
||
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
27 |
def getViewBranches(self, attribute): |
28 |
"""Create the view and get the branches for `attribute`."""
|
|
8537.4.2
by Tim Penhey
Add a test to confirm the precaching of the permissions. |
29 |
request = LaunchpadTestRequest() |
30 |
login(ANONYMOUS, request) |
|
31 |
view = BazaarApplicationView(object(), request) |
|
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
32 |
return getattr(view, attribute) |
33 |
||
34 |
def test_recently_registered(self): |
|
13931.4.6
by Ian Booth
Fix some more tests |
35 |
# Create a some private branches (stacked and unstacked) that the
|
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
36 |
# logged in user would not normally see.
|
37 |
private_branch = self.factory.makeAnyBranch(private=True) |
|
13931.4.6
by Ian Booth
Fix some more tests |
38 |
self.factory.makeAnyBranch(stacked_on=private_branch) |
39 |
branch = self.factory.makeAnyBranch() |
|
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
40 |
recent_branches = self.getViewBranches('recently_registered_branches') |
41 |
self.assertEqual(branch, recent_branches[0]) |
|
42 |
self.assertTrue(check_permission('launchpad.View', branch)) |
|
43 |
||
44 |
def makeBranchScanned(self, branch): |
|
45 |
"""Make the branch appear scanned."""
|
|
46 |
revision = self.factory.makeRevision() |
|
47 |
# Login an administrator so they can update the branch's details.
|
|
48 |
login('admin@canonical.com') |
|
49 |
branch.updateScannedDetails(revision, 1) |
|
50 |
||
51 |
def test_recently_changed(self): |
|
13931.4.6
by Ian Booth
Fix some more tests |
52 |
# Create a some private branches (stacked and unstacked) that the
|
53 |
# logged in user would not normally see.
|
|
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
54 |
private_branch = self.factory.makeAnyBranch(private=True) |
13931.4.6
by Ian Booth
Fix some more tests |
55 |
stacked_private_branch = self.factory.makeAnyBranch( |
56 |
stacked_on=private_branch) |
|
57 |
branch = self.factory.makeAnyBranch() |
|
58 |
self.makeBranchScanned(stacked_private_branch) |
|
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
59 |
self.makeBranchScanned(branch) |
60 |
recent_branches = self.getViewBranches('recently_changed_branches') |
|
61 |
self.assertEqual(branch, recent_branches[0]) |
|
62 |
self.assertTrue(check_permission('launchpad.View', branch)) |
|
63 |
||
64 |
def test_recently_imported(self): |
|
65 |
# Create an import branch that is stacked on a private branch that the
|
|
66 |
# logged in user would not normally see. This would never happen in
|
|
67 |
# reality, but hey, lets test the function actually works.
|
|
68 |
private_branch = self.factory.makeAnyBranch(private=True) |
|
69 |
# A new code import needs a real user as the sender for the outgoing
|
|
70 |
# email.
|
|
71 |
login_person(self.factory.makePerson()) |
|
13931.4.6
by Ian Booth
Fix some more tests |
72 |
private_code_import = self.factory.makeCodeImport() |
73 |
stacked_private_branch = private_code_import.branch |
|
74 |
naked_branch = removeSecurityProxy(stacked_private_branch) |
|
75 |
naked_branch.stacked_on = private_branch |
|
10454.4.19
by James Westby
Drop makeAnyCodeImport as makeCodeImport does that anyway. |
76 |
code_import = self.factory.makeCodeImport() |
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
77 |
branch = code_import.branch |
13931.4.6
by Ian Booth
Fix some more tests |
78 |
self.makeBranchScanned(stacked_private_branch) |
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
79 |
self.makeBranchScanned(branch) |
80 |
recent_branches = self.getViewBranches('recently_imported_branches') |
|
81 |
self.assertEqual(branch, recent_branches[0]) |
|
8537.4.2
by Tim Penhey
Add a test to confirm the precaching of the permissions. |
82 |
self.assertTrue(check_permission('launchpad.View', branch)) |