This commit is contained in:
Raul Ochoa 2015-03-23 12:40:24 +01:00
parent 0321884795
commit 25e4e3bd33

View File

@ -1,11 +1,9 @@
var assert = require('../support/assert'); var assert = require('../support/assert');
var tests = module.exports = {};
var _ = require('underscore'); var _ = require('underscore');
var redis = require('redis'); var redis = require('redis');
var querystring = require('querystring'); var querystring = require('querystring');
var semver = require('semver'); var semver = require('semver');
var Step = require('step'); var step = require('step');
var http = require('http');
var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js'); var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js');
var helper = require(__dirname + '/../support/test_helper'); var helper = require(__dirname + '/../support/test_helper');
@ -30,15 +28,27 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
var default_style; var default_style;
if ( semver.satisfies(mapnik_version, '<2.1.0') ) { if ( semver.satisfies(mapnik_version, '<2.1.0') ) {
// 2.0.0 default // 2.0.0 default
default_style = '#<%= table %>{marker-fill: #FF6600;marker-opacity: 1;marker-width: 8;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}'; default_style = '#<%= table %>{marker-fill: #FF6600;marker-opacity: 1;marker-width: 8;marker-line-color: white;' +
'marker-line-width: 3;marker-line-opacity: 0.9;marker-placement: point;marker-type: ' +
'ellipse;marker-allow-overlap: true;}';
} }
else if ( semver.satisfies(mapnik_version, '<2.2.0') ) { else if ( semver.satisfies(mapnik_version, '<2.2.0') ) {
// 2.1.0 default // 2.1.0 default
default_style = '#<%= table %>[mapnik-geometry-type=1] {marker-fill: #FF6600;marker-opacity: 1;marker-width: 16;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}#<%= table %>[mapnik-geometry-type=2] {line-color:#FF6600; line-width:1; line-opacity: 0.7;}#<%= table %>[mapnik-geometry-type=3] {polygon-fill:#FF6600; polygon-opacity: 0.7; line-opacity:1; line-color: #FFFFFF;}'; default_style = '#<%= table %>[mapnik-geometry-type=1] {marker-fill: #FF6600;marker-opacity: 1;' +
'marker-width: 16;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;' +
'marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}' +
'#<%= table %>[mapnik-geometry-type=2] {line-color:#FF6600; line-width:1; line-opacity: 0.7;}' +
'#<%= table %>[mapnik-geometry-type=3] {polygon-fill:#FF6600; polygon-opacity: 0.7; line-opacity:1;' +
' line-color: #FFFFFF;}';
} }
else { else {
// 2.2.0+ default // 2.2.0+ default
default_style = '#<%= table %>["mapnik::geometry_type"=1] {marker-fill: #FF6600;marker-opacity: 1;marker-width: 16;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}#<%= table %>["mapnik::geometry_type"=2] {line-color:#FF6600; line-width:1; line-opacity: 0.7;}#<%= table %>["mapnik::geometry_type"=3] {polygon-fill:#FF6600; polygon-opacity: 0.7; line-opacity:1; line-color: #FFFFFF;}'; default_style = '#<%= table %>["mapnik::geometry_type"=1] {marker-fill: #FF6600;marker-opacity: 1;' +
'marker-width: 16;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;' +
'marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}' +
'#<%= table %>["mapnik::geometry_type"=2] {line-color:#FF6600; line-width:1; line-opacity: 0.7;}' +
'#<%= table %>["mapnik::geometry_type"=3] {polygon-fill:#FF6600; polygon-opacity: 0.7; line-opacity:1;' +
' line-color: #FFFFFF;}';
} }
// A couple of styles to use during testing // A couple of styles to use during testing
@ -58,7 +68,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
// TODO: I guess this should be a 404 instead... // TODO: I guess this should be a 404 instead...
test("get call to server returns 200", function(done){ test("get call to server returns 200", function(done){
Step( step(
function doGet() { function doGet() {
var next = this; var next = this;
assert.response(server, { assert.response(server, {
@ -121,7 +131,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
method: 'GET' method: 'GET'
},{ },{
status: 200, status: 200,
headers: { 'X-Cache-Channel': test_database+':my_table' }, headers: { 'X-Cache-Channel': test_database+':my_table' }
}, function(res) { }, function(res) {
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
assert.equal(parsed.style, _.template(default_style, {table: 'my_table'})); assert.equal(parsed.style, _.template(default_style, {table: 'my_table'}));
@ -186,7 +196,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
test("get'ing unrenderable style", function(done) { test("get'ing unrenderable style", function(done) {
var base_key = 'map_style|'+test_database+'|issue94'; var base_key = 'map_style|'+test_database+'|issue94';
var style = '#s{bogus}'; var style = '#s{bogus}';
Step( step(
function checkRedis() { function checkRedis() {
redis_client.keys(base_key+'*', this); redis_client.keys(base_key+'*', this);
}, },
@ -212,7 +222,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
assert.equal(parsed.style, style); assert.equal(parsed.style, style);
return null return null;
}, },
function finish(err) { function finish(err) {
done(err); done(err);
@ -260,7 +270,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
data: querystring.stringify({style: '#my_table3{'}) data: querystring.stringify({style: '#my_table3{'})
},{}, function(res) { },{}, function(res) {
assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body); assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body);
assert.ok( RegExp(/missing closing/i).test(res.body) ); assert.ok( new RegExp(/missing closing/i).test(res.body) );
done(); done();
}); });
}); });
@ -272,12 +282,12 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
headers: {host: 'localhost', 'Content-Type': 'application/x-www-form-urlencoded' }, headers: {host: 'localhost', 'Content-Type': 'application/x-www-form-urlencoded' },
data: querystring.stringify({style: '#my_table4{backgxxxxxround-color:#fff;foo:bar}'}) data: querystring.stringify({style: '#my_table4{backgxxxxxround-color:#fff;foo:bar}'})
},{ },{
status: 400, status: 400
}, function(res) { }, function(res) {
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
assert.equal(parsed.length, 2); assert.equal(parsed.length, 2);
assert.ok( RegExp(/Unrecognized rule: backgxxxxxround-color/).test(parsed[0]) ); assert.ok( new RegExp(/Unrecognized rule: backgxxxxxround-color/).test(parsed[0]) );
assert.ok( RegExp(/Unrecognized rule: foo/).test(parsed[1]) ); assert.ok( new RegExp(/Unrecognized rule: foo/).test(parsed[1]) );
done(); done();
}); });
}); });
@ -333,7 +343,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
url: '/tiles/my_table5/style', url: '/tiles/my_table5/style',
method: 'GET' method: 'GET'
},{ },{
status: 200, status: 200
}, function(res) { }, function(res) {
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
assert.equal(parsed.style, 'Map { background-color:#fff; }'); assert.equal(parsed.style, 'Map { background-color:#fff; }');
@ -420,7 +430,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.response(server, { assert.response(server, {
url: '/tiles/my_table5/style', url: '/tiles/my_table5/style',
method: 'DELETE', method: 'DELETE',
headers: {host: 'localhost'}, headers: {host: 'localhost'}
},{}, function(res) { },{}, function(res) {
// FIXME: should be 403 Forbidden // FIXME: should be 403 Forbidden
assert.equal(res.statusCode, 400, res.body); assert.equal(res.statusCode, 400, res.body);
@ -431,7 +441,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
url: '/tiles/my_table5/style?map_key=1234', url: '/tiles/my_table5/style?map_key=1234',
method: 'GET' method: 'GET'
},{ },{
status: 200, status: 200
}, function(res) { }, function(res) {
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
assert.equal(parsed.style, 'Map { background-color:#fff; }'); assert.equal(parsed.style, 'Map { background-color:#fff; }');
@ -447,7 +457,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.response(server, { assert.response(server, {
url: '/tiles/my_table5/style?map_key=1234', url: '/tiles/my_table5/style?map_key=1234',
method: 'DELETE', method: 'DELETE',
headers: {host: 'localhost'}, headers: {host: 'localhost'}
},{}, function(res) { },{}, function(res) {
assert.equal(res.statusCode, 200, res.body); assert.equal(res.statusCode, 200, res.body);
@ -481,7 +491,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.response(server, { assert.response(server, {
url: '/tiles/my_table5/style?api_key=1234', url: '/tiles/my_table5/style?api_key=1234',
method: 'DELETE', method: 'DELETE',
headers: {host: 'localhost'}, headers: {host: 'localhost'}
},{}, function(res) { },{}, function(res) {
assert.equal(res.statusCode, 200, res.body); assert.equal(res.statusCode, 200, res.body);
done(); done();
@ -518,7 +528,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
}); });
test("get'ing a json with default style and sql should return a constrained grid", function(done){ test("get'ing a json with default style and sql should return a constrained grid", function(done){
var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08'"}) var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08'"});
assert.response(server, { assert.response(server, {
headers: {host: 'localhost'}, headers: {host: 'localhost'},
url: '/tiles/gadm4/6/31/24.grid.json?' + sql, url: '/tiles/gadm4/6/31/24.grid.json?' + sql,
@ -601,7 +611,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
url: '/tiles/gadm4/6/31/24.png', url: '/tiles/gadm4/6/31/24.png',
method: 'GET' method: 'GET'
},{ },{
status: 200, status: 200
}, function(res) { }, function(res) {
var cc = res.headers['cache-control']; var cc = res.headers['cache-control'];
assert.ok(cc); assert.ok(cc);
@ -619,7 +629,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
url: '/tiles/gadm4/6/31/24.png?cache_policy=persist', url: '/tiles/gadm4/6/31/24.png?cache_policy=persist',
method: 'GET' method: 'GET'
},{ },{
status: 200, status: 200
}, function(res) { }, function(res) {
var cc = res.headers['cache-control']; var cc = res.headers['cache-control'];
assert.ok(cc); assert.ok(cc);
@ -653,7 +663,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
test("get'ing a tile with default style and complex sql should return a constrained image", function(done){ test("get'ing a tile with default style and complex sql should return a constrained image", function(done){
var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08' AND codccaa > 60"}) var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08' AND codccaa > 60"});
assert.response(server, { assert.response(server, {
headers: {host: 'localhost'}, headers: {host: 'localhost'},
url: '/tiles/gadm4/6/31/24.png?' + sql, url: '/tiles/gadm4/6/31/24.png?' + sql,
@ -666,7 +676,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
test("get'ing a tile with data from private table should succeed when authenticated", function(done){ test("get'ing a tile with data from private table should succeed when authenticated", function(done){
// NOTE: may fail if grainstore < 0.3.0 is used by Windshaft // NOTE: may fail if grainstore < 0.3.0 is used by Windshaft
var sql = querystring.stringify({sql: "SELECT * FROM test_table_private_1", map_key: 1234}) var sql = querystring.stringify({sql: "SELECT * FROM test_table_private_1", map_key: 1234});
assert.response(server, { assert.response(server, {
headers: {host: 'localhost'}, headers: {host: 'localhost'},
// NOTE: we encode a public table in the URL ! // NOTE: we encode a public table in the URL !
@ -681,7 +691,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/38 // See https://github.com/Vizzuality/Windshaft-cartodb/issues/38
test("get'ing a tile with data from private table should succeed when authenticated with api_key", function(done){ test("get'ing a tile with data from private table should succeed when authenticated with api_key", function(done){
// NOTE: may fail if grainstore < 0.3.0 is used by Windshaft // NOTE: may fail if grainstore < 0.3.0 is used by Windshaft
var sql = querystring.stringify({sql: "SELECT * FROM test_table_private_1", api_key: 1234}) var sql = querystring.stringify({sql: "SELECT * FROM test_table_private_1", api_key: 1234});
assert.response(server, { assert.response(server, {
headers: {host: 'localhost'}, headers: {host: 'localhost'},
url: '/tiles/gadm4/6/31/24.png?' + sql, url: '/tiles/gadm4/6/31/24.png?' + sql,
@ -730,7 +740,8 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
}); });
}); });
test("get'ing a tile with data from private table should fail when unauthenticated (uses old redis key)", function(done){ test("get'ing a tile with data from private table should fail when unauthenticated (uses old redis key)",
function(done) {
var sql = querystring.stringify({ var sql = querystring.stringify({
sql: "SELECT * FROM test_table_private_1", sql: "SELECT * FROM test_table_private_1",
cache_buster:3, cache_buster:3,
@ -764,11 +775,11 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
var ct = res.headers['content-type']; var ct = res.headers['content-type'];
assert.equal(ct, 'image/png'); assert.equal(ct, 'image/png');
assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png', IMAGE_EQUALS_TOLERANCE_PER_MIL, assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png',
function(err, similarity) { IMAGE_EQUALS_TOLERANCE_PER_MIL, function(err/*, similarity*/) {
if (err) throw err; if (err) throw err;
done(); done();
}); });
}); });
}); });
@ -777,7 +788,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
var style = querystring.stringify({style: test_style_black_200, style_version: '2.0.0'}); var style = querystring.stringify({style: test_style_black_200, style_version: '2.0.0'});
var backupDBHost = global.environment.postgres.host; var backupDBHost = global.environment.postgres.host;
global.environment.postgres.host = '6.6.6.6'; global.environment.postgres.host = '6.6.6.6';
Step ( step (
function() { function() {
var next = this; var next = this;
assert.response(server, { assert.response(server, {
@ -797,9 +808,9 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
'./test/fixtures/test_table_15_16046_12354_styled_black.png', './test/fixtures/test_table_15_16046_12354_styled_black.png',
IMAGE_EQUALS_TOLERANCE_PER_MIL, this); IMAGE_EQUALS_TOLERANCE_PER_MIL, this);
}, },
function checkImage(err, similarity) { function checkImage(err/*, similarity*/) {
if (err) throw err; if (err) throw err;
return null return null;
}, },
function finish(err) { function finish(err) {
global.environment.postgres.host = backupDBHost; global.environment.postgres.host = backupDBHost;
@ -813,13 +824,12 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
var style = querystring.stringify({style: test_style_black_200, style_version: '2.0.0'}); var style = querystring.stringify({style: test_style_black_200, style_version: '2.0.0'});
var backupDBPass = global.environment.postgres_auth_pass; var backupDBPass = global.environment.postgres_auth_pass;
global.environment.postgres_auth_pass = '<%= user_password %>'; global.environment.postgres_auth_pass = '<%= user_password %>';
Step ( step (
function() { function() {
var next = this; var next = this;
assert.response(server, { assert.response(server, {
headers: {host: 'cartodb250user'}, headers: {host: 'cartodb250user'},
url: '/tiles/test_table/15/16046/12354.png?' url: '/tiles/test_table/15/16046/12354.png?' + 'cache_buster=4.20&api_key=4321&' + style,
+ 'cache_buster=4.20&api_key=4321&' + style,
method: 'GET', method: 'GET',
encoding: 'binary' encoding: 'binary'
},{}, function(res){ },{}, function(res){
@ -834,9 +844,9 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
'./test/fixtures/test_table_15_16046_12354_styled_black.png', './test/fixtures/test_table_15_16046_12354_styled_black.png',
IMAGE_EQUALS_TOLERANCE_PER_MIL, this); IMAGE_EQUALS_TOLERANCE_PER_MIL, this);
}, },
function checkImage(err, similarity) { function checkImage(err/*, similarity*/) {
if (err) throw err; if (err) throw err;
return null return null;
}, },
function finish(err) { function finish(err) {
global.environment.postgres_auth_pass = backupDBPass; global.environment.postgres_auth_pass = backupDBPass;
@ -856,11 +866,11 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
var ct = res.headers['content-type']; var ct = res.headers['content-type'];
assert.equal(ct, 'image/png'); assert.equal(ct, 'image/png');
assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png', IMAGE_EQUALS_TOLERANCE_PER_MIL, assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png',
function(err, similarity) { IMAGE_EQUALS_TOLERANCE_PER_MIL, function(err/*, similarity*/) {
if (err) throw err; if (err) throw err;
done(); done();
}); });
}); });
}); });
@ -870,10 +880,9 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
style_version: '2.1.0', style_version: '2.1.0',
cache_buster: 5 cache_buster: 5
}; };
Step ( step (
function compressQuery () { function compressQuery () {
//console.log("Compressing starts"); //console.log("Compressing starts");
var next = this;
helper.lzma_compress_to_base64(JSON.stringify(qo), 1, this); helper.lzma_compress_to_base64(JSON.stringify(qo), 1, this);
}, },
function sendRequest(err, lzma) { function sendRequest(err, lzma) {
@ -893,10 +902,10 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
var ct = res.headers['content-type']; var ct = res.headers['content-type'];
assert.equal(ct, 'image/png'); assert.equal(ct, 'image/png');
assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png', IMAGE_EQUALS_TOLERANCE_PER_MIL, assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png',
function(err, similarity) { IMAGE_EQUALS_TOLERANCE_PER_MIL, function(err/*, similarity*/) {
next(err); next(err);
}); });
}, },
function finish(err) { function finish(err) {
done(err); done(err);
@ -906,8 +915,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
// See http://github.com/Vizzuality/Windshaft-cartodb/issues/57 // See http://github.com/Vizzuality/Windshaft-cartodb/issues/57
test("GET'ing a tile as anonymous with style set by POST", function(done){ test("GET'ing a tile as anonymous with style set by POST", function(done){
var style = querystring.stringify({style: test_style_black_210, style_version: '2.1.0'}); step (
Step (
function postStyle1() { function postStyle1() {
var next = this; var next = this;
assert.response(server, { assert.response(server, {
@ -934,7 +942,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
var ct = res.headers['content-type']; var ct = res.headers['content-type'];
assert.equal(ct, 'image/png'); assert.equal(ct, 'image/png');
assert.imageEqualsFile(res.body, './test/fixtures/blank.png', IMAGE_EQUALS_ZERO_TOLERANCE_PER_MIL, assert.imageEqualsFile(res.body, './test/fixtures/blank.png', IMAGE_EQUALS_ZERO_TOLERANCE_PER_MIL,
function(err, similarity) { function(err/*, similarity*/) {
if (err) next(err); if (err) next(err);
else next(); else next();
}); });
@ -954,7 +962,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
var ct = res.headers['content-type']; var ct = res.headers['content-type'];
assert.equal(ct, 'image/png'); assert.equal(ct, 'image/png');
assert.imageEqualsFile(res.body, './test/fixtures/blank.png', IMAGE_EQUALS_ZERO_TOLERANCE_PER_MIL, assert.imageEqualsFile(res.body, './test/fixtures/blank.png', IMAGE_EQUALS_ZERO_TOLERANCE_PER_MIL,
function(err, similarity) { function(err/*, similarity*/) {
if (err) next(err); if (err) next(err);
else next(); else next();
}); });
@ -990,12 +998,12 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
var ct = res.headers['content-type']; var ct = res.headers['content-type'];
assert.equal(ct, 'image/png'); assert.equal(ct, 'image/png');
assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png', IMAGE_EQUALS_TOLERANCE_PER_MIL, assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png',
function(err, similarity) { IMAGE_EQUALS_TOLERANCE_PER_MIL, function(err/*, similarity*/) {
// NOTE: we expect them to be EQUAL here // NOTE: we expect them to be EQUAL here
if (err) { next(err); return; } if (err) { next(err); return; }
next(); next();
}); });
}); });
}, },
// Delete the style // Delete the style
@ -1027,12 +1035,13 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
var ct = res.headers['content-type']; var ct = res.headers['content-type'];
assert.equal(ct, 'image/png'); assert.equal(ct, 'image/png');
assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png', IMAGE_EQUALS_TOLERANCE_PER_MIL, assert.imageEqualsFile(res.body, './test/fixtures/test_table_15_16046_12354_styled_black.png',
function(err, similarity) { IMAGE_EQUALS_TOLERANCE_PER_MIL, function(err/*, similarity*/) {
// NOTE: we expect them to be different here // NOTE: we expect them to be different here
if (err) next(); if (err) next();
else next(new Error('Last posted style still in effect after delete')); else next(new Error('Last posted style still in effect after delete'));
}); }
);
}); });
}, },
function finish(err) { function finish(err) {
@ -1043,14 +1052,13 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
test("uses sqlapi to figure source data of query", function(done){ test("uses sqlapi to figure source data of query", function(done){
var qo = { var qo = {
sql: "SELECT g.cartodb_id, g.codineprov, t.the_geom_webmercator " sql: "SELECT g.cartodb_id, g.codineprov, t.the_geom_webmercator" +
+ "FROM gadm4 g, test_table t " " FROM gadm4 g, test_table t" +
+ "WHERE g.cartodb_id = t.cartodb_id", " WHERE g.cartodb_id = t.cartodb_id",
map_key: 1234 map_key: 1234
}; };
var sqlapi; step(
Step( function sendRequest() {
function sendRequest(err) {
var next = this; var next = this;
assert.response(server, { assert.response(server, {
headers: {host: 'localhost'}, headers: {host: 'localhost'},
@ -1087,9 +1095,8 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
sql: "SELECT * from gadm4", sql: "SELECT * from gadm4",
map_key: 1234 map_key: 1234
}; };
var sqlapi; step(
Step( function sendRequest() {
function sendRequest(err) {
var next = this; var next = this;
assert.response(server, { assert.response(server, {
headers: {host: 'localhost'}, headers: {host: 'localhost'},
@ -1102,7 +1109,7 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
var last_request = sqlapi_server.getLastRequest(); var last_request = sqlapi_server.getLastRequest();
assert.ok(last_request); assert.ok(last_request);
var host = last_request.headers['host']; var host = last_request.headers.host;
assert.ok(host); assert.ok(host);
assert.equal(last_request.method, 'GET'); assert.equal(last_request.method, 'GET');
assert.equal(host, 'localhost.donot_look_this_up'); assert.equal(host, 'localhost.donot_look_this_up');
@ -1118,15 +1125,13 @@ suite('server:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function() {
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
test("requests to skip cache on sqlapi error", function(done){ test("requests to skip cache on sqlapi error", function(done){
var qo = { var qo = {
sql: "SELECT g.cartodb_id, g.codineprov, t.the_geom_webmercator " sql: "SELECT g.cartodb_id, g.codineprov, t.the_geom_webmercator, 'SQLAPIERROR' is not null" +
+ ", 'SQLAPIERROR' is not null " " FROM gadm4 g, test_table t" +
+ "FROM gadm4 g, test_table t " " WHERE g.cartodb_id = t.cartodb_id",
+ "WHERE g.cartodb_id = t.cartodb_id",
map_key: 1234 map_key: 1234
}; };
var sqlapi; step(
Step( function sendRequest() {
function sendRequest(err) {
var next = this; var next = this;
assert.response(server, { assert.response(server, {
headers: {host: 'localhost'}, headers: {host: 'localhost'},