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 |
|
10 |
from canonical.launchpad.webapp.authorization import check_permission |
|
11 |
from canonical.launchpad.webapp.servers import LaunchpadTestRequest |
|
11666.3.5
by Curtis Hovey
Import layers from canonical.testing.layers. |
12 |
from canonical.testing.layers import DatabaseFunctionalLayer |
8537.4.2
by Tim Penhey
Add a test to confirm the precaching of the permissions. |
13 |
from lp.code.browser.bazaar import BazaarApplicationView |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
14 |
from lp.testing import ( |
15 |
ANONYMOUS, |
|
16 |
login, |
|
17 |
login_person, |
|
18 |
TestCaseWithFactory, |
|
19 |
)
|
|
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): |
|
35 |
# Create a branches that is stacked on a private branch that the
|
|
36 |
# logged in user would not normally see.
|
|
37 |
private_branch = self.factory.makeAnyBranch(private=True) |
|
38 |
branch = self.factory.makeAnyBranch(stacked_on=private_branch) |
|
39 |
recent_branches = self.getViewBranches('recently_registered_branches') |
|
40 |
self.assertEqual(branch, recent_branches[0]) |
|
41 |
self.assertTrue(check_permission('launchpad.View', branch)) |
|
42 |
||
43 |
def makeBranchScanned(self, branch): |
|
44 |
"""Make the branch appear scanned."""
|
|
45 |
revision = self.factory.makeRevision() |
|
46 |
# Login an administrator so they can update the branch's details.
|
|
47 |
login('admin@canonical.com') |
|
48 |
branch.updateScannedDetails(revision, 1) |
|
49 |
||
50 |
def test_recently_changed(self): |
|
51 |
# Create a recently changed branch that is stacked on a private branch
|
|
52 |
# that the logged in user would not normally see.
|
|
53 |
private_branch = self.factory.makeAnyBranch(private=True) |
|
54 |
branch = self.factory.makeAnyBranch(stacked_on=private_branch) |
|
55 |
self.makeBranchScanned(branch) |
|
56 |
recent_branches = self.getViewBranches('recently_changed_branches') |
|
57 |
self.assertEqual(branch, recent_branches[0]) |
|
58 |
self.assertTrue(check_permission('launchpad.View', branch)) |
|
59 |
||
60 |
def test_recently_imported(self): |
|
61 |
# Create an import branch that is stacked on a private branch that the
|
|
62 |
# logged in user would not normally see. This would never happen in
|
|
63 |
# reality, but hey, lets test the function actually works.
|
|
64 |
private_branch = self.factory.makeAnyBranch(private=True) |
|
65 |
# A new code import needs a real user as the sender for the outgoing
|
|
66 |
# email.
|
|
67 |
login_person(self.factory.makePerson()) |
|
10454.4.19
by James Westby
Drop makeAnyCodeImport as makeCodeImport does that anyway. |
68 |
code_import = self.factory.makeCodeImport() |
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
69 |
branch = code_import.branch |
8537.4.6
by Tim Penhey
Updates following review. |
70 |
removeSecurityProxy(branch).stacked_on = private_branch |
8537.4.5
by Tim Penhey
Get tests for the various BazaarView methods. |
71 |
self.makeBranchScanned(branch) |
72 |
recent_branches = self.getViewBranches('recently_imported_branches') |
|
73 |
self.assertEqual(branch, recent_branches[0]) |
|
8537.4.2
by Tim Penhey
Add a test to confirm the precaching of the permissions. |
74 |
self.assertTrue(check_permission('launchpad.View', branch)) |