~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/tests/test_yuixhr_fixture.py

  • Committer: Gary Poster
  • Date: 2011-09-20 22:33:07 UTC
  • mto: This revision was merged to the branch mainline in revision 14015.
  • Revision ID: gary.poster@canonical.com-20110920223307-zt1kr1px2ixjg9mn
Add yui xhr integration test support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
13
from lp.testing.yuixhr import (
 
14
    login_as_person,
 
15
    make_suite,
 
16
    setup,
 
17
    )
 
18
from lp.testing.factory import LaunchpadObjectFactory
 
19
 
 
20
# The following are the fixtures needed by the tests.
 
21
 
 
22
# We use this variable for test results.
 
23
_received = []
 
24
 
 
25
@setup
 
26
def baseline(request, data):
 
27
    data['hello'] = 'world'
 
28
 
 
29
@baseline.add_cleanup
 
30
def baseline(request, data):
 
31
    global _received
 
32
    _received.append(('baseline', request, data))
 
33
 
 
34
@setup
 
35
def second(request, data):
 
36
    data['second'] = 'here'
 
37
@second.add_cleanup
 
38
def second(request, data):
 
39
    global _received
 
40
    _received.append(('second', request, data))
 
41
 
 
42
test_value = None
 
43
 
 
44
@setup
 
45
def faux_database_thing(request, data):
 
46
    global test_value
 
47
    data['previous_value'] = test_value
 
48
    test_value = None
 
49
@faux_database_thing.add_cleanup
 
50
def faux_database_thing(request, data):
 
51
    global test_value
 
52
    test_value = 'teardown was called'
 
53
 
 
54
@setup
 
55
def show_teardown_value(request, data):
 
56
    data['setup_data'] = 'Hello world'
 
57
@show_teardown_value.add_cleanup
 
58
def show_teardown_value(request, data):
 
59
    global test_value
 
60
    test_value = data
 
61
 
 
62
factory = LaunchpadObjectFactory()
 
63
 
 
64
@setup
 
65
def make_product(request, data):
 
66
    data['product'] = factory.makeProduct()
 
67
 
 
68
@setup
 
69
def make_product_loggedin(request, data):
 
70
    data['person'] = factory.makeAdministrator()
 
71
    login_person(data['person'])
 
72
    data['product'] = factory.makeProduct(owner=data['person'])
 
73
 
 
74
@setup
 
75
def naughty_make_product(request, data):
 
76
    data['product'] = removeSecurityProxy(factory.makeProduct())
 
77
 
 
78
@setup
 
79
def teardown_will_fail(request, data):
 
80
    pass
 
81
@teardown_will_fail.add_cleanup
 
82
def teardown_will_fail(request, data):
 
83
    raise RuntimeError('rutebegas')
 
84
 
 
85
@setup
 
86
def login_as_admin(request, data):
 
87
    data['user'] = factory.makeAdministrator()
 
88
    login_as_person(data['user'])
 
89
 
 
90
def test_suite():
 
91
    return make_suite(__name__)