Merge branch 'master' of git.curoverse.com:arvados into 2612-workbench-displays-user...
[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 !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'
11
12     # save the pipeline and expect state to be New
13     Thread.current[:user] = users(:admin)
14
15     pi.save
16     pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-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'
20   end
21
22   test "update attributes for pipeline" do
23     Thread.current[:user] = users(:admin)
24
25     pi = pipeline_instances :new_pipeline
26
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-xxxxx-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'
37
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-xxxxx-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'
48
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-xxxxx-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'
59
60     pi.active = true
61     pi.save
62     pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-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'
66
67     pi.success = false
68     pi.save
69     pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-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'
73
74     pi.state = PipelineInstance::RunningOnServer
75     pi.save
76     pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-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'
80
81     pi.state = PipelineInstance::Paused
82     pi.save
83     pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-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'
87
88     pi.state = PipelineInstance::Complete
89     pi.save
90     pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-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'
94
95     pi.state = 'bogus'
96     pi.save
97     pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-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'
101
102     pi.state = PipelineInstance::Failed
103     pi.save
104     pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-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'
108   end
109
110   test "update attributes for pipeline with two components" do
111     pi = pipeline_instances :new_pipeline
112
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
119
120     Thread.current[:user] = users(:admin)
121     pi.update_attribute 'components', pi.components
122
123     pi = PipelineInstance.find_by_uuid 'zzzzz-xxxxx-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'
128   end
129
130 end