X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2e5ac62b550f7dd608cf133ae66ef04f801be76b..6c564c9ce38a31df9f14e1988f4065c4854516d8:/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 983885d1ad..e67f1b1a9b 100644 --- a/services/api/test/integration/collections_api_test.rb +++ b/services/api/test/integration/collections_api_test.rb @@ -57,6 +57,34 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest assert_equal "arvados#collectionList", json_response['kind'] end + test "get index with select= (valid attribute)" do + get "/arvados/v1/collections", { + :format => :json, + :select => ['portable_data_hash'].to_json + }, auth(:active) + assert_response :success + assert json_response['items'][0].keys.include?('portable_data_hash') + assert not(json_response['items'][0].keys.include?('uuid')) + end + + test "get index with select= (invalid attribute) responds 422" do + get "/arvados/v1/collections", { + :format => :json, + :select => ['bogus'].to_json + }, auth(:active) + assert_response 422 + assert_match /Invalid attribute.*bogus/, json_response['errors'].join(' ') + end + + test "get index with select= (invalid attribute type) responds 422" do + get "/arvados/v1/collections", { + :format => :json, + :select => [['bogus']].to_json + }, auth(:active) + assert_response 422 + assert_match /Attribute.*should be a string/, json_response['errors'].join(' ') + end + test "controller 404 response is json" do get "/arvados/v1/thingsthatdonotexist", {:format => :xml}, auth(:active) assert_response 404 @@ -218,14 +246,15 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest created = json_response # search using the filename - search_using_full_text_search 'subdir2', 1 - search_using_full_text_search 'subdir2/subdir', 1 + search_using_full_text_search 'subdir2', 0 + search_using_full_text_search 'subdir2:*', 1 search_using_full_text_search 'subdir2/subdir3/subdir4', 1 - search_using_full_text_search 'file4', 1 - search_using_full_text_search 'file4_in_subdir', 1 - search_using_full_text_search 'subdir2 file4', 1 # look for prefixes subdir2 and file4 - search_using_full_text_search 'subdir2 ile4', 0 + search_using_full_text_search 'file4:*', 1 + search_using_full_text_search 'file4_in_subdir4.txt', 1 + search_using_full_text_search 'subdir2 file4:*', 0 # first word is incomplete + search_using_full_text_search 'subdir2/subdir3/subdir4 file4:*', 1 search_using_full_text_search 'subdir2/subdir3/subdir4 file4_in_subdir4.txt', 1 + search_using_full_text_search 'ile4', 0 # not a prefix match end def search_using_full_text_search search_filter, expected_items @@ -251,4 +280,46 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest }, auth(:active) assert_response 422 end + + [ + 'quick fox', + 'quick_brown fox', + 'brown_ fox', + 'fox dogs', + ].each do |search_filter| + test "full text search ignores special characters and finds with filter #{search_filter}" do + # description: The quick_brown_fox jumps over the lazy_dog + # full text search treats '_' as space apparently + get '/arvados/v1/collections', { + :filters => [['any', '@@', search_filter]].to_json + }, auth(:active) + assert_response 200 + response_items = json_response['items'] + assert_not_nil response_items + first_item = response_items.first + refute_empty first_item + assert_equal first_item['description'], 'The quick_brown_fox jumps over the lazy_dog' + end + end + + test "create and get collection with properties" do + # create collection to be searched for + signed_manifest = Collection.sign_manifest(". bad42fa702ae3ea7d888fef11b46f450+44 0:44:my_test_file.txt\n", api_token(:active)) + post "/arvados/v1/collections", { + format: :json, + collection: {manifest_text: signed_manifest}.to_json, + }, auth(:active) + assert_response 200 + assert_not_nil json_response['uuid'] + assert_not_nil json_response['properties'] + assert_empty json_response['properties'] + + # update collection's description + put "/arvados/v1/collections/#{json_response['uuid']}", { + format: :json, + collection: { properties: {'property_1' => 'value_1'} } + }, auth(:active) + assert_response :success + assert_equal 'value_1', json_response['properties']['property_1'] + end end