~launchpad-pqm/launchpad/devel

13992.1.1 by Gary Poster
Add yui xhr integration test support.
1
# Copyright 2011 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""These are yui appserver fixtures for the yui appserver test code's tests.
5
"""
6
7
__metaclass__ = type
8
__all__ = []
9
10
from zope.security.proxy import removeSecurityProxy
11
12
from lp.testing import login_person
14550.1.1 by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad
13
from lp.testing.factory import LaunchpadObjectFactory
13992.1.1 by Gary Poster
Add yui xhr integration test support.
14
from lp.testing.yuixhr import (
15
    login_as_person,
16
    make_suite,
17
    setup,
18
    )
19
20
# The following are the fixtures needed by the tests.
21
22
# We use this variable for test results.
23
_received = []
24
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
25
13992.1.1 by Gary Poster
Add yui xhr integration test support.
26
@setup
27
def baseline(request, data):
28
    data['hello'] = 'world'
29
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
30
13992.1.1 by Gary Poster
Add yui xhr integration test support.
31
@baseline.add_cleanup
32
def baseline(request, data):
33
    global _received
34
    _received.append(('baseline', request, data))
35
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
36
13992.1.1 by Gary Poster
Add yui xhr integration test support.
37
@setup
38
def second(request, data):
39
    data['second'] = 'here'
40
@second.add_cleanup
41
def second(request, data):
42
    global _received
43
    _received.append(('second', request, data))
44
45
test_value = None
46
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
47
13992.1.1 by Gary Poster
Add yui xhr integration test support.
48
@setup
49
def faux_database_thing(request, data):
50
    global test_value
51
    data['previous_value'] = test_value
52
    test_value = None
53
@faux_database_thing.add_cleanup
54
def faux_database_thing(request, data):
55
    global test_value
56
    test_value = 'teardown was called'
57
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
58
13992.1.1 by Gary Poster
Add yui xhr integration test support.
59
@setup
60
def show_teardown_value(request, data):
61
    data['setup_data'] = 'Hello world'
62
@show_teardown_value.add_cleanup
63
def show_teardown_value(request, data):
64
    global test_value
65
    test_value = data
66
67
factory = LaunchpadObjectFactory()
68
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
69
13992.1.1 by Gary Poster
Add yui xhr integration test support.
70
@setup
71
def make_product(request, data):
72
    data['product'] = factory.makeProduct()
73
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
74
13992.1.1 by Gary Poster
Add yui xhr integration test support.
75
@setup
76
def make_product_loggedin(request, data):
77
    data['person'] = factory.makeAdministrator()
78
    login_person(data['person'])
79
    data['product'] = factory.makeProduct(owner=data['person'])
80
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
81
13992.1.1 by Gary Poster
Add yui xhr integration test support.
82
@setup
83
def naughty_make_product(request, data):
84
    data['product'] = removeSecurityProxy(factory.makeProduct())
85
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
86
13992.1.1 by Gary Poster
Add yui xhr integration test support.
87
@setup
88
def teardown_will_fail(request, data):
89
    pass
90
@teardown_will_fail.add_cleanup
91
def teardown_will_fail(request, data):
92
    raise RuntimeError('rutebegas')
93
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
94
13992.1.1 by Gary Poster
Add yui xhr integration test support.
95
@setup
96
def login_as_admin(request, data):
97
    data['user'] = factory.makeAdministrator()
98
    login_as_person(data['user'])
99
13992.1.2 by Gary Poster
clean up some lint and make tests pass by adding file I thought was unnecessary.
100
13992.1.1 by Gary Poster
Add yui xhr integration test support.
101
def test_suite():
102
    return make_suite(__name__)