Skip to content

Commit b76adfb

Browse files
committed
AC-11246 add chart put endpoint
1 parent ae22a53 commit b76adfb

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

lib/superset/chart/put.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

lib/superset/chart/update_dataset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def params_updated
4343
new_params.merge!("query_context": query_context.to_json) # update to point to the new query context
4444
new_params.merge!("query_context_generation": true) # new param set to true to regenerate the query context
4545
end
46-
46+
4747
new_params
4848
end
4949
end

spec/superset/chart/put_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

0 commit comments

Comments
 (0)