diff --git a/test/acceptance/analysis/analysis-layers.js b/test/acceptance/analysis/analysis-layers.js new file mode 100644 index 00000000..5d5c5a0e --- /dev/null +++ b/test/acceptance/analysis/analysis-layers.js @@ -0,0 +1,107 @@ +require('../../support/test_helper'); + +var assert = require('../../support/assert'); +var TestClient = require('../../support/test-client'); +var dot = require('dot'); + +describe('analysis-layers', function() { + + + var multitypeStyleTemplate = dot.template([ + "#points['mapnik::geometry_type'=1] {", + " marker-fill-opacity: {{=it._opacity}};", + " marker-line-color: #FFF;", + " marker-line-width: 0.5;", + " marker-line-opacity: {{=it._opacity}};", + " marker-placement: point;", + " marker-type: ellipse;", + " marker-width: 8;", + " marker-fill: {{=it._color}};", + " marker-allow-overlap: true;", + "}", + "#lines['mapnik::geometry_type'=2] {", + " line-color: {{=it._color}};", + " line-width: 2;", + " line-opacity: {{=it._opacity}};", + "}", + "#polygons['mapnik::geometry_type'=3] {", + " polygon-fill: {{=it._color}};", + " polygon-opacity: {{=it._opacity}};", + " line-color: #FFF;", + " line-width: 0.5;", + " line-opacity: {{=it._opacity}};", + "}" + ].join('\n')); + + + function cartocss(color, opacity) { + return multitypeStyleTemplate({ + _color: color || '#F11810', + _opacity: Number.isFinite(opacity) ? opacity : 1 + }); + } + + function mapConfig(layers, dataviews, analysis) { + return { + version: '1.5.0', + layers: layers, + dataviews: dataviews || {}, + analyses: analysis || [] + }; + } + + var DEFAULT_MULTITYPE_STYLE = cartocss(); + + var TILE_ANALYSIS_TABLES = { z: 14, x: 8023, y: 6177 }; + + var useCases = [ + { + desc: 'basic source-id mapnik layer', + mapConfig: mapConfig( + [ + { + "type": "cartodb", + "options": { + "source": { + "id": "2570e105-7b37-40d2-bdf4-1af889598745" + }, + "cartocss": DEFAULT_MULTITYPE_STYLE, + "cartocss_version": "2.1.1", + "interactivity": [] + } + } + ], + {}, + [ + { + "id": "2570e105-7b37-40d2-bdf4-1af889598745", + "type": "source", + "params": { + "query": "select * from populated_places_simple_reduced" + } + } + ] + ), + tile: { z: 0, x: 0, y: 0 } + } + ]; + + useCases.forEach(function(useCase, imageIdx) { + it('should implement use case: "' + useCase.desc + '"', function(done) { + + var testClient = new TestClient(useCase.mapConfig, 1234); + + var tile = useCase.tile || TILE_ANALYSIS_TABLES; + + testClient.getTile(tile.z, tile.x, tile.y, function(err, res, image) { + assert.ok(!err, err); + + image.save('/tmp/tests/' + imageIdx + '---' + useCase.desc.replace(/\s/g, '-') + '.png'); + + assert.equal(image.width(), 256); + + testClient.drain(done); + }); + }); + }); +}); diff --git a/test/support/prepare_db.sh b/test/support/prepare_db.sh index f03d52de..928272fd 100755 --- a/test/support/prepare_db.sh +++ b/test/support/prepare_db.sh @@ -71,6 +71,9 @@ if test x"$PREPARE_PGSQL" = xyes; then dropdb "${TEST_DB}" createdb -Ttemplate_postgis -EUTF8 "${TEST_DB}" || die "Could not create test database" + curl -L -s https://raw.githubusercontent.com/CartoDB/camshaft/master/test/fixtures/cdb_analysis_catalog.sql -o sql/cdb_analysis_catalog.sql + cat sql/cdb_analysis_catalog.sql | psql -v ON_ERROR_STOP=1 ${TEST_DB} || exit 1 + cat sql/windshaft.test.sql sql/gadm4.sql | sed "s/:PUBLICUSER/${PUBLICUSER}/" | sed "s/:PUBLICPASS/${PUBLICPASS}/" | diff --git a/test/support/sql/windshaft.test.sql b/test/support/sql/windshaft.test.sql index cb8485b1..7ad07821 100644 --- a/test/support/sql/windshaft.test.sql +++ b/test/support/sql/windshaft.test.sql @@ -706,3 +706,5 @@ GRANT SELECT ON TABLE analysis_rent_listings TO :PUBLICUSER; -- PostgreSQL database dump complete -- +-- +GRANT SELECT, UPDATE, INSERT, DELETE ON cdb_analysis_catalog TO :TESTUSER;