Merge remote-tracking branch 'origin/master' into 15106-trgm-text-search
[arvados.git] / services / api / test / integration / jobs_api_test.rb
index 89eb84ff4c65c862611f6bc3782fbbf11ac048a2..f5fb920b46d82e4e48bd06c5db1b145ebd5279b3 100644 (file)
@@ -1,32 +1,42 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 
 class JobsApiTest < ActionDispatch::IntegrationTest
   fixtures :all
 
   test "cancel job" do
-    post "/arvados/v1/jobs/#{jobs(:running).uuid}/cancel", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:active).api_token}"}
+    post "/arvados/v1/jobs/#{jobs(:running).uuid}/cancel",
+      params: {:format => :json},
+      headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:active).api_token}"}
     assert_response :success
     assert_equal "arvados#job", json_response['kind']
     assert_not_nil json_response['cancelled_at']
   end
 
   test "cancel someone else's visible job" do
-    post "/arvados/v1/jobs/#{jobs(:barbaz).uuid}/cancel", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
+    post "/arvados/v1/jobs/#{jobs(:runningbarbaz).uuid}/cancel",
+      params: {:format => :json},
+      headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
     assert_response 403
   end
 
   test "cancel someone else's invisible job" do
-    post "/arvados/v1/jobs/#{jobs(:running).uuid}/cancel", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
+    post "/arvados/v1/jobs/#{jobs(:running).uuid}/cancel",
+      params: {:format => :json},
+      headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
     assert_response 404
   end
 
   test "task qsequence values automatically increase monotonically" do
     post_args = ["/arvados/v1/job_tasks",
-                 {job_task: {
+                 params: {job_task: {
                      job_uuid: jobs(:running).uuid,
                      sequence: 1,
                    }},
-                 auth(:active)]
+                 headers: auth(:active)]
     last_qsequence = -1
     (1..3).each do |task_num|
       @response = nil
@@ -39,4 +49,43 @@ class JobsApiTest < ActionDispatch::IntegrationTest
       last_qsequence = qsequence
     end
   end
+
+  test 'get_delete components_get again for job with components' do
+    authorize_with :active
+    get "/arvados/v1/jobs/#{jobs(:running_job_with_components).uuid}",
+      headers: auth(:active)
+    assert_response 200
+    assert_not_nil json_response["components"]
+    assert_equal ["component1", "component2"], json_response["components"].keys
+
+    # delete second component
+    put "/arvados/v1/jobs/#{jobs(:running_job_with_components).uuid}", params: {
+      job: {
+        components: {"component1" => "zzzzz-8i9sb-jobuuid00000001"}
+      },
+      limit: 1000
+    }, headers: auth(:active)
+    assert_response 200
+
+    get "/arvados/v1/jobs/#{jobs(:running_job_with_components).uuid}",
+      headers: auth(:active)
+    assert_response 200
+    assert_not_nil json_response["components"]
+    assert_equal ["component1"], json_response["components"].keys
+
+    # delete all components
+    put "/arvados/v1/jobs/#{jobs(:running_job_with_components).uuid}", params: {
+      job: {
+        components: nil
+      },
+      limit: 1000
+    }, headers: auth(:active)
+    assert_response 200
+
+    get "/arvados/v1/jobs/#{jobs(:running_job_with_components).uuid}",
+      headers: auth(:active)
+    assert_response 200
+    assert_not_nil json_response["components"]
+    assert_equal [], json_response["components"].keys
+  end
 end