Skip to content

Commit f248f7f

Browse files
committed
adds spec and fixture for export process
1 parent 32d5abb commit f248f7f

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ superset-*.gem
1717

1818
# ignore local log file
1919
log/superset-client.log
20+
21+
# ignore local ./tmp directory
22+
./tmp/

lib/superset/dashboard/export.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class Export < Request
1818

1919
def initialize(dashboard_id: , destination_path: )
2020
@dashboard_id = dashboard_id
21-
@destination_path = destination_path
22-
@download_path = TMP_SUPERSET_DASHBOARD_PATH
21+
@destination_path = destination_path.chomp('/')
2322
end
2423

2524
def perform
26-
response
27-
write_file_and_unzip
25+
create_tmp_dir
26+
save_exported_zip_file
27+
unzip_files
2828
copy_export_files_to_destination_path if destination_path
2929
end
3030

@@ -43,18 +43,15 @@ def download_folder
4343

4444
private
4545

46-
def route
47-
"dashboard/export/"
48-
end
49-
5046
def params
5147
{ "q": "!(#{dashboard_id})" } # pulled off chrome dev tools doing a GUI export. Swagger interface not helpfull with this endpoint.
5248
end
5349

54-
def write_file_and_unzip
55-
create_tmp_dir
56-
File.open(zip_file_name, 'wb') { |fp| fp.write(@response.body) }
50+
def save_exported_zip_file
51+
File.open(zip_file_name, 'wb') { |fp| fp.write(response.body) }
52+
end
5753

54+
def unzip_files
5855
@extracted_files = unzip_file(zip_file_name, tmp_uniq_dashboard_path)
5956
end
6057

@@ -89,6 +86,10 @@ def extracted_files
8986
@extracted_files ||= []
9087
end
9188

89+
def route
90+
"dashboard/export/"
91+
end
92+
9293
def datestamp
9394
@datestamp ||= Time.now.strftime('%Y%m%d')
9495
end
16.7 KB
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe Superset::Dashboard::Export do
4+
subject { described_class.new(dashboard_id: dashboard_id, destination_path: destination_path) }
5+
let(:dashboard_id) { 18 }
6+
let(:destination_path) { './tmp/superset_dashboard_backups/' }
7+
8+
describe '#perform' do
9+
let(:response) { double('response') }
10+
let(:zip_file_name) { 'spec/fixtures/dashboard_18_export_20240322.zip' } # example birth names dashboard export fixture
11+
12+
before do
13+
allow(subject).to receive(:response).and_return(response)
14+
allow(subject).to receive(:zip_file_name).and_return(zip_file_name)
15+
allow(subject).to receive(:save_exported_zip_file)
16+
end
17+
18+
it 'unzips into the destination path' do
19+
subject.perform
20+
expect(Dir.glob(subject.destination_path + "/**/*").sort).to match_array([
21+
"./tmp/superset_dashboard_backups/18",
22+
"./tmp/superset_dashboard_backups/18/charts",
23+
"./tmp/superset_dashboard_backups/18/charts/Boy_Name_Cloud_53920.yaml",
24+
"./tmp/superset_dashboard_backups/18/charts/Names_Sorted_by_Num_in_California_53929.yaml",
25+
"./tmp/superset_dashboard_backups/18/charts/Number_of_Girls_53930.yaml",
26+
"./tmp/superset_dashboard_backups/18/charts/Pivot_Table_53931.yaml",
27+
"./tmp/superset_dashboard_backups/18/charts/Top_10_Girl_Name_Share_53921.yaml",
28+
"./tmp/superset_dashboard_backups/18/dashboards",
29+
"./tmp/superset_dashboard_backups/18/dashboards/Birth_Names_18.yaml",
30+
"./tmp/superset_dashboard_backups/18/databases",
31+
"./tmp/superset_dashboard_backups/18/databases/examples.yaml",
32+
"./tmp/superset_dashboard_backups/18/datasets",
33+
"./tmp/superset_dashboard_backups/18/datasets/examples",
34+
"./tmp/superset_dashboard_backups/18/datasets/examples/birth_names.yaml",
35+
"./tmp/superset_dashboard_backups/18/metadata.yaml"
36+
])
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)