Add 'apps/arv-web/' from commit 'f9732ad8460d013c2f28363655d0d1b91894dca5'
[arvados.git] / services / api / test / unit / pipeline_instance_test.rb
1 require 'test_helper'
2
3 class PipelineInstanceTest < ActiveSupport::TestCase
4
5   test "check active and success for a pipeline in new state" do
6     pi = pipeline_instances :new_pipeline
7
8     assert_equal 'New', pi.state, 'expected state to be New for :new_pipeline'
9
10     # save the pipeline and expect state to be New
11     Thread.current[:user] = users(:admin)
12
13     pi.save
14     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
15     assert_equal PipelineInstance::New, pi.state, 'expected state to be New for new pipeline'
16   end
17
18   test "check active and success for a newly created pipeline" do
19     set_user_from_auth :active
20
21     pi = PipelineInstance.create(state: 'Ready')
22     pi.save
23
24     assert pi.valid?, 'expected newly created empty pipeline to be valid ' + pi.errors.messages.to_s
25     assert_equal 'Ready', pi.state, 'expected state to be Ready for a new empty pipeline'
26   end
27
28   test "update attributes for pipeline" do
29     Thread.current[:user] = users(:admin)
30
31     pi = pipeline_instances :new_pipeline
32
33     # add a component with no input and expect state to be New
34     component = {'script_parameters' => {"input_not_provided" => {"required" => true}}}
35     pi.components['first'] = component
36     components = pi.components
37     pi.update_attribute 'components', pi.components
38     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
39     assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
40     assert_equal pi.components.size, 1, 'expected one component'
41
42     # add a component with no input not required
43     component = {'script_parameters' => {"input_not_provided" => {"required" => false}}}
44     pi.components['first'] = component
45     components = pi.components
46     pi.update_attribute 'components', pi.components
47     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
48     assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
49     assert_equal pi.components.size, 1, 'expected one component'
50
51     # add a component with input and expect state to become Ready
52     component = {'script_parameters' => {"input" => "yyyad4b39ca5a924e481008009d94e32+210"}}
53     pi.components['first'] = component
54     components = pi.components
55     pi.update_attribute 'components', pi.components
56     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
57     assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
58     assert_equal pi.components.size, 1, 'expected one component'
59
60     pi.state = PipelineInstance::RunningOnServer
61     pi.save
62     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
63     assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating state to RunningOnServer'
64
65     pi.state = PipelineInstance::Paused
66     pi.save
67     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
68     assert_equal PipelineInstance::Paused, pi.state, 'expected state to be Paused after updating state to Paused'
69
70     pi.state = PipelineInstance::Complete
71     pi.save
72     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
73     assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating state to Complete'
74
75     pi.state = 'bogus'
76     pi.save
77     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
78     assert_equal PipelineInstance::Complete, pi.state, 'expected state to be unchanged with set to a bogus value'
79
80     pi.state = PipelineInstance::Failed
81     pi.save
82     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
83     assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating state to Failed'
84   end
85
86   test "update attributes for pipeline with two components" do
87     pi = pipeline_instances :new_pipeline
88
89     # add two components, one with input and one with no input and expect state to be New
90     component1 = {'script_parameters' => {"something" => "xxxad4b39ca5a924e481008009d94e32+210", "input" => "c1bad4b39ca5a924e481008009d94e32+210"}}
91     component2 = {'script_parameters' => {"something_else" => "xxxad4b39ca5a924e481008009d94e32+210", "input_missing" => {"required" => true}}}
92     pi.components['first'] = component1
93     pi.components['second'] = component2
94     components = pi.components
95
96     Thread.current[:user] = users(:admin)
97     pi.update_attribute 'components', pi.components
98
99     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
100     assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
101     assert_equal pi.components.size, 2, 'expected two components'
102   end
103
104   [:has_component_with_no_script_parameters,
105    :has_component_with_empty_script_parameters].each do |pi_name|
106     test "update pipeline that #{pi_name}" do
107       pi = pipeline_instances pi_name
108
109       Thread.current[:user] = users(:active)
110       assert_equal PipelineInstance::Ready, pi.state
111     end
112   end
113 end