ensuring works with sql parameter in query string

This commit is contained in:
Simon Martín 2018-05-08 12:51:52 +02:00
parent 6b96032fcf
commit a2d0163ece
2 changed files with 34 additions and 7 deletions

View File

@ -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'},

View File

@ -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;