X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9052027ce0c8e3f3a338b4b1541bf4119185c327..431b8df752ca99dd8aa777864f7c5ada650d0ac9:/services/api/test/integration/collections_api_test.rb diff --git a/services/api/test/integration/collections_api_test.rb b/services/api/test/integration/collections_api_test.rb index b7194b6797..73cbad6430 100644 --- a/services/api/test/integration/collections_api_test.rb +++ b/services/api/test/integration/collections_api_test.rb @@ -275,6 +275,41 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest end end + [ + ["false", false], + ["0", false], + ["true", true], + ["1", true] + ].each do |param, truthiness| + test "include_trash=#{param.inspect} param JSON-encoded should be interpreted as include_trash=#{truthiness}" do + expired_col = collections(:expired_collection) + assert expired_col.is_trashed + # Try #index first + post "/arvados/v1/collections", + params: { + :_method => 'GET', + :include_trash => param, + :filters => [['uuid', '=', expired_col.uuid]].to_json + }, + headers: auth(:active) + assert_response :success + assert_not_nil json_response['items'] + assert_equal truthiness, json_response['items'].collect {|c| c['uuid']}.include?(expired_col.uuid) + # Try #show next + post "/arvados/v1/collections/#{expired_col.uuid}", + params: { + :_method => 'GET', + :include_trash => param, + }, + headers: auth(:active) + if truthiness + assert_response :success + else + assert_response 404 + end + end + end + [ ["false", false], ["0", false], @@ -291,7 +326,7 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest assert_not_nil json_response['items'] assert_equal truthiness, json_response['items'].collect {|c| c['uuid']}.include?(expired_col.uuid) # Try #show next - get("/arvados/v1/collections/#{expired_col.uuid}/?include_trash=#{param}", + get("/arvados/v1/collections/#{expired_col.uuid}?include_trash=#{param}", headers: auth(:active)) if truthiness assert_response :success @@ -311,11 +346,12 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest expired_col = collections(:expired_collection) assert expired_col.is_trashed params = [ + ['_method', 'GET'], ['include_trash', param], ['filters', [['uuid','=',expired_col.uuid]].to_json], ] # Try #index first - get "/arvados/v1/collections", + post "/arvados/v1/collections", params: URI.encode_www_form(params), headers: { "Content-type" => "application/x-www-form-urlencoded" @@ -324,8 +360,8 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest assert_not_nil json_response['items'] assert_equal truthiness, json_response['items'].collect {|c| c['uuid']}.include?(expired_col.uuid) # Try #show next - get "/arvados/v1/collections", - params: URI.encode_www_form([['include_trash', param]]), + post "/arvados/v1/collections/#{expired_col.uuid}", + params: URI.encode_www_form([['_method', 'GET'],['include_trash', param]]), headers: { "Content-type" => "application/x-www-form-urlencoded" }.update(auth(:active)) @@ -459,4 +495,82 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest assert_equal Hash, json_response['properties'].class, 'Collection properties attribute should be of type hash' assert_equal 'value_1', json_response['properties']['property_1'] end + + test "update collection with versioning enabled and using preserve_version" do + Rails.configuration.Collections.CollectionVersioning = true + Rails.configuration.Collections.PreserveVersionIfIdle = -1 # Disable auto versioning + + signed_manifest = Collection.sign_manifest(". bad42fa702ae3ea7d888fef11b46f450+44 0:44:my_test_file.txt\n", api_token(:active)) + post "/arvados/v1/collections", + params: { + format: :json, + collection: { + name: 'Test collection', + manifest_text: signed_manifest, + }.to_json, + }, + headers: auth(:active) + assert_response 200 + assert_not_nil json_response['uuid'] + assert_equal 1, json_response['version'] + assert_equal false, json_response['preserve_version'] + + # Versionable update including preserve_version=true should create a new + # version that will also be persisted. + put "/arvados/v1/collections/#{json_response['uuid']}", + params: { + format: :json, + collection: { + name: 'Test collection v2', + preserve_version: true, + }.to_json, + }, + headers: auth(:active) + assert_response 200 + assert_equal 2, json_response['version'] + assert_equal true, json_response['preserve_version'] + + # 2nd versionable update including preserve_version=true should create a new + # version that will also be persisted. + put "/arvados/v1/collections/#{json_response['uuid']}", + params: { + format: :json, + collection: { + name: 'Test collection v3', + preserve_version: true, + }.to_json, + }, + headers: auth(:active) + assert_response 200 + assert_equal 3, json_response['version'] + assert_equal true, json_response['preserve_version'] + + # 3rd versionable update without including preserve_version should create a new + # version that will have its preserve_version attr reset to false. + put "/arvados/v1/collections/#{json_response['uuid']}", + params: { + format: :json, + collection: { + name: 'Test collection v4', + }.to_json, + }, + headers: auth(:active) + assert_response 200 + assert_equal 4, json_response['version'] + assert_equal false, json_response['preserve_version'] + + # 4th versionable update without including preserve_version=true should NOT + # create a new version. + put "/arvados/v1/collections/#{json_response['uuid']}", + params: { + format: :json, + collection: { + name: 'Test collection v5?', + }.to_json, + }, + headers: auth(:active) + assert_response 200 + assert_equal 4, json_response['version'] + assert_equal false, json_response['preserve_version'] + end end