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