2015-06-01 19:20:51 +08:00
|
|
|
var app = require(global.settings.app_root + '/app/controllers/app')();
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var sqlite = require('sqlite3');
|
|
|
|
|
|
|
|
describe.only('spatialite query',function(){
|
|
|
|
|
2015-06-01 21:16:05 +08:00
|
|
|
it('returns a valid sqlite database', function(done){
|
2015-06-01 19:20:51 +08:00
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4%20LIMIT%201&format=spatialite',
|
|
|
|
headers: {host: 'vizzuality.cartodb.com'},
|
|
|
|
method: 'GET'
|
|
|
|
},{ }, function(res) {
|
2015-06-01 21:16:05 +08:00
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
assert.equal(res.headers["content-type"], "application/x-sqlite3; charset=utf-8");
|
|
|
|
var db = new sqlite.Database(res.body);
|
|
|
|
var qr = db.get("PRAGMA database_list", function(err){
|
|
|
|
assert.equal(err, null);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
assert.notEqual(qr, undefined);
|
2015-06-01 19:20:51 +08:00
|
|
|
});
|
2015-06-01 21:16:05 +08:00
|
|
|
|
2015-06-01 19:20:51 +08:00
|
|
|
});
|
2015-06-01 21:16:05 +08:00
|
|
|
|
|
|
|
it('different file name', function(done){
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4%20LIMIT%201&format=spatialite&filename=manolo',
|
|
|
|
headers: {host: 'vizzuality.cartodb.com'},
|
|
|
|
method: 'GET'
|
|
|
|
},{ }, function(res) {
|
|
|
|
assert.equal(res.headers["content-type"], "application/x-sqlite3; charset=utf-8");
|
|
|
|
assert.notEqual(res.headers["content-disposition"].indexOf("manolo.sqlite"), -1);
|
2015-06-01 19:20:51 +08:00
|
|
|
done();
|
|
|
|
});
|
2015-06-01 21:16:05 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('gets database schema', function(done){
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4%20LIMIT%201&format=spatialite',
|
|
|
|
headers: {host: 'vizzuality.cartodb.com'},
|
|
|
|
method: 'GET'
|
|
|
|
},{ }, function(res) {
|
|
|
|
var db = new sqlite.Database(res.body);
|
|
|
|
var schemaQuery = "SELECT name, sql FROM sqlite_master WHERE type='table' ORDER BY name";
|
|
|
|
var qr = db.get(schemaQuery, function(err){
|
|
|
|
assert.equal(err, null);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
assert.notEqual(qr, undefined);
|
|
|
|
});
|
2015-06-01 19:20:51 +08:00
|
|
|
});
|
|
|
|
});
|