~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
13668.1.29 by Curtis Hovey
removed duplicate setup/teardown from test_system_documentation.
12
from canonical.config import config
14600.2.2 by Curtis Hovey
Moved webapp to lp.services.
13
from lp.services.webapp.authorization import LaunchpadSecurityPolicy
14604.1.1 by Curtis Hovey
Separate test-authoring classes from test-running classes.
14
from lp.testing.layers import (
14578.4.4 by William Grant
format-imports.
15
    LaunchpadFunctionalLayer,
16
    LaunchpadZopelessLayer,
17
    )
18
from lp.services.testing import build_test_suite
14578.4.1 by William Grant
Move the remains of canonical.launchpad.testing to lp.testing.
19
from lp.testing.systemdocs import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
20
    LayeredDocFileSuite,
21
    setGlobs,
22
    setUp,
23
    tearDown,
24
    )
8356.1.5 by Leonard Richardson
Coverted the rest of the test_doc.py files in lp/ to use build_test_suite().
25
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
26
27
here = os.path.dirname(os.path.realpath(__file__))
28
29
13668.1.29 by Curtis Hovey
removed duplicate setup/teardown from test_system_documentation.
30
def branchscannerSetUp(test):
31
    """Setup the user for the branch scanner tests."""
32
    LaunchpadZopelessLayer.switchDbUser(config.branchscanner.dbuser)
33
    setUp(test)
34
35
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
36
def zopelessLaunchpadSecuritySetUp(test):
37
    """Set up a LaunchpadZopelessLayer test to use LaunchpadSecurityPolicy.
38
39
    To be able to use LaunchpadZopelessLayer.switchDbUser in a test, we need
40
    to run in the Zopeless environment. The Zopeless environment normally runs
14104.3.7 by Michael Hudson-Doyle
hunt down references to PermissiveSecurityPolicy
41
    using the LaunchpadPermissiveSecurityPolicy. If we want the test to cover
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
42
    functionality used in the webapp, it needs to use the
43
    LaunchpadSecurityPolicy.
44
    """
45
    setGlobs(test)
46
    test.old_security_policy = setSecurityPolicy(LaunchpadSecurityPolicy)
47
48
49
def zopelessLaunchpadSecurityTearDown(test):
50
    setSecurityPolicy(test.old_security_policy)
51
52
53
special = {
54
    'codeimport-machine.txt': LayeredDocFileSuite(
55
        '../doc/codeimport-machine.txt',
56
        setUp=zopelessLaunchpadSecuritySetUp,
57
        tearDown=zopelessLaunchpadSecurityTearDown,
58
        layer=LaunchpadZopelessLayer,
59
        ),
8590.1.4 by Tim Penhey
Tests pass\!
60
    'revision.txt': LayeredDocFileSuite(
61
        '../doc/revision.txt',
62
        setUp=branchscannerSetUp, tearDown=tearDown,
63
        layer=LaunchpadZopelessLayer
64
        ),
9260.3.2 by Jonathan Lange
Mark the two tests that actually need the librarian.
65
    'codeimport-result.txt': LayeredDocFileSuite(
66
        '../doc/codeimport-result.txt',
67
        setUp=setUp, tearDown=tearDown, layer=LaunchpadFunctionalLayer,
68
        ),
69
    'branch-merge-proposal-notifications.txt': LayeredDocFileSuite(
70
        '../doc/branch-merge-proposal-notifications.txt',
71
        setUp=setUp, tearDown=tearDown, layer=LaunchpadFunctionalLayer,
72
        ),
8138.1.2 by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing.
73
    }
74
75
76
def test_suite():
10129.5.8 by Francis J. Lacoste
Made the DatabaseFunctionalLayer the default for build_test_suite
77
    return build_test_suite(here, special)