|
11 | 11 | let(:target_schema) { 'schema_one' }
|
12 | 12 | let(:target_database_id) { 6 }
|
13 | 13 | let(:target_database_available_schemas) { ['schema_one', 'schema_two', 'schema_three'] }
|
14 |
| - |
15 | 14 | let(:source_dataset_1) { 101 }
|
16 | 15 | let(:source_dataset_2) { 102 }
|
17 | 16 | let(:source_dashboard_datasets) {[
|
18 | 17 | {id: source_dataset_1, datasource_name: "Dataset 1", schema: "schema1", database: {id: 9, name: "db_9", backend: "postgresql"}},
|
19 | 18 | {id: source_dataset_2, datasource_name: "Dataset 2", schema: "schema1", database: {id: 9, name: "db_9", backend: "postgresql"}}
|
20 | 19 | ]}
|
| 20 | + let(:json_metadata) { { 'native_filter_configuration' => [{ 'targets' => [{ 'datasetId' => 201 }]}]} } |
| 21 | + let(:new_json_metadata) { { 'native_filter_configuration' => [{ 'targets' => [{ 'datasetId' => 201 }]}]} } |
| 22 | + let(:source_allowed_filters) { [{'id' => 201}] } |
| 23 | + let(:source_dashboard_filters) {[{ 'datasetId' => 201 }]} |
| 24 | + let(:dataset_duplication_tracker) { [{ source_dataset_id: 201, new_dataset_id: 201 }] } |
21 | 25 |
|
22 | 26 | let(:new_dashboard_id) { 2 }
|
23 |
| - let(:new_dashboard) { double('new_dashboard', id: new_dashboard_id, url: "http://superset-host.com/superset/dashboard/#{new_dashboard_id}") } |
| 27 | + let(:new_dashboard) { double('new_dashboard', id: new_dashboard_id, url: "http://superset-host.com/superset/dashboard/#{new_dashboard_id}", json_metadata: json_metadata) } |
24 | 28 |
|
25 | 29 | let(:new_dataset_1) { 201 }
|
26 | 30 | let(:new_dataset_2) { 202 }
|
|
35 | 39 | allow(subject).to receive(:new_dashboard).and_return(new_dashboard)
|
36 | 40 | allow(subject).to receive(:source_dashboard_datasets).and_return(source_dashboard_datasets)
|
37 | 41 | allow(subject).to receive(:target_schema_matching_dataset_names).and_return(existing_target_datasets_list)
|
| 42 | + allow(subject).to receive(:source_allowed_filters).and_return(source_allowed_filters) |
| 43 | + allow(subject).to receive(:source_dashboard_filters).and_return(source_dashboard_filters) |
| 44 | + allow(subject).to receive(:dataset_duplication_tracker).and_return(dataset_duplication_tracker) |
| 45 | + allow(new_dashboard).to receive(:result).and_return({ 'json_metadata' => json_metadata.to_json }) |
38 | 46 | end
|
39 | 47 |
|
40 | 48 | describe '#perform' do
|
41 | 49 | context 'with valid params' do
|
42 |
| - |
43 | 50 | before do
|
44 | 51 | # duplicating the current datasets
|
45 | 52 | expect(Superset::Dataset::Duplicate).to receive(:new).with(source_dataset_id: source_dataset_1, new_dataset_name: "Dataset 1 (COPY)").and_return(double(perform: new_dataset_1))
|
46 | 53 | expect(Superset::Dataset::Duplicate).to receive(:new).with(source_dataset_id: source_dataset_2, new_dataset_name: "Dataset 2 (COPY)").and_return(double(perform: new_dataset_2))
|
47 | 54 |
|
48 | 55 | # updating the new datasets to point to the target schema and target database
|
49 |
| - expect(Superset::Dataset::UpdateSchema).to receive(:new).with(source_dataset_id: new_dataset_1, target_database_id: target_database_id, target_schema: target_schema).and_return(double(response: true)) |
50 |
| - expect(Superset::Dataset::UpdateSchema).to receive(:new).with(source_dataset_id: new_dataset_2, target_database_id: target_database_id, target_schema: target_schema).and_return(double(response: true)) |
| 56 | + expect(Superset::Dataset::UpdateSchema).to receive(:new).with(source_dataset_id: new_dataset_1, target_database_id: target_database_id, target_schema: target_schema).and_return(double(perform: new_dataset_1)) |
| 57 | + expect(Superset::Dataset::UpdateSchema).to receive(:new).with(source_dataset_id: new_dataset_2, target_database_id: target_database_id, target_schema: target_schema).and_return(double(perform: new_dataset_2)) |
51 | 58 |
|
52 | 59 | # getting the list of charts for the source dashboard
|
53 |
| - allow(Superset::Dashboard::Charts::List).to receive(:new).with(new_dashboard_id).and_return(double(chart_ids: [new_chart_1, new_chart_2])) |
| 60 | + allow(Superset::Dashboard::Charts::List).to receive(:new).with(source_dashboard_id).and_return(double(result: [{ 'slice_name' => "test", "id" => 3001}, { 'slice_name' => "test", "id" => 3002}], chart_ids: [new_chart_1, new_chart_2])) |
| 61 | + allow(Superset::Dashboard::Charts::List).to receive(:new).with(new_dashboard_id).and_return(double(result: [{ 'slice_name' => "test", "id" => 3001}, { 'slice_name' => "test", "id" => 3002}])) |
54 | 62 |
|
55 | 63 | # getting the current dataset_id for the new charts .. still pointing to the old datasets
|
56 | 64 | expect(Superset::Chart::Get).to receive(:new).with(3001).and_return(double(datasource_id: source_dataset_1))
|
57 | 65 | expect(Superset::Chart::Get).to receive(:new).with(3002).and_return(double(datasource_id: source_dataset_2))
|
58 | 66 |
|
59 | 67 | # updating the new charts to point to the new datasets
|
60 |
| - expect(Superset::Chart::UpdateDataset).to receive(:new).with(chart_id: new_chart_1, target_dataset_id: new_dataset_1).and_return(double(response: true)) |
61 |
| - expect(Superset::Chart::UpdateDataset).to receive(:new).with(chart_id: new_chart_2, target_dataset_id: new_dataset_2).and_return(double(response: true)) |
| 68 | + expect(Superset::Chart::UpdateDataset).to receive(:new).with(chart_id: new_chart_1, target_dataset_id: new_dataset_1).and_return(double(perform: true)) |
| 69 | + expect(Superset::Chart::UpdateDataset).to receive(:new).with(chart_id: new_chart_2, target_dataset_id: new_dataset_2).and_return(double(perform: true)) |
| 70 | + |
| 71 | + # get json metadata |
| 72 | + expect(Superset::Dashboard::Get).to receive(:new).with(new_dashboard_id).and_return(double(json_metadata: json_metadata)) |
| 73 | + |
| 74 | + # update dashboard json metadata |
| 75 | + expect(Superset::Dashboard::Put).to receive(:new).twice.with(target_dashboard_id: new_dashboard_id, params: { 'json_metadata' => new_json_metadata.to_json }).and_return(double(perform: true)) |
62 | 76 | end
|
63 | 77 |
|
64 | 78 | specify do
|
|
99 | 113 | end
|
100 | 114 | end
|
101 | 115 |
|
| 116 | + context 'filters set is outside source schema' do |
| 117 | + let(:target_schema) { 'schema_one' } |
| 118 | + let(:source_dashboard_filters) { [{ 'datasetId' => 201 }, { 'datasetId' => 203 }] } |
| 119 | + |
| 120 | + specify do |
| 121 | + expect { subject.perform }.to raise_error(Superset::Request::ValidationError, "The source_dashboard_id #{source_dashboard_id} filters point to more than one schema.") |
| 122 | + end |
| 123 | + end |
| 124 | + |
102 | 125 | context 'source dashboard datasets use multiple schemas' do
|
103 | 126 | before do
|
104 | 127 | allow(subject).to receive(:source_dashboard_schemas).and_return(['schema_one', 'schema_five'])
|
|
0 commit comments