Merge branch 'master' into 3889-functional-testing
[arvados.git] / apps / workbench / test / functional / pipeline_instances_controller_test.rb
1 require 'test_helper'
2
3 class PipelineInstancesControllerTest < ActionController::TestCase
4   def create_instance_long_enough_to(instance_attrs={})
5     pt_fixture = api_fixture('pipeline_templates')['two_part']
6     post :create, {
7       pipeline_instance: instance_attrs.merge({
8         pipeline_template_uuid: pt_fixture['uuid']
9       }),
10       format: :json
11     }, session_for(:active)
12     assert_response :success
13     pi_uuid = assigns(:object).uuid
14     assert_not_nil assigns(:object)
15     yield pi_uuid, pt_fixture
16   end
17
18   test "pipeline instance components populated after create" do
19     create_instance_long_enough_to do |new_instance_uuid, template_fixture|
20       assert_equal(template_fixture['components'].to_json,
21                    assigns(:object).components.to_json)
22     end
23   end
24
25   test "can render pipeline instance with tagged collections" do
26     # Make sure to pass in a tagged collection to test that part of the rendering behavior.
27     get(:show,
28         {id: api_fixture("pipeline_instances")["pipeline_with_tagged_collection_input"]["uuid"]},
29         session_for(:active))
30     assert_response :success
31   end
32
33   test "update script_parameters one at a time using merge param" do
34       template_fixture = api_fixture('pipeline_templates')['two_part']
35       post :update, {
36         id: api_fixture("pipeline_instances")["pipeline_to_merge_params"]["uuid"],
37         pipeline_instance: {
38           components: {
39             "part-two" => {
40               script_parameters: {
41                 integer_with_value: {
42                   value: 9
43                 },
44                 plain_string: {
45                   value: 'quux'
46                 },
47               }
48             }
49           }
50         },
51         merge: true,
52         format: :json
53       }, session_for(:active)
54       assert_response :success
55       assert_not_nil assigns(:object)
56       orig_params = template_fixture['components']['part-two']['script_parameters']
57       new_params = assigns(:object).components[:'part-two'][:script_parameters]
58       orig_params.keys.each do |k|
59         unless %w(integer_with_value plain_string).index(k)
60           assert_equal orig_params[k].to_json, new_params[k.to_sym].to_json
61         end
62       end
63   end
64
65   test "component rendering copes with unexpeceted components format" do
66     get(:show,
67         {id: api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]},
68         session_for(:active))
69     assert_response :success
70   end
71 end