ensuring works with sql parameter in query string
This commit is contained in:
parent
6b96032fcf
commit
a2d0163ece
@ -10,7 +10,25 @@ describe('copy-endpoints', function() {
|
|||||||
assert.response(server, {
|
assert.response(server, {
|
||||||
url: "/api/v1/sql/copyfrom",
|
url: "/api/v1/sql/copyfrom",
|
||||||
formData: {
|
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'),
|
file: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
|
||||||
},
|
},
|
||||||
headers: {host: 'vizzuality.cartodb.com'},
|
headers: {host: 'vizzuality.cartodb.com'},
|
||||||
@ -58,7 +76,7 @@ describe('copy-endpoints', function() {
|
|||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
JSON.parse(res.body),
|
JSON.parse(res.body),
|
||||||
{
|
{
|
||||||
error:['no rows copied']
|
error:['The file is missing']
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
@ -88,7 +106,7 @@ describe('copy-endpoints', function() {
|
|||||||
it('should works with copyto endpoint', function(done){
|
it('should works with copyto endpoint', function(done){
|
||||||
assert.response(server, {
|
assert.response(server, {
|
||||||
url: "/api/v1/sql/copyto?" + querystring.stringify({
|
url: "/api/v1/sql/copyto?" + querystring.stringify({
|
||||||
sql: 'COPY copy_test TO STDOUT',
|
sql: 'COPY copy_endpoints_test TO STDOUT',
|
||||||
filename: '/tmp/output.dmp'
|
filename: '/tmp/output.dmp'
|
||||||
}),
|
}),
|
||||||
headers: {host: 'vizzuality.cartodb.com'},
|
headers: {host: 'vizzuality.cartodb.com'},
|
||||||
|
@ -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 :TESTUSER;
|
||||||
GRANT SELECT ON CDB_TableMetadata TO test_cartodb_user_2;
|
GRANT SELECT ON CDB_TableMetadata TO test_cartodb_user_2;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS copy_test;
|
DROP TABLE IF EXISTS copy_endpoints_test;
|
||||||
CREATE TABLE copy_test (
|
CREATE TABLE copy_endpoints_test (
|
||||||
id integer,
|
id integer,
|
||||||
name text,
|
name text,
|
||||||
age integer default 10
|
age integer default 10
|
||||||
);
|
);
|
||||||
GRANT ALL ON TABLE copy_test TO :TESTUSER;
|
GRANT ALL ON TABLE copy_endpoints_test TO :TESTUSER;
|
||||||
GRANT ALL ON TABLE copy_test TO :PUBLICUSER;
|
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user