8784: Fix test for latest firefox.
[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     assert_nil pi.started_at, 'expected started_at to be nil on new pipeline instance'
42     assert_nil pi.finished_at, 'expected finished_at to be nil on new pipeline instance'
43
44     # add a component with no input not required
45     component = {'script_parameters' => {"input_not_provided" => {"required" => false}}}
46     pi.components['first'] = component
47     components = pi.components
48     pi.update_attribute 'components', pi.components
49     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
50     assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
51     assert_equal pi.components.size, 1, 'expected one component'
52
53     # add a component with input and expect state to become Ready
54     component = {'script_parameters' => {"input" => "yyyad4b39ca5a924e481008009d94e32+210"}}
55     pi.components['first'] = component
56     components = pi.components
57     pi.update_attribute 'components', pi.components
58     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
59     assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
60     assert_equal pi.components.size, 1, 'expected one component'
61
62     pi.state = PipelineInstance::RunningOnServer
63     pi.save
64     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
65     assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating state to RunningOnServer'
66     assert_not_nil pi.started_at, 'expected started_at to have a value on a running pipeline instance'
67     assert_nil pi.finished_at, 'expected finished_at to be nil on a running pipeline instance'
68
69     pi.state = PipelineInstance::Paused
70     pi.save
71     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
72     assert_equal PipelineInstance::Paused, pi.state, 'expected state to be Paused after updating state to Paused'
73
74     pi.state = PipelineInstance::Complete
75     pi.save
76     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
77     assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating state to Complete'
78     assert_not_nil pi.started_at, 'expected started_at to have a value on a completed pipeline instance'
79     assert_not_nil pi.finished_at, 'expected finished_at to have a value on a completed pipeline instance'
80
81     pi.state = 'bogus'
82     pi.save
83     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
84     assert_equal PipelineInstance::Complete, pi.state, 'expected state to be unchanged with set to a bogus value'
85
86     pi.state = PipelineInstance::Failed
87     pi.save
88     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
89     assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating state to Failed'
90     assert_not_nil pi.started_at, 'expected started_at to have a value on a failed pipeline instance'
91     assert_not_nil pi.finished_at, 'expected finished_at to have a value on a failed pipeline instance'
92   end
93
94   test "update attributes for pipeline with two components" do
95     pi = pipeline_instances :new_pipeline
96
97     # add two components, one with input and one with no input and expect state to be New
98     component1 = {'script_parameters' => {"something" => "xxxad4b39ca5a924e481008009d94e32+210", "input" => "c1bad4b39ca5a924e481008009d94e32+210"}}
99     component2 = {'script_parameters' => {"something_else" => "xxxad4b39ca5a924e481008009d94e32+210", "input_missing" => {"required" => true}}}
100     pi.components['first'] = component1
101     pi.components['second'] = component2
102
103     Thread.current[:user] = users(:admin)
104     pi.update_attribute 'components', pi.components
105
106     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
107     assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
108     assert_equal pi.components.size, 2, 'expected two components'
109   end
110
111   [:has_component_with_no_script_parameters,
112    :has_component_with_empty_script_parameters].each do |pi_name|
113     test "update pipeline that #{pi_name}" do
114       pi = pipeline_instances pi_name
115
116       Thread.current[:user] = users(:active)
117       assert_equal PipelineInstance::Ready, pi.state
118     end
119   end
120 end