mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
refactor: upload data unification, less permissions and less endpoints (#31959)
This commit is contained in:
committed by
GitHub
parent
09c1987de4
commit
1b375b715c
@@ -25,9 +25,7 @@ import userEvent from '@testing-library/user-event';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
import { UploadFile } from 'antd/lib/upload/interface';
|
||||
|
||||
fetchMock.post('glob:*api/v1/database/1/csv_upload/', {});
|
||||
fetchMock.post('glob:*api/v1/database/1/excel_upload/', {});
|
||||
fetchMock.post('glob:*api/v1/database/1/columnar_upload/', {});
|
||||
fetchMock.post('glob:*api/v1/database/1/upload/', {});
|
||||
|
||||
fetchMock.get(
|
||||
'glob:*api/v1/database/?q=(filters:!((col:allow_file_upload,opr:eq,value:!t)),page:0,page_size:100)',
|
||||
@@ -643,18 +641,21 @@ test('CSV, form post', async () => {
|
||||
});
|
||||
|
||||
userEvent.click(uploadButton);
|
||||
await waitFor(() => fetchMock.called('glob:*api/v1/database/1/csv_upload/'));
|
||||
await waitFor(() => fetchMock.called('glob:*api/v1/database/1/upload/'));
|
||||
|
||||
// Get the matching fetch calls made
|
||||
const matchingCalls = fetchMock.calls('glob:*api/v1/database/1/csv_upload/');
|
||||
const matchingCalls = fetchMock.calls('glob:*api/v1/database/1/upload/');
|
||||
expect(matchingCalls).toHaveLength(1);
|
||||
const [_, options] = matchingCalls[0];
|
||||
const formData = options?.body as FormData;
|
||||
expect(formData.get('type')).toBe('csv');
|
||||
expect(formData.get('table_name')).toBe('table1');
|
||||
expect(formData.get('schema')).toBe('public');
|
||||
expect(formData.get('table_name')).toBe('table1');
|
||||
const fileData = formData.get('file') as File;
|
||||
expect(fileData.name).toBe('test.csv');
|
||||
// Avoid leaking fetchMock calls
|
||||
fetchMock.resetHistory();
|
||||
});
|
||||
|
||||
test('Excel, form post', async () => {
|
||||
@@ -700,22 +701,21 @@ test('Excel, form post', async () => {
|
||||
});
|
||||
|
||||
userEvent.click(uploadButton);
|
||||
await waitFor(() =>
|
||||
fetchMock.called('glob:*api/v1/database/1/excel_upload/'),
|
||||
);
|
||||
await waitFor(() => fetchMock.called('glob:*api/v1/database/1/upload/'));
|
||||
|
||||
// Get the matching fetch calls made
|
||||
const matchingCalls = fetchMock.calls(
|
||||
'glob:*api/v1/database/1/excel_upload/',
|
||||
);
|
||||
const matchingCalls = fetchMock.calls('glob:*api/v1/database/1/upload/');
|
||||
expect(matchingCalls).toHaveLength(1);
|
||||
const [_, options] = matchingCalls[0];
|
||||
const formData = options?.body as FormData;
|
||||
expect(formData.get('type')).toBe('excel');
|
||||
expect(formData.get('table_name')).toBe('table1');
|
||||
expect(formData.get('schema')).toBe('public');
|
||||
expect(formData.get('table_name')).toBe('table1');
|
||||
const fileData = formData.get('file') as File;
|
||||
expect(fileData.name).toBe('test.xls');
|
||||
// Avoid leaking fetchMock calls
|
||||
fetchMock.resetHistory();
|
||||
});
|
||||
|
||||
test('Columnar, form post', async () => {
|
||||
@@ -761,22 +761,21 @@ test('Columnar, form post', async () => {
|
||||
});
|
||||
|
||||
userEvent.click(uploadButton);
|
||||
await waitFor(() =>
|
||||
fetchMock.called('glob:*api/v1/database/1/columnar_upload/'),
|
||||
);
|
||||
await waitFor(() => fetchMock.called('glob:*api/v1/database/1/upload/'));
|
||||
|
||||
// Get the matching fetch calls made
|
||||
const matchingCalls = fetchMock.calls(
|
||||
'glob:*api/v1/database/1/columnar_upload/',
|
||||
);
|
||||
const matchingCalls = fetchMock.calls('glob:*api/v1/database/1/upload/');
|
||||
expect(matchingCalls).toHaveLength(1);
|
||||
const [_, options] = matchingCalls[0];
|
||||
const formData = options?.body as FormData;
|
||||
expect(formData.get('type')).toBe('columnar');
|
||||
expect(formData.get('table_name')).toBe('table1');
|
||||
expect(formData.get('schema')).toBe('public');
|
||||
expect(formData.get('table_name')).toBe('table1');
|
||||
const fileData = formData.get('file') as File;
|
||||
expect(fileData.name).toBe('test.parquet');
|
||||
// Avoid leaking fetchMock calls
|
||||
fetchMock.resetHistory();
|
||||
});
|
||||
|
||||
test('CSV, validate file extension returns false', () => {
|
||||
|
||||
Reference in New Issue
Block a user