3
filter: 'raw', combine: false, fetchCSS: false
4
}).use('test', 'console', 'json', 'cookie', 'lp.testing.serverfixture',
7
var suite = new Y.Test.Suite("lp.testing.yuixhr Tests");
8
var module = Y.lp.testing.serverfixture;
12
* Test setup and teardown of yuixhr fixtures, and the asociated JS module.
14
suite.add(new Y.Test.Case({
15
name: 'Fixture setup and teardown tests',
17
tearDown: function() {
18
delete this._lp_fixture_setups;
19
delete this._lp_fixture_data;
24
test_bad_http_call_raises_error: true,
25
test_bad_http_teardown_raises_error: true
29
test_simple_setup: function() {
30
var data = module.setup(this, 'baseline');
31
Y.ArrayAssert.itemsAreEqual(['baseline'], this._lp_fixture_setups);
32
Y.ObjectAssert.areEqual({'hello': 'world'}, data);
33
Y.ObjectAssert.areEqual({'hello': 'world'}, this._lp_fixture_data);
34
module.teardown(this); // Just for cleanliness, not for testing.
37
test_setup_with_multiple_fixtures: function() {
38
var data = module.setup(this, 'baseline', 'second');
39
Y.ArrayAssert.itemsAreEqual(
40
['baseline', 'second'], this._lp_fixture_setups);
41
Y.ObjectAssert.areEqual({'hello': 'world', 'second': 'here'}, data);
42
Y.ObjectAssert.areEqual(
43
{'hello': 'world', 'second': 'here'}, this._lp_fixture_data);
44
module.teardown(this); // Just for cleanliness, not for testing.
47
test_multiple_setup_calls: function() {
48
var data = module.setup(this, 'baseline');
49
var second_data = module.setup(this, 'second');
50
Y.ArrayAssert.itemsAreEqual(
51
['baseline', 'second'], this._lp_fixture_setups);
52
Y.ObjectAssert.areEqual({'hello': 'world'}, data);
53
Y.ObjectAssert.areEqual({'second': 'here'}, second_data);
54
Y.ObjectAssert.areEqual(
55
{'hello': 'world', 'second': 'here'}, this._lp_fixture_data);
56
module.teardown(this); // Just for cleanliness, not for testing.
59
test_teardown_clears_attributes: function() {
60
var data = module.setup(this, 'baseline');
61
module.teardown(this);
62
Y.Assert.isUndefined(this._lp_fixture_setups);
63
Y.Assert.isUndefined(this._lp_fixture_data);
66
test_bad_http_call_raises_error: function() {
67
module.setup(this, 'does not exist');
70
test_bad_http_call_shows_traceback: function() {
71
try {module.setup(this, 'does not exist');}
73
Y.Assert.areEqual('Traceback (most recent call last)',
74
err.message.substring(0, 33));
78
test_bad_http_teardown_raises_error: function() {
79
module.setup(this, 'teardown_will_fail');
80
module.teardown(this);
83
test_bad_http_teardown_shows_traceback: function() {
84
module.setup(this, 'teardown_will_fail');
85
try {module.teardown(this);}
87
Y.Assert.areEqual('Traceback (most recent call last)',
88
err.message.substring(0, 33));
92
test_setup_called_twice_with_same_fixture: function() {
93
// This is arguably not desirable, but it is the way it works now.
94
var data = module.setup(this, 'baseline');
95
var second_data = module.setup(this, 'baseline');
96
Y.ArrayAssert.itemsAreEqual(
97
['baseline', 'baseline'], this._lp_fixture_setups);
98
Y.ObjectAssert.areEqual({'hello': 'world'}, data);
99
Y.ObjectAssert.areEqual({'hello': 'world'}, second_data);
100
Y.ObjectAssert.areEqual(
101
{'hello': 'world'}, this._lp_fixture_data);
102
module.teardown(this); // Just for cleanliness, not for testing.
105
test_teardown: function() {
106
module.setup(this, 'faux_database_thing');
107
module.teardown(this);
108
var data = module.setup(this, 'faux_database_thing');
109
Y.ObjectAssert.areEqual(
110
{'previous_value': 'teardown was called'}, data);
113
test_teardown_receives_data_from_setup: function() {
114
module.setup(this, 'show_teardown_value');
115
module.teardown(this);
116
var data = module.setup(this, 'faux_database_thing');
117
Y.ObjectAssert.areEqual(
118
{'setup_data': 'Hello world'}, data.previous_value);
121
test_teardown_resets_database: function() {
122
var data = module.setup(this, 'make_product');
124
data.product.self_link,
127
Y.Assert.areEqual(200, response.status);
128
module.teardown(this);
130
data.product.self_link,
133
Y.Assert.areEqual(404, response.status);
136
test_login_works: function() {
137
// Make sure the session cookie is cleared out at start of test.
138
Y.Cookie.remove('launchpad_tests');
140
var data = module.setup(this, 'make_product');
141
// We can't see this because only Launchpad and Registry admins can.
143
'tag:launchpad.net:2008:redacted', data.product.project_reviewed);
144
// Login as a Launchpad admin.
145
module.setup(this, 'login_as_admin');
146
// The session cookie is set.
147
Y.Assert.isTrue(Y.Cookie.exists('launchpad_tests'));
148
// We can now see things that only a Launchpad admin can see.
150
data.product.self_link,
151
{sync: true, headers: {Accept: 'application/json'}}
153
var result = Y.JSON.parse(response.responseText);
154
Y.Assert.areEqual(false, result.project_reviewed);
155
module.teardown(this);
156
// After teardown, the database is cleared out, as shown in other
157
// tests, so we are not logged in practically--the user is gone--but
158
// also our session cookie is gone.
159
Y.Assert.isFalse(Y.Cookie.exists('launchpad_tests'));
163
var handle_complete = function(data) {
164
window.status = '::::' + Y.JSON.stringify(data);
166
Y.Test.Runner.on('complete', handle_complete);
167
Y.Test.Runner.add(suite);
169
var console = new Y.Console({newestOnTop: false});
171
Y.on('domready', function() {
172
console.render('#log');