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 a new pipeline'
9 assert !pi.success, 'expected success to be false for a new pipeline'
10 assert !pi.state, 'expected state to be nil because the fixture had no state specified'
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 "update attributes for pipeline" do
23 Thread.current[:user] = users(:admin)
25 pi = pipeline_instances :new_pipeline
27 # add a component with no input and expect state to be New
28 component = {'script_parameters' => {"input_not_provided" => {"required" => true}}}
29 pi.components['first'] = component
30 components = pi.components
31 pi.update_attribute 'components', pi.components
32 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
33 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
34 assert_equal pi.components.size, 1, 'expected one component'
35 assert !pi.active, 'expected active to be false after update'
36 assert !pi.success, 'expected success to be false for a new pipeline'
38 # add a component with no input not required
39 component = {'script_parameters' => {"input_not_provided" => {"required" => false}}}
40 pi.components['first'] = component
41 components = pi.components
42 pi.update_attribute 'components', pi.components
43 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
44 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
45 assert_equal pi.components.size, 1, 'expected one component'
46 assert !pi.active, 'expected active to be false after update'
47 assert !pi.success, 'expected success to be false for a new pipeline'
49 # add a component with input and expect state to become Ready
50 component = {'script_parameters' => {"input" => "yyyad4b39ca5a924e481008009d94e32+210"}}
51 pi.components['first'] = component
52 components = pi.components
53 pi.update_attribute 'components', pi.components
54 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
55 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
56 assert_equal pi.components.size, 1, 'expected one component'
57 assert !pi.active, 'expected active to be false after update'
58 assert !pi.success, 'expected success to be false for a new pipeline'
62 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
63 assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating active to true'
64 assert pi.active, 'expected active to be true after update'
65 assert !pi.success, 'expected success to be false for a new pipeline'
69 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
70 assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating success to false'
71 assert !pi.active, 'expected active to be false after update'
72 assert !pi.success, 'expected success to be false for a new pipeline'
74 pi.state = PipelineInstance::RunningOnServer
76 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
77 assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating state to RunningOnServer'
78 assert pi.active, 'expected active to be true after update'
79 assert !pi.success, 'expected success to be alse after update'
81 pi.state = PipelineInstance::Paused
83 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
84 assert_equal PipelineInstance::Paused, pi.state, 'expected state to be Paused after updating state to Paused'
85 assert !pi.active, 'expected active to be false after update'
86 assert !pi.success, 'expected success to be false after update'
88 pi.state = PipelineInstance::Complete
90 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
91 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating state to Complete'
92 assert !pi.active, 'expected active to be false after update'
93 assert pi.success, 'expected success to be true after update'
97 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
98 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be unchanged with set to a bogus value'
99 assert !pi.active, 'expected active to be false after update'
100 assert pi.success, 'expected success to be true after update'
102 pi.state = PipelineInstance::Failed
104 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
105 assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating state to Failed'
106 assert !pi.active, 'expected active to be false after update'
107 assert !pi.success, 'expected success to be false after update'
110 test "update attributes for pipeline with two components" do
111 pi = pipeline_instances :new_pipeline
113 # add two components, one with input and one with no input and expect state to be New
114 component1 = {'script_parameters' => {"something" => "xxxad4b39ca5a924e481008009d94e32+210", "input" => "c1bad4b39ca5a924e481008009d94e32+210"}}
115 component2 = {'script_parameters' => {"something_else" => "xxxad4b39ca5a924e481008009d94e32+210", "input_missing" => {"required" => true}}}
116 pi.components['first'] = component1
117 pi.components['second'] = component2
118 components = pi.components
120 Thread.current[:user] = users(:admin)
121 pi.update_attribute 'components', pi.components
123 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
124 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
125 assert_equal pi.components.size, 2, 'expected two components'
126 assert !pi.active, 'expected active to be false after update'
127 assert !pi.success, 'expected success to be false for a new pipeline'
130 [:has_component_with_no_script_parameters,
131 :has_component_with_empty_script_parameters].each do |pi_name|
132 test "update pipeline that #{pi_name}" do
133 pi = pipeline_instances pi_name
135 Thread.current[:user] = users(:active)
136 # Make sure we go through the "active_changed? and active" code:
137 pi.update_attributes active: true
138 pi.update_attributes active: false
139 assert_equal PipelineInstance::Ready, pi.state