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
14 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
15 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be New for new pipeline'
16 assert !pi.active, 'expected active to be false for a new pipeline'
17 assert !pi.success, 'expected success to be false for a new pipeline'
20 test "update attributes for pipeline" do
21 pi = pipeline_instances :new_pipeline
23 # add a component with no input and expect state to be New
24 component = {'script_parameters' => {"input_not_provided" => {"required" => "true"}}}
25 pi.components['first'] = component
26 components = pi.components
27 pi.update_attribute 'components', pi.components
28 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
29 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
30 assert_equal pi.components.size, 1, 'expected one component'
31 assert !pi.active, 'expected active to be false after update'
32 assert !pi.success, 'expected success to be false for a new pipeline'
34 # add a component with input and expect state to become Ready
35 component = {'script_parameters' => {"input" => "yyyad4b39ca5a924e481008009d94e32+210"}}
36 pi.components['first'] = component
37 components = pi.components
38 pi.update_attribute 'components', pi.components
39 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
40 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
41 assert_equal pi.components.size, 1, 'expected one component'
42 assert !pi.active, 'expected active to be false after update'
43 assert !pi.success, 'expected success to be false for a new pipeline'
47 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
48 assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating active to true'
49 assert pi.active, 'expected active to be true after update'
50 assert !pi.success, 'expected success to be false for a new pipeline'
54 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
55 assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating success to false'
56 assert !pi.active, 'expected active to be false after update'
57 assert !pi.success, 'expected success to be false for a new pipeline'
61 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
62 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating success to true'
63 assert !pi.active, 'expected active to be false after update'
64 assert pi.success, 'expected success to be true after update'
66 pi.update_attribute 'active', true
67 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
68 assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating active to true'
69 assert pi.active, 'expected active to be true after update'
71 pi.update_attribute 'success', false
72 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
73 assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating success to false'
74 assert !pi.active, 'expected active to be false after update'
75 assert !pi.success, 'expected success to be false for a new pipeline'
77 pi.update_attribute 'success', true
78 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
79 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating success to true'
80 assert !pi.active, 'expected active to be false after update'
81 assert pi.success, 'expected success to be true after update'
84 test "update attributes for pipeline with two components" do
85 pi = pipeline_instances :new_pipeline
87 # add two components, one with input and one with no input and expect state to be New
88 component1 = {'script_parameters' => {"something" => "xxxad4b39ca5a924e481008009d94e32+210", "input" => "c1bad4b39ca5a924e481008009d94e32+210"}}
89 component2 = {'script_parameters' => {"something_else" => "xxxad4b39ca5a924e481008009d94e32+210", "input_missing" => {"required" => "true"}}}
90 pi.components['first'] = component1
91 pi.components['second'] = component2
92 components = pi.components
93 pi.update_attribute 'components', pi.components
94 pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-f4gneyn6br1xize'
95 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
96 assert_equal pi.components.size, 2, 'expected two components'
97 assert !pi.active, 'expected active to be false after update'
98 assert !pi.success, 'expected success to be false for a new pipeline'