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')
169 created = json_response
171 # search using the filename
172 search_using_filter 'my_test_file.txt', 1
174 # update the collection's manifest text
175 signed_manifest = Collection.sign_manifest(". bad42fa702ae3ea7d888fef11b46f450+44 0:44:my_updated_test_file.txt\n", api_token(:active))
176 put "/arvados/v1/collections/#{created['uuid']}", {
178 collection: {manifest_text: signed_manifest}.to_json,
180 assert_response :success
181 assert_equal created['uuid'], json_response['uuid']
182 assert_equal true, json_response['manifest_text'].include?('my_updated_test_file.txt')
183 assert_equal false, json_response['manifest_text'].include?('my_test_file.txt')
185 # search using the new filename
186 search_using_filter 'my_updated_test_file.txt', 1
187 search_using_filter 'my_test_file.txt', 0
188 search_using_filter 'there_is_no_such_file.txt', 0
191 def search_using_filter search_filter, expected_items
192 get '/arvados/v1/collections', {
193 :filters => [['any', 'ilike', "%#{search_filter}%"]].to_json
195 assert_response :success
196 response_items = json_response['items']
197 assert_not_nil response_items
198 if expected_items == 0
199 assert_equal 0, json_response['items_available']
200 assert_equal 0, response_items.size
202 assert_equal expected_items, response_items.size
203 first_item = response_items.first
204 assert_not_nil first_item