Replaces affected tables test with multilayer one

This commit is contained in:
Raul Ochoa 2015-03-30 15:27:40 +02:00
parent 85804f9854
commit b599e67c35
2 changed files with 34 additions and 44 deletions

View File

@ -3,6 +3,7 @@ var testHelper = require(__dirname + '/../support/test_helper');
var assert = require('../support/assert');
var redis = require('redis');
var _ = require('underscore');
var CartodbWindshaft = require('../../lib/cartodb/cartodb_windshaft');
var serverOptions = require('../../lib/cartodb/server_options')();
@ -156,7 +157,6 @@ describe('tests from old api translated to multilayer', function() {
});
it("creating a layergroup from lzma param", function(done){
var params = {
config: JSON.stringify(singleLayergroupConfig(pointSql, '#layer { marker-fill:red; }'))
};
@ -187,8 +187,7 @@ describe('tests from old api translated to multilayer', function() {
});
});
it("creating a layergroup from lzma param, invalid json input", function(done){
it("creating a layergroup from lzma param, invalid json input", function(done) {
var params = {
config: 'WADUS'
};
@ -219,4 +218,36 @@ describe('tests from old api translated to multilayer', function() {
});
});
it("uses queries postgresql to figure affected tables in query", function(done) {
var tableName = 'gadm4';
var expectedCacheChannel = _.template('<%= databaseName %>:public.<%= tableName %>', {
databaseName: _.template(global.environment.postgres_auth_user, {user_id:1}) + '_db',
tableName: tableName
});
var layergroup = singleLayergroupConfig('select * from ' + tableName, '#gadm4 { marker-fill: red; }');
assert.response(server,
{
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
method: 'GET',
headers: {
host: 'localhost'
}
},
{
status: 200
},
function(res) {
var parsed = JSON.parse(res.body);
assert.ok(parsed.layergroupid);
assert.ok(res.headers.hasOwnProperty('x-cache-channel'));
assert.equal(res.headers['x-cache-channel'], expectedCacheChannel);
done();
}
);
});
});

View File

@ -63,47 +63,6 @@ suite('server', function() {
suite.skip('server old_api', function() {
var test_database = _.template(global.environment.postgres_auth_user, {user_id:1}) + '_db';
test("uses sqlapi to figure source data of query", function(done){
var qo = {
sql: "SELECT g.cartodb_id, g.codineprov, t.the_geom_webmercator" +
" FROM gadm4 g, test_table t" +
" WHERE g.cartodb_id = t.cartodb_id",
map_key: 1234
};
step(
function sendRequest() {
var next = this;
assert.response(server, {
headers: {host: 'localhost'},
url: '/tiles/gadm4/6/31/24.png?' + querystring.stringify(qo),
method: 'GET'
},{}, function(res) { next(null, res); });
},
function checkResponse(err, res) {
if ( err ) throw err;
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
var ct = res.headers['content-type'];
assert.equal(ct, 'image/png');
var cc = res.headers['x-cache-channel'];
assert(cc, 'Missing X-Cache-Channel');
var dbname = test_database;
assert.equal(cc.substring(0, dbname.length), dbname);
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
var jsonquery = cc.substring(dbname.length + 1);
var sentquery = JSON.parse(jsonquery);
assert.equal(sentquery.api_key, qo.map_key);
assert.equal(sentquery.q, 'SELECT CDB_QueryTables($windshaft$' + qo.sql + '$windshaft$)');
}
return null;
},
function finish(err) {
done(err);
}
);
});
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
test("requests to skip cache on sqlapi error", function(done){
var qo = {