From a2d0163ece1f9431da687f13978c99d9c07ce0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Tue, 8 May 2018 12:51:52 +0200 Subject: [PATCH] ensuring works with sql parameter in query string --- test/acceptance/copy-endpoints.js | 24 +++++++++++++++++++++--- test/support/sql/test.sql | 17 +++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/test/acceptance/copy-endpoints.js b/test/acceptance/copy-endpoints.js index de4fb49a..8c84c1ec 100644 --- a/test/acceptance/copy-endpoints.js +++ b/test/acceptance/copy-endpoints.js @@ -10,7 +10,25 @@ describe('copy-endpoints', function() { assert.response(server, { url: "/api/v1/sql/copyfrom", formData: { - sql: "COPY copy_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)", + sql: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)", + file: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'), + }, + headers: {host: 'vizzuality.cartodb.com'}, + method: 'POST' + },{}, function(err, res) { + assert.ifError(err); + const response = JSON.parse(res.body); + assert.equal(!!response.time, true); + assert.strictEqual(response.total_rows, 6); + done(); + }); + }); + + it('should works with copyfrom endpoint and SQL in querystring', function(done){ + const sql = "COPY copy_endpoints_test2 (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"; + assert.response(server, { + url: `/api/v1/sql/copyfrom?sql=${sql}`, + formData: { file: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'), }, headers: {host: 'vizzuality.cartodb.com'}, @@ -58,7 +76,7 @@ describe('copy-endpoints', function() { assert.deepEqual( JSON.parse(res.body), { - error:['no rows copied'] + error:['The file is missing'] } ); done(); @@ -88,7 +106,7 @@ describe('copy-endpoints', function() { it('should works with copyto endpoint', function(done){ assert.response(server, { url: "/api/v1/sql/copyto?" + querystring.stringify({ - sql: 'COPY copy_test TO STDOUT', + sql: 'COPY copy_endpoints_test TO STDOUT', filename: '/tmp/output.dmp' }), headers: {host: 'vizzuality.cartodb.com'}, diff --git a/test/support/sql/test.sql b/test/support/sql/test.sql index 8a3b3459..711e6183 100644 --- a/test/support/sql/test.sql +++ b/test/support/sql/test.sql @@ -218,11 +218,20 @@ INSERT INTO CDB_TableMetadata (tabname, updated_at) VALUES ('scoped_table_1'::re GRANT SELECT ON CDB_TableMetadata TO :TESTUSER; GRANT SELECT ON CDB_TableMetadata TO test_cartodb_user_2; -DROP TABLE IF EXISTS copy_test; -CREATE TABLE copy_test ( +DROP TABLE IF EXISTS copy_endpoints_test; +CREATE TABLE copy_endpoints_test ( id integer, name text, age integer default 10 ); -GRANT ALL ON TABLE copy_test TO :TESTUSER; -GRANT ALL ON TABLE copy_test TO :PUBLICUSER; +GRANT ALL ON TABLE copy_endpoints_test TO :TESTUSER; +GRANT ALL ON TABLE copy_endpoints_test TO :PUBLICUSER; + +DROP TABLE IF EXISTS copy_endpoints_test2; +CREATE TABLE copy_endpoints_test2 ( + id integer, + name text, + age integer default 10 +); +GRANT ALL ON TABLE copy_endpoints_test2 TO :TESTUSER; +GRANT ALL ON TABLE copy_endpoints_test2 TO :PUBLICUSER;