File tree Expand file tree Collapse file tree 3 files changed +86
-1
lines changed Expand file tree Collapse file tree 3 files changed +86
-1
lines changed Original file line number Diff line number Diff line change
1
+ # Updates a chart in Superset with the given params
2
+ #
3
+ # Usage:
4
+ # params = { owners: [ 58, 3 ] }
5
+ # Superset::Chart::Put.new(chart_id: 3998, params: params ).perform
6
+
7
+ module Superset
8
+ module Chart
9
+ class Put < Superset ::Request
10
+
11
+ attr_reader :chart_id , :params
12
+
13
+ def initialize ( chart_id : , params :)
14
+ @chart_id = chart_id
15
+ @params = params
16
+ end
17
+
18
+ def perform
19
+ validate_proposed_changes
20
+ response
21
+ end
22
+
23
+ def response
24
+ @response ||= client . put ( route , params )
25
+ end
26
+
27
+ private
28
+
29
+ def validate_proposed_changes
30
+ raise "Error: chart_id integer is required" unless chart_id . present? && chart_id . is_a? ( Integer )
31
+ raise "Error: params hash is required" unless params . present? && params . is_a? ( Hash )
32
+ end
33
+
34
+ def route
35
+ "chart/#{ chart_id } "
36
+ end
37
+ end
38
+ end
39
+ end
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ def params_updated
43
43
new_params . merge! ( "query_context" : query_context . to_json ) # update to point to the new query context
44
44
new_params . merge! ( "query_context_generation" : true ) # new param set to true to regenerate the query context
45
45
end
46
-
46
+
47
47
new_params
48
48
end
49
49
end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ RSpec . describe Superset ::Chart ::Put do
4
+ subject { described_class . new (
5
+ chart_id : chart_id ,
6
+ params : params ) }
7
+
8
+ let ( :chart_id ) { 226 }
9
+ let ( :params ) { { owners : [ 1 , 2 , 3 ] } }
10
+ let ( :response ) do
11
+ {
12
+ id : chart_id ,
13
+ result : { owners : [ 1 , 2 , 3 ] }
14
+ }
15
+ end
16
+
17
+ before do
18
+ allow ( subject ) . to receive ( :response ) . and_return ( response )
19
+ end
20
+
21
+ describe '#perform' do
22
+ context 'with valid params' do
23
+ specify do
24
+ expect ( subject . perform ) . to eq response
25
+ end
26
+ end
27
+
28
+ context 'with invalid params' do
29
+ context 'chart_id is empty' do
30
+ let ( :chart_id ) { nil }
31
+
32
+ specify do
33
+ expect { subject . perform } . to raise_error ( RuntimeError , "Error: chart_id integer is required" )
34
+ end
35
+ end
36
+
37
+ context 'params is empty' do
38
+ let ( :params ) { nil }
39
+
40
+ specify do
41
+ expect { subject . perform } . to raise_error ( RuntimeError , "Error: params hash is required" )
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
You can’t perform that action at this time.
0 commit comments