3 class CollectionsApiTest < ActionDispatch::IntegrationTest
6 test "should get index" do
7 get "/arvados/v1/collections", {:format => :json}, auth(:active)
8 assert_response :success
9 assert_equal "arvados#collectionList", json_response['kind']
12 test "get index with filters= (empty string)" do
13 get "/arvados/v1/collections", {:format => :json, :filters => ''}, auth(:active)
14 assert_response :success
15 assert_equal "arvados#collectionList", json_response['kind']
18 test "get index with invalid filters (array of strings) responds 422" do
19 get "/arvados/v1/collections", {
21 :filters => ['uuid', '=', 'ad02e37b6a7f45bbe2ead3c29a109b8a+54'].to_json
24 assert_match /nvalid element.*not an array/, json_response['errors'].join(' ')
27 test "get index with invalid filters (unsearchable column) responds 422" do
28 get "/arvados/v1/collections", {
30 :filters => [['this_column_does_not_exist', '=', 'bogus']].to_json
33 assert_match /nvalid attribute/, json_response['errors'].join(' ')
36 test "get index with invalid filters (invalid operator) responds 422" do
37 get "/arvados/v1/collections", {
39 :filters => [['uuid', ':-(', 'displeased']].to_json
42 assert_match /nvalid operator/, json_response['errors'].join(' ')
45 test "get index with invalid filters (invalid operand type) responds 422" do
46 get "/arvados/v1/collections", {
48 :filters => [['uuid', '=', {foo: 'bar'}]].to_json
51 assert_match /nvalid operand type/, json_response['errors'].join(' ')
54 test "get index with where= (empty string)" do
55 get "/arvados/v1/collections", {:format => :json, :where => ''}, auth(:active)
56 assert_response :success
57 assert_equal "arvados#collectionList", json_response['kind']
60 test "controller 404 response is json" do
61 get "/arvados/v1/thingsthatdonotexist", {:format => :xml}, auth(:active)
63 assert_equal 1, json_response['errors'].length
64 assert_equal true, json_response['errors'][0].is_a?(String)
67 test "object 404 response is json" do
68 get "/arvados/v1/groups/zzzzz-j7d0g-o5ba971173cup4f", {}, auth(:active)
70 assert_equal 1, json_response['errors'].length
71 assert_equal true, json_response['errors'][0].is_a?(String)
74 test "store collection as json" do
76 key: Rails.configuration.blob_signing_key,
77 api_token: api_token(:active),
79 signed_locator = Blob.sign_locator('bad42fa702ae3ea7d888fef11b46f450+44',
81 post "/arvados/v1/collections", {
83 collection: "{\"manifest_text\":\". #{signed_locator} 0:44:md5sum.txt\\n\",\"portable_data_hash\":\"ad02e37b6a7f45bbe2ead3c29a109b8a+54\"}"
86 assert_equal 'ad02e37b6a7f45bbe2ead3c29a109b8a+54', json_response['portable_data_hash']
89 test "store collection with manifest_text only" do
91 key: Rails.configuration.blob_signing_key,
92 api_token: api_token(:active),
94 signed_locator = Blob.sign_locator('bad42fa702ae3ea7d888fef11b46f450+44',
96 post "/arvados/v1/collections", {
98 collection: "{\"manifest_text\":\". #{signed_locator} 0:44:md5sum.txt\\n\"}"
101 assert_equal 'ad02e37b6a7f45bbe2ead3c29a109b8a+54', json_response['portable_data_hash']
104 test "store collection then update name" do
106 key: Rails.configuration.blob_signing_key,
107 api_token: api_token(:active),
109 signed_locator = Blob.sign_locator('bad42fa702ae3ea7d888fef11b46f450+44',
111 post "/arvados/v1/collections", {
113 collection: "{\"manifest_text\":\". #{signed_locator} 0:44:md5sum.txt\\n\",\"portable_data_hash\":\"ad02e37b6a7f45bbe2ead3c29a109b8a+54\"}"
116 assert_equal 'ad02e37b6a7f45bbe2ead3c29a109b8a+54', json_response['portable_data_hash']
118 put "/arvados/v1/collections/#{json_response['uuid']}", {
120 collection: { name: "a name" }
124 assert_equal 'ad02e37b6a7f45bbe2ead3c29a109b8a+54', json_response['portable_data_hash']
125 assert_equal 'a name', json_response['name']
127 get "/arvados/v1/collections/#{json_response['uuid']}", {
132 assert_equal 'ad02e37b6a7f45bbe2ead3c29a109b8a+54', json_response['portable_data_hash']
133 assert_equal 'a name', json_response['name']
136 test "update description for a collection, and search for that description" do
137 collection = collections(:multilevel_collection_1)
139 # update collection's description
140 put "/arvados/v1/collections/#{collection['uuid']}", {
142 collection: { description: "something specific" }
144 assert_response :success
145 assert_equal 'something specific', json_response['description']
147 # get the collection and verify newly added description
148 get "/arvados/v1/collections/#{collection['uuid']}", {
152 assert_equal 'something specific', json_response['description']
155 search_using_filter 'specific', 1
156 search_using_filter 'not specific enough', 0
159 test "create collection, update manifest, and search with filename" do
161 signed_manifest = Collection.sign_manifest(". bad42fa702ae3ea7d888fef11b46f450+44 0:44:my_test_file.txt\n", api_token(:active))
162 post "/arvados/v1/collections", {
164 collection: {manifest_text: signed_manifest}.to_json,
166 assert_response :success
167 assert_equal true, json_response['manifest_text'].include?('my_test_file.txt')
168 assert_includes json_response['manifest_text'], 'my_test_file.txt'
170 created = json_response
172 # search using the filename
173 search_using_filter 'my_test_file.txt', 1
175 # update the collection's manifest text
176 signed_manifest = Collection.sign_manifest(". bad42fa702ae3ea7d888fef11b46f450+44 0:44:my_updated_test_file.txt\n", api_token(:active))
177 put "/arvados/v1/collections/#{created['uuid']}", {
179 collection: {manifest_text: signed_manifest}.to_json,
181 assert_response :success
182 assert_equal created['uuid'], json_response['uuid']
183 assert_includes json_response['manifest_text'], 'my_updated_test_file.txt'
184 assert_not_includes json_response['manifest_text'], 'my_test_file.txt'
186 # search using the new filename
187 search_using_filter 'my_updated_test_file.txt', 1
188 search_using_filter 'my_test_file.txt', 0
189 search_using_filter 'there_is_no_such_file.txt', 0
192 def search_using_filter search_filter, expected_items
193 get '/arvados/v1/collections', {
194 :filters => [['any', 'ilike', "%#{search_filter}%"]].to_json
196 assert_response :success
197 response_items = json_response['items']
198 assert_not_nil response_items
199 if expected_items == 0
200 assert_empty response_items
202 refute_empty response_items
203 first_item = response_items.first
204 assert_not_nil first_item
208 test "search collection using full text search" do
209 # create collection to be searched for
210 signed_manifest = Collection.sign_manifest(". 85877ca2d7e05498dd3d109baf2df106+95+A3a4e26a366ee7e4ed3e476ccf05354761be2e4ae@545a9920 0:95:file_in_subdir1\n./subdir2/subdir3 2bbc341c702df4d8f42ec31f16c10120+64+A315d7e7bad2ce937e711fc454fae2d1194d14d64@545a9920 0:32:file1_in_subdir3.txt 32:32:file2_in_subdir3.txt\n./subdir2/subdir3/subdir4 2bbc341c702df4d8f42ec31f16c10120+64+A315d7e7bad2ce937e711fc454fae2d1194d14d64@545a9920 0:32:file3_in_subdir4.txt 32:32:file4_in_subdir4.txt\n", api_token(:active))
211 post "/arvados/v1/collections", {
213 collection: {description: 'specific collection description', manifest_text: signed_manifest}.to_json,
215 assert_response :success
216 assert_equal true, json_response['manifest_text'].include?('file4_in_subdir4.txt')
218 created = json_response
220 # search using the filename
221 search_using_full_text_search 'subdir2', 0
222 search_using_full_text_search 'subdir2:*', 1
223 search_using_full_text_search 'subdir2/subdir3/subdir4', 1
224 search_using_full_text_search 'file4:*', 1
225 search_using_full_text_search 'file4_in_subdir4.txt', 1
226 search_using_full_text_search 'subdir2 file4:*', 0 # first word is incomplete
227 search_using_full_text_search 'subdir2/subdir3/subdir4 file4:*', 1
228 search_using_full_text_search 'subdir2/subdir3/subdir4 file4_in_subdir4.txt', 1
229 search_using_full_text_search 'ile4', 0 # not a prefix match
232 def search_using_full_text_search search_filter, expected_items
233 get '/arvados/v1/collections', {
234 :filters => [['any', '@@', search_filter]].to_json
236 assert_response :success
237 response_items = json_response['items']
238 assert_not_nil response_items
239 if expected_items == 0
240 assert_empty response_items
242 refute_empty response_items
243 first_item = response_items.first
244 assert_not_nil first_item
248 # search for the filename in the file_names column and expect error
249 test "full text search not supported for individual columns" do
250 get '/arvados/v1/collections', {
251 :filters => [['name', '@@', 'General']].to_json
261 ].each do |search_filter|
262 test "full text search ignores special characters and finds with filter #{search_filter}" do
263 # description: The quick_brown_fox jumps over the lazy_dog
264 # full text search treats '_' as space apparently
265 get '/arvados/v1/collections', {
266 :filters => [['any', '@@', search_filter]].to_json
269 response_items = json_response['items']
270 assert_not_nil response_items
271 first_item = response_items.first
272 refute_empty first_item
273 assert_equal first_item['description'], 'The quick_brown_fox jumps over the lazy_dog'
277 test "create and get collection with properties" do
278 # create collection to be searched for
279 signed_manifest = Collection.sign_manifest(". bad42fa702ae3ea7d888fef11b46f450+44 0:44:my_test_file.txt\n", api_token(:active))
280 post "/arvados/v1/collections", {
282 collection: {manifest_text: signed_manifest}.to_json,
285 assert_not_nil json_response['uuid']
286 assert_not_nil json_response['properties']
287 assert_empty json_response['properties']
289 # update collection's description
290 put "/arvados/v1/collections/#{json_response['uuid']}", {
292 collection: { properties: {'property_1' => 'value_1'} }
294 assert_response :success
295 assert_equal 'value_1', json_response['properties']['property_1']