Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Side by Side Diff: test/test_sandbox.js

Issue 9070043: Sandbox import/export w/File DnD support
Patch Set: Created 11 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 'use strict'; 1 'use strict';
2 2
3 (function() { 3 (function() {
4 4
5 describe('sandbox.ClientConnection', function() { 5 describe('sandbox.ClientConnection', function() {
6 var requires = ['juju-env-sandbox', 'json-stringify']; 6 var requires = ['juju-env-sandbox', 'json-stringify'];
7 var Y, sandboxModule, ClientConnection; 7 var Y, sandboxModule, ClientConnection;
8 8
9 before(function(done) { 9 before(function(done) {
10 Y = YUI(GlobalConfig).use(requires, function(Y) { 10 Y = YUI(GlobalConfig).use(requires, function(Y) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 assert.throws( 156 assert.throws(
157 conn.receive.bind(conn, {response: 42}), 157 conn.receive.bind(conn, {response: 42}),
158 'INVALID_STATE_ERR : Connection is closed.'); 158 'INVALID_STATE_ERR : Connection is closed.');
159 }); 159 });
160 160
161 }); 161 });
162 162
163 describe('sandbox.PyJujuAPI', function() { 163 describe('sandbox.PyJujuAPI', function() {
164 var requires = [ 164 var requires = [
165 'juju-env-sandbox', 'juju-tests-utils', 'juju-env-python', 165 'juju-env-sandbox', 'juju-tests-utils', 'juju-env-python',
166 'juju-models']; 166 'juju-models', 'promise'];
167 var Y, sandboxModule, ClientConnection, PyJujuAPI, environmentsModule, 167 var Y, sandboxModule, ClientConnection, PyJujuAPI, environmentsModule,
168 state, juju, client, env, utils, cleanups; 168 state, juju, client, env, utils, cleanups;
169 169
170 this.timeout(2000); // Long timeouts make async failures hard to detect. 170 this.timeout(2000); // Long timeouts make async failures hard to detect.
171 171
172 before(function(done) { 172 before(function(done) {
173 Y = YUI(GlobalConfig).use(requires, function(Y) { 173 Y = YUI(GlobalConfig).use(requires, function(Y) {
174 sandboxModule = Y.namespace('juju.environments.sandbox'); 174 sandboxModule = Y.namespace('juju.environments.sandbox');
175 environmentsModule = Y.namespace('juju.environments'); 175 environmentsModule = Y.namespace('juju.environments');
176 utils = Y.namespace('juju-tests.utils'); 176 utils = Y.namespace('juju-tests.utils');
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 request_id: 99 1362 request_id: 99
1363 }; 1363 };
1364 client.onmessage = function(received) { 1364 client.onmessage = function(received) {
1365 var parsed = Y.JSON.parse(received.data); 1365 var parsed = Y.JSON.parse(received.data);
1366 assert.equal(parsed.result, true); 1366 assert.equal(parsed.result, true);
1367 done(parsed.error); 1367 done(parsed.error);
1368 }; 1368 };
1369 client.open(); 1369 client.open();
1370 client.send(Y.JSON.stringify(op)); 1370 client.send(Y.JSON.stringify(op));
1371 }); 1371 });
1372 });
1372 1373
1374 /**
1375 * Utility method to turn _some_ callback
1376 * styled async methods into Promises.
1377 * It doesn't this by supplying a simple
gary.poster 2013/05/01 19:29:18 doesn't? :-)
bcsaller 2013/05/01 20:47:21 Oh no I didn't!
1378 * adaptor that can handle {error:...}
1379 * and {result: ... } returns.
1380 *
1381 * This callback is appended to any calling arguments
1382 *
1383 * @method P
1384 * @param {Object} context Calling context.
1385 * @param {String} methodName name of method on context to invoke.
1386 * @param {Arguments} arguments Additional arguments passed
1387 * to resolved method.
1388 * @return {Promise} a Y.Promise object.
1389 */
1390 function P(context, methodName) {
1391 var slice = Array.prototype.slice;
1392 var args = slice.call(arguments, 2);
1393 var method = context[methodName];
1394
1395 return Y.Promise(function(resolve, reject) {
1396 var resultHandler = function(result) {
1397 if (result.err || result.error) {
1398 reject(result.err || result.error);
1399 } else {
1400 resolve(result);
1401 }
1402 };
1403
1404 args.push(resultHandler);
1405 var result = method.apply(context, args);
1406 if (result !== undefined) {
1407 // The method returned right away.
1408 return resultHandler(result);
1409 }
1410 });
1411 }
1412
1413 it('should support export', function(done) {
1414 this.timeout(250);
1415
1416 client.open();
1417 // jshint is insisting on these 'new' prefixes.
gary.poster 2013/05/01 19:29:18 Because of initial capital letter, maybe? Maybe i
bcsaller 2013/05/01 20:47:21 That appears to have been it. Overcome by conventi
1418 new P(state, 'deploy', 'cs:wordpress')
1419 .then(new P(state, 'deploy', 'cs:mysql'))
1420 .then(new P(state, 'addRelation', 'wordpress:db', 'mysql:db'))
1421 .then(function() {
1422 client.onmessage = function(result) {
1423 var data = Y.JSON.parse(result.data).result;
1424 assert.equal(data.services[0].name, 'wordpress');
1425 done();
1426 };
1427 client.send(Y.JSON.stringify({op: 'exportEnvironment'}));
1428 });
1429 });
1430
1431 it('should support import', function(done) {
1432 this.timeout(300);
1433 var fixture = utils.loadFixture('data/sample-fakebackend.json', false);
1434
1435 client.onmessage = function() {
1436 client.onmessage = function(result) {
1437 var data = Y.JSON.parse(result.data).result;
1438 assert.isTrue(data);
1439
1440 // Verify that we can now an find expected entry
1441 // in the database.
1442 assert.isNotNull(state.db.services.getById('wordpress'));
1443
1444 var changes = state.nextChanges();
1445 // Validate the delta includes imported services.
1446 assert.include(changes.services, 'wordpress');
1447 assert.include(changes.services, 'mysql');
1448 // validate relation was added/updated.
1449 assert.include(changes.relations, 'relation-0');
1450 done();
1451 };
1452 client.send(Y.JSON.stringify({op: 'importEnvironment',
1453 envData: fixture}));
1454 };
1455 client.open();
1373 }); 1456 });
1374 1457
1375 }); 1458 });
1376 1459
1377 })(); 1460 })();
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b