2411: Add copyright notices to everything.
[arvados.git] / apps / workbench / test / controllers / container_requests_controller_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class ContainerRequestsControllerTest < ActionController::TestCase
8   test "visit completed container request log tab" do
9     use_token 'active'
10
11     cr = api_fixture('container_requests')['completed']
12     container_uuid = cr['container_uuid']
13     container = Container.find(container_uuid)
14
15     get :show, {id: cr['uuid'], tab_pane: 'Log'}, session_for(:active)
16     assert_response :success
17
18     assert_select "a", {:href=>"/collections/#{container['log']}", :text=>"Download the log"}
19     assert_select "a", {:href=>"#{container['log']}/baz"}
20     assert_not_includes @response.body, '<div id="event_log_div"'
21   end
22
23   test "visit running container request log tab" do
24     use_token 'active'
25
26     cr = api_fixture('container_requests')['running']
27     container_uuid = cr['container_uuid']
28     container = Container.find(container_uuid)
29
30     get :show, {id: cr['uuid'], tab_pane: 'Log'}, session_for(:active)
31     assert_response :success
32
33     assert_includes @response.body, '<div id="event_log_div"'
34     assert_select 'Download the log', false
35   end
36
37   test "completed container request offers re-run option" do
38     use_token 'active'
39
40     uuid = api_fixture('container_requests')['completed']['uuid']
41
42     get :show, {id: uuid}, session_for(:active)
43     assert_response :success
44
45    assert_includes @response.body, "action=\"/container_requests/#{uuid}/copy\""
46   end
47
48   [
49     ['completed', false, false],
50     ['completed', true, false],
51     ['completed-older', false, true],
52     ['completed-older', true, true],
53   ].each do |cr_fixture, reuse_enabled, uses_acr|
54     test "container request #{uses_acr ? '' : 'not'} using arvados-cwl-runner copy #{reuse_enabled ? 'with' : 'without'} reuse enabled" do
55       completed_cr = api_fixture('container_requests')[cr_fixture]
56       # Set up post request params
57       copy_params = {id: completed_cr['uuid']}
58       if reuse_enabled
59         copy_params.merge!({use_existing: true})
60       end
61       post(:copy, copy_params, session_for(:active))
62       assert_response 302
63       copied_cr = assigns(:object)
64       assert_not_nil copied_cr
65       assert_equal 'Uncommitted', copied_cr[:state]
66       assert_equal "Copy of #{completed_cr['name']}", copied_cr['name']
67       assert_equal completed_cr['cmd'], copied_cr['cmd']
68       assert_equal completed_cr['runtime_constraints']['ram'], copied_cr['runtime_constraints'][:ram]
69       if reuse_enabled
70         assert copied_cr[:use_existing]
71       else
72         refute copied_cr[:use_existing]
73       end
74       # If the CR's command is arvados-cwl-runner, the appropriate flag should
75       # be passed to it
76       if uses_acr
77         if reuse_enabled
78           # arvados-cwl-runner's default behavior is to enable reuse
79           assert_includes copied_cr['command'], 'arvados-cwl-runner'
80           assert_not_includes copied_cr['command'], '--disable-reuse'
81         else
82           assert_includes copied_cr['command'], 'arvados-cwl-runner'
83           assert_includes copied_cr['command'], '--disable-reuse'
84           assert_not_includes copied_cr['command'], '--enable-reuse'
85         end
86       else
87         # If no arvados-cwl-runner is being used, the command should be left alone
88         assert_equal completed_cr['command'], copied_cr['command']
89       end
90     end
91   end
92
93   [
94     ['completed', true],
95     ['running', true],
96     ['queued', true],
97     ['uncommitted', false],
98   ].each do |cr_fixture, should_show|
99     test "provenance tab should #{should_show ? '' : 'not'} be shown on #{cr_fixture} container requests" do
100       cr = api_fixture('container_requests')[cr_fixture]
101       assert_not_nil cr
102       get(:show,
103           {id: cr['uuid']},
104           session_for(:active))
105       assert_response :success
106       if should_show
107         assert_includes @response.body, "href=\"#Provenance\""
108       else
109         assert_not_includes @response.body, "href=\"#Provenance\""
110       end
111     end
112   end
113
114   test "container request display" do
115     use_token 'active'
116
117     cr = api_fixture('container_requests')['completed_with_input_mounts']
118
119     get :show, {id: cr['uuid']}, session_for(:active)
120     assert_response :success
121
122     assert_match /hello/, @response.body
123     assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/foo" # mount input1
124     assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/bar" # mount input2
125     assert_includes @response.body, "href=\"\/collections/1fd08fc162a5c6413070a8bd0bffc818+150" # mount workflow
126     assert_includes @response.body, "href=\"#Log\""
127     assert_includes @response.body, "href=\"#Provenance\""
128   end
129 end