~launchpad-pqm/launchpad/devel

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).
3
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
4
"""
5
Run the doctests and pagetests.
6
"""
7
8
import os
9
8356.1.10 by Leonard Richardson
Fix test failures.
10
from zope.security.management import setSecurityPolicy
11
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
12
from canonical.launchpad.ftests.test_system_documentation import (
13
    branchscannerSetUp,
14
    )
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
15
from canonical.launchpad.testing.systemdocs import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
16
    LayeredDocFileSuite,
17
    setGlobs,
18
    setUp,
19
    tearDown,
20
    )
8356.1.10 by Leonard Richardson
Fix test failures.
21
from canonical.launchpad.webapp.authorization import LaunchpadSecurityPolicy
11666.3.5 by Curtis Hovey
Import layers from canonical.testing.layers.
22
from canonical.testing.layers import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
23
    LaunchpadFunctionalLayer,
24
    LaunchpadZopelessLayer,
25
    )
8356.1.5 by Leonard Richardson
Coverted the rest of the test_doc.py files in lp/ to use build_test_suite().
26
from lp.services.testing import build_test_suite
27
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
28
29
here = os.path.dirname(os.path.realpath(__file__))
30
31
32
def zopelessLaunchpadSecuritySetUp(test):
33
    """Set up a LaunchpadZopelessLayer test to use LaunchpadSecurityPolicy.
34
35
    To be able to use LaunchpadZopelessLayer.switchDbUser in a test, we need
36
    to run in the Zopeless environment. The Zopeless environment normally runs
37
    using the PermissiveSecurityPolicy. If we want the test to cover
38
    functionality used in the webapp, it needs to use the
39
    LaunchpadSecurityPolicy.
40
    """
41
    setGlobs(test)
42
    test.old_security_policy = setSecurityPolicy(LaunchpadSecurityPolicy)
43
44
45
def zopelessLaunchpadSecurityTearDown(test):
46
    setSecurityPolicy(test.old_security_policy)
47
48
49
special = {
50
    'codeimport-machine.txt': LayeredDocFileSuite(
51
        '../doc/codeimport-machine.txt',
52
        setUp=zopelessLaunchpadSecuritySetUp,
53
        tearDown=zopelessLaunchpadSecurityTearDown,
54
        layer=LaunchpadZopelessLayer,
55
        ),
8590.1.4 by Tim Penhey
Tests pass\!
56
    'revision.txt': LayeredDocFileSuite(
57
        '../doc/revision.txt',
58
        setUp=branchscannerSetUp, tearDown=tearDown,
59
        layer=LaunchpadZopelessLayer
60
        ),
9260.3.2 by Jonathan Lange
Mark the two tests that actually need the librarian.
61
    'codeimport-result.txt': LayeredDocFileSuite(
62
        '../doc/codeimport-result.txt',
63
        setUp=setUp, tearDown=tearDown, layer=LaunchpadFunctionalLayer,
64
        ),
65
    'branch-merge-proposal-notifications.txt': LayeredDocFileSuite(
66
        '../doc/branch-merge-proposal-notifications.txt',
67
        setUp=setUp, tearDown=tearDown, layer=LaunchpadFunctionalLayer,
68
        ),
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
69
    }
70
71
72
def test_suite():
10129.5.8 by Francis J. Lacoste
Made the DatabaseFunctionalLayer the default for build_test_suite
73
    return build_test_suite(here, special)