14717: Fixups since tests now use config.yml
[arvados.git] / apps / workbench / test / integration / jobs_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'fileutils'
6 require 'tmpdir'
7
8 require 'integration_helper'
9
10 class JobsTest < ActionDispatch::IntegrationTest
11   setup do
12       need_javascript
13   end
14
15   def fakepipe_with_log_data
16     content =
17       "2014-01-01_12:00:01 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 1\n" +
18       "2014-01-01_12:00:02 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 2\n" +
19       "2014-01-01_12:00:03 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 3\n"
20     StringIO.new content, 'r'
21   end
22
23   test "add job description" do
24     job = api_fixture('jobs')['nearly_finished_job']
25     visit page_with_token("active", "/jobs/#{job['uuid']}")
26
27     # edit job description
28     within('.arv-description-as-subtitle') do
29       find('.fa-pencil').click
30       find('.editable-input textarea').set('*Textile description for job* - "Go to dashboard":/')
31       find('.editable-submit').click
32     end
33
34     # Verify edited description
35     assert_no_text '*Textile description for job*'
36     assert_text 'Textile description for job'
37     assert_selector 'a[href="/"]', text: 'Go to dashboard'
38   end
39
40   test 'view partial job log' do
41     need_selenium 'to be able to see the CORS response headers (PhantomJS 1.9.8 does not)'
42     use_keep_web_config
43
44     # This config will be restored during teardown by ../test_helper.rb:
45     Rails.configuration.Workbench.LogViewerMaxBytes = 100
46
47     logdata = fakepipe_with_log_data.read
48     job_uuid = api_fixture('jobs')['running']['uuid']
49     logcollection = upload_data_and_get_collection(logdata, 'active', "#{job_uuid}.log.txt")
50     job = nil
51     use_token 'active' do
52       job = Job.find job_uuid
53       job.update_attributes log: logcollection.portable_data_hash
54     end
55     visit page_with_token 'active', '/jobs/'+job.uuid
56     find('a[href="#Log"]').click
57     wait_for_ajax
58     assert_text 'Showing only 100 bytes of this log'
59   end
60
61   test 'view log via keep-web redirect' do
62     use_keep_web_config
63
64     token = api_token('active')
65     logdata = fakepipe_with_log_data.read
66     logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
67     assert $?.success?, $?
68
69     job = nil
70     use_token 'active' do
71       job = Job.find api_fixture('jobs')['running']['uuid']
72       mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
73       logcollection = Collection.create(manifest_text: mtxt)
74       job.update_attributes log: logcollection.portable_data_hash
75     end
76     visit page_with_token 'active', '/jobs/'+job.uuid
77     find('a[href="#Log"]').click
78     assert_text 'log message 1'
79   end
80
81   [
82     ['foobar', false, false],
83     ['job_with_latest_version', true, false],
84     ['job_with_latest_version', true, true],
85   ].each do |job_name, expect_options, use_latest|
86     test "Rerun #{job_name} job, expect options #{expect_options},
87           and use latest version option #{use_latest}" do
88       job = api_fixture('jobs')[job_name]
89       visit page_with_token 'active', '/jobs/'+job['uuid']
90
91       if expect_options
92         assert_text 'supplied_script_version: master'
93       else
94         assert_no_text 'supplied_script_version'
95       end
96
97       assert_triggers_dom_event 'shown.bs.modal' do
98         find('a,button', text: 'Re-run job...').click
99       end
100       within('.modal-dialog') do
101         assert_selector 'a,button', text: 'Cancel'
102         if use_latest
103           page.choose("job_script_version_#{job['supplied_script_version']}")
104         end
105         click_on "Run now"
106       end
107
108       # Re-running jobs doesn't currently work because the test API
109       # server has no git repository to check against.  For now, check
110       # that the error message says something appropriate for that
111       # situation.
112       if expect_options && use_latest
113         assert_text "077ba2ad3ea24a929091a9e6ce545c93199b8e57"
114       else
115         assert_text "Script version #{job['script_version']} does not resolve to a commit"
116       end
117     end
118   end
119
120   [
121     ['active', true],
122     ['job_reader2', false],
123   ].each do |user, readable|
124     test "view job with components as #{user} user" do
125       job = api_fixture('jobs')['running_job_with_components']
126       component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
127       component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
128       component2_child1 = api_fixture('jobs')['previous_job_run']
129       component2_child2 = api_fixture('jobs')['running']
130
131       visit page_with_token(user, "/jobs/#{job['uuid']}")
132       assert page.has_text? job['script_version']
133       assert page.has_no_text? 'script_parameters'
134
135       # The job_reader2 is allowed to read job, component2, and component2_child1,
136       # and component2_child2 only as a component of the pipeline component2
137       if readable
138         assert page.has_link? 'component1'
139         assert page.has_link? 'component2'
140       else
141         assert page.has_no_link? 'component1'
142         assert page.has_link? 'component2'
143       end
144
145       if readable
146         click_link('component1')
147         within('.panel-collapse') do
148           assert(has_text? component1['uuid'])
149           assert(has_text? component1['script_version'])
150           assert(has_text? 'script_parameters')
151         end
152         click_link('component1')
153       end
154
155       click_link('component2')
156       within('.panel-collapse') do
157         assert(has_text? component2['uuid'])
158         assert(has_text? component2['script_version'])
159         assert(has_no_text? 'script_parameters')
160         assert(has_link? 'previous')
161         assert(has_link? 'running')
162
163         click_link('previous')
164         within('.panel-collapse') do
165           assert(has_text? component2_child1['uuid'])
166           assert(has_text? component2_child1['script_version'])
167         end
168         click_link('previous')
169
170         click_link('running')
171         within('.panel-collapse') do
172           assert(has_text? component2_child2['uuid'])
173           if readable
174             assert(has_text? component2_child2['script_version'])
175           else
176             assert(has_no_text? component2_child2['script_version'])
177           end
178         end
179       end
180     end
181   end
182 end