Reorganize smoke spec tests

pull/240/head
Alejandro Martínez 12 years ago
parent 68954ee1b0
commit 81fbbc32a1

@ -9,4 +9,3 @@ configuration.API_KEY = options['cartodb_api_key'] // API key
configuration.USER_EMAIL = options['cartodb_user_email'] // email
configuration.USER_PASSWORD = options['cartodb_user_password'] // password
module.exports = configuration

@ -0,0 +1,57 @@
/* Table utilities using the table endpoint */
module.exports = {
removeAllTables: function(api_key) {
this.api_key = api_key || configuration.API_KEY;
var url = configuration.BASE_URL + '/api/v1/tables';
var headers = {
'Host' : configuration.HOST,
'Accept' : 'application/json'
};
casper.thenOpen(tools.auth(url)).then(function() {
response = JSON.parse(casper.getPageContent());
for (table in response.tables) {
var table_id = response.tables[table]["id"];
var url = configuration.BASE_URL + '/api/v1/tables/' + table_id;
casper.log("Removing table "+table_id);
casper.thenOpen(tools.auth(url), {
method: 'delete',
data: JSON.stringify(payload),
headers: headers
});
};
})
},
Table: function(tableName, api_key) {
//Creates a random table name with the timestamp
this.tableName = tableName || "test" + Date.now();
this.api_key = api_key || configuration.API_KEY;
this.create = function() {
var payload = { name: this.tableName };
var url = configuration.BASE_URL + '/api/v1/tables';
var headers = {
'Host' : configuration.HOST,
'Content-Type': 'application/json',
'Accept' : 'application/json'
}
casper.thenOpen(tools.auth(url), {
method: 'post',
data: JSON.stringify(payload),
headers: headers
})
casper.then(function() {
response = JSON.parse(casper.getPageContent());
})
}
return this;
}
}

@ -0,0 +1,5 @@
module.exports = {
auth: function(url) {
return(url + "?api_key=" + configuration.API_KEY);
}
}

@ -1,8 +1,5 @@
var configuration = require("./spec/smokes/configuration")
var authenticated = function(url) {
return(url + "?api_key=" + configuration.API_KEY);
}
var tools = require("./spec/smokes/helpers/tools")
var url = configuration.BASE_URL + '/api/v1/viz';
var payload = {
@ -20,7 +17,7 @@ var headers = {
casper.echo(configuration.HOST)
casper.start()
casper.open(authenticated(url), {
casper.open(tools.auth(url), {
method: 'post',
data: JSON.stringify(payload),
headers: headers
@ -28,9 +25,11 @@ casper.open(authenticated(url), {
casper.then(function() {
response = JSON.parse(casper.getPageContent());
casper.test.assertEquals(response['name'], payload['name']);
require('utils').dump(response);
casper.test.assertHttpStatus(200, "Visualization creation should return 200");
casper.test.assertEquals(response['name'], payload['name'], "Visualization should be named as we wanted");
});
casper.run();
casper.run(function() {
casper.test.done(2);
});

@ -0,0 +1,47 @@
var configuration = require("./spec/smokes/configuration");
var tables = require("./spec/smokes/helpers/table");
var url = configuration.BASE_URL + '/api/v1/viz';
var payload = {
name: 'Visualization',
tables: ['table1', 'table2']
};
var headers = {
'Host' : configuration.HOST,
'Content-Type': 'application/json',
'Accept' : 'application/json'
};
casper.echo(configuration.HOST);
casper.start();
casper.thenOpen(tools.auth(url), {
method: 'post',
data: JSON.stringify(payload),
headers: headers
}).then(function() {
this.test.assertHttpStatus(404, "Create visualization from non-existing table should fail");
});
tables.removeAllTables();
var table = new tables.Table();
table.create();
casper.thenOpen(tools.auth(url), {
method: 'post',
data: JSON.stringify({name: 'Visualization', tables: [table.tableName]}),
headers: headers
})
casper.then(function() {
this.test.assertHttpStatus(200, "Visualization from new table should be created");
})
tables.removeAllTables();
casper.run(function() {
casper.test.done(2);
});
Loading…
Cancel
Save