parent
68954ee1b0
commit
81fbbc32a1
@ -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);
|
||||
}
|
||||
}
|
@ -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…
Reference in new issue