3 class PipelineInstanceTest < ActiveSupport::TestCase
5 test "check active and success for a pipeline in new state" do
6 pi = pipeline_instances :new_pipeline
8 assert !pi.active, 'expected active to be false for :new_pipeline'
9 assert !pi.success, 'expected success to be false for :new_pipeline'
10 assert_equal 'New', pi.state, 'expected state to be New for :new_pipeline'
12 # save the pipeline and expect state to be New
13 Thread.current[:user] = users(:admin)
16 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
17 assert_equal PipelineInstance::New, pi.state, 'expected state to be New for new pipeline'
18 assert !pi.active, 'expected active to be false for a new pipeline'
19 assert !pi.success, 'expected success to be false for a new pipeline'
22 test "check active and success for a newly created pipeline" do
23 set_user_from_auth :active
25 pi = PipelineInstance.create(state: 'Ready')
28 assert pi.valid?, 'expected newly created empty pipeline to be valid ' + pi.errors.messages.to_s
29 assert !pi.active, 'expected active to be false for a new pipeline'
30 assert !pi.success, 'expected success to be false for a new pipeline'
31 assert_equal 'Ready', pi.state, 'expected state to be Ready for a new empty pipeline'
34 test "update attributes for pipeline" do
35 Thread.current[:user] = users(:admin)
37 pi = pipeline_instances :new_pipeline
39 # add a component with no input and expect state to be New
40 component = {'script_parameters' => {"input_not_provided" => {"required" => true}}}
41 pi.components['first'] = component
42 components = pi.components
43 pi.update_attribute 'components', pi.components
44 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
45 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
46 assert_equal pi.components.size, 1, 'expected one component'
47 assert !pi.active, 'expected active to be false after update'
48 assert !pi.success, 'expected success to be false for a new pipeline'
50 # add a component with no input not required
51 component = {'script_parameters' => {"input_not_provided" => {"required" => false}}}
52 pi.components['first'] = component
53 components = pi.components
54 pi.update_attribute 'components', pi.components
55 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
56 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
57 assert_equal pi.components.size, 1, 'expected one component'
58 assert !pi.active, 'expected active to be false after update'
59 assert !pi.success, 'expected success to be false for a new pipeline'
61 # add a component with input and expect state to become Ready
62 component = {'script_parameters' => {"input" => "yyyad4b39ca5a924e481008009d94e32+210"}}
63 pi.components['first'] = component
64 components = pi.components
65 pi.update_attribute 'components', pi.components
66 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
67 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
68 assert_equal pi.components.size, 1, 'expected one component'
69 assert !pi.active, 'expected active to be false after update'
70 assert !pi.success, 'expected success to be false for a new pipeline'
73 assert_equal true, pi.save, 'expected pipeline instance to save, but ' + pi.errors.messages.to_s
74 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
75 assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating active to true'
76 assert pi.active, 'expected active to be true after update'
77 assert !pi.success, 'expected success to be false for a new pipeline'
81 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
82 assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating success to false'
83 assert !pi.active, 'expected active to be false after update'
84 assert !pi.success, 'expected success to be false for a new pipeline'
86 pi.state = PipelineInstance::RunningOnServer
88 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
89 assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating state to RunningOnServer'
90 assert pi.active, 'expected active to be true after update'
91 assert !pi.success, 'expected success to be alse after update'
93 pi.state = PipelineInstance::Paused
95 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
96 assert_equal PipelineInstance::Paused, pi.state, 'expected state to be Paused after updating state to Paused'
97 assert !pi.active, 'expected active to be false after update'
98 assert !pi.success, 'expected success to be false after update'
100 pi.state = PipelineInstance::Complete
102 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
103 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating state to Complete'
104 assert !pi.active, 'expected active to be false after update'
105 assert pi.success, 'expected success to be true after update'
109 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
110 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be unchanged with set to a bogus value'
111 assert !pi.active, 'expected active to be false after update'
112 assert pi.success, 'expected success to be true after update'
114 pi.state = PipelineInstance::Failed
116 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
117 assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating state to Failed'
118 assert !pi.active, 'expected active to be false after update'
119 assert !pi.success, 'expected success to be false after update'
122 test "update attributes for pipeline with two components" do
123 pi = pipeline_instances :new_pipeline
125 # add two components, one with input and one with no input and expect state to be New
126 component1 = {'script_parameters' => {"something" => "xxxad4b39ca5a924e481008009d94e32+210", "input" => "c1bad4b39ca5a924e481008009d94e32+210"}}
127 component2 = {'script_parameters' => {"something_else" => "xxxad4b39ca5a924e481008009d94e32+210", "input_missing" => {"required" => true}}}
128 pi.components['first'] = component1
129 pi.components['second'] = component2
130 components = pi.components
132 Thread.current[:user] = users(:admin)
133 pi.update_attribute 'components', pi.components
135 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
136 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
137 assert_equal pi.components.size, 2, 'expected two components'
138 assert !pi.active, 'expected active to be false after update'
139 assert !pi.success, 'expected success to be false for a new pipeline'
142 [:has_component_with_no_script_parameters,
143 :has_component_with_empty_script_parameters].each do |pi_name|
144 test "update pipeline that #{pi_name}" do
145 pi = pipeline_instances pi_name
147 Thread.current[:user] = users(:active)
148 # Make sure we go through the "active_changed? and active" code:
149 assert_equal true, pi.update_attributes(active: true), pi.errors.messages
150 assert_equal true, pi.update_attributes(active: false), pi.errors.messages
151 assert_equal PipelineInstance::Paused, pi.state