3 class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
5 test "should get index" do
8 assert_response :success
9 assert_not_nil assigns(:objects)
12 [0,1,2].each do |limit|
13 test "get index with limit=#{limit}" do
14 authorize_with :active
15 get :index, limit: limit
16 assert_response :success
17 assert_equal limit, assigns(:objects).count
18 resp = JSON.parse(@response.body)
19 assert_equal limit, resp['limit']
23 test "items.count == items_available" do
24 authorize_with :active
25 get :index, limit: 100000
26 assert_response :success
27 resp = JSON.parse(@response.body)
28 assert_equal resp['items_available'], assigns(:objects).length
29 assert_equal resp['items_available'], resp['items'].count
30 unique_uuids = resp['items'].collect { |i| i['uuid'] }.compact.uniq
31 assert_equal unique_uuids.count, resp['items'].count
34 test "get index with limit=2 offset=99999" do
35 # Assume there are not that many test fixtures.
36 authorize_with :active
37 get :index, limit: 2, offset: 99999
38 assert_response :success
39 assert_equal 0, assigns(:objects).count
40 resp = JSON.parse(@response.body)
41 assert_equal 2, resp['limit']
42 assert_equal 99999, resp['offset']
45 test "should create" do
46 authorize_with :active
49 . d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt
50 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
51 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
52 ./baz acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
55 test_collection[:uuid] =
56 Digest::MD5.hexdigest(test_collection[:manifest_text]) +
58 test_collection[:manifest_text].length.to_s
60 collection: test_collection
62 assert_response :success
63 assert_nil assigns(:objects)
66 id: test_collection[:uuid]
68 assert_response :success
69 assert_not_nil assigns(:object)
70 resp = JSON.parse(@response.body)
71 assert_equal test_collection[:uuid], resp['uuid']
72 assert_equal test_collection[:manifest_text], resp['manifest_text']
73 assert_equal 9, resp['data_size']
74 assert_equal [['.', 'foo.txt', 0],
76 ['./baz', 'bar.txt', 3]], resp['files']
79 test "list of files is correct for empty manifest" do
80 authorize_with :active
83 uuid: "d41d8cd98f00b204e9800998ecf8427e+0"
86 collection: test_collection
88 assert_response :success
91 id: "d41d8cd98f00b204e9800998ecf8427e+0"
93 assert_response :success
94 resp = JSON.parse(@response.body)
95 assert_equal [], resp['files']
98 test "create with owner_uuid set to owned group" do
99 authorize_with :active
100 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
103 owner_uuid: 'zzzzz-j7d0g-rew6elm53kancon',
104 manifest_text: manifest_text,
105 uuid: "d30fe8ae534397864cb96c544f4cf102"
108 assert_response :success
109 resp = JSON.parse(@response.body)
110 assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
113 test "create with owner_uuid set to group i can_manage" do
114 authorize_with :active
115 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
118 owner_uuid: 'zzzzz-j7d0g-8ulrifv67tve5sx',
119 manifest_text: manifest_text,
120 uuid: "d30fe8ae534397864cb96c544f4cf102"
123 assert_response :success
124 resp = JSON.parse(@response.body)
125 assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
128 test "create with owner_uuid set to group with no can_manage permission" do
129 authorize_with :active
130 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
133 owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
134 manifest_text: manifest_text,
135 uuid: "d30fe8ae534397864cb96c544f4cf102"
141 test "admin create with owner_uuid set to group with no permission" do
142 authorize_with :admin
143 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
146 owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
147 manifest_text: manifest_text,
148 uuid: "d30fe8ae534397864cb96c544f4cf102"
151 assert_response :success
154 test "should create with collection passed as json" do
155 authorize_with :active
159 "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",\
160 "uuid":"d30fe8ae534397864cb96c544f4cf102"\
164 assert_response :success
167 test "should fail to create with checksum mismatch" do
168 authorize_with :active
172 "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:bar.txt\n",\
173 "uuid":"d30fe8ae534397864cb96c544f4cf102"\
180 test "get full provenance for baz file" do
181 authorize_with :active
182 get :provenance, id: 'ea10d51bcf88862dbcc36eb292017dfd+45'
183 assert_response :success
184 resp = JSON.parse(@response.body)
185 assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
186 assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
187 assert_not_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
188 assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
189 assert_not_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
192 test "get no provenance for foo file" do
193 # spectator user cannot even see baz collection
194 authorize_with :spectator
195 get :provenance, id: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
199 test "get partial provenance for baz file" do
200 # spectator user can see bar->baz job, but not foo->bar job
201 authorize_with :spectator
202 get :provenance, id: 'ea10d51bcf88862dbcc36eb292017dfd+45'
203 assert_response :success
204 resp = JSON.parse(@response.body)
205 assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
206 assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
207 assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
208 assert_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
209 assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
212 test "search collections with 'any' operator" do
213 authorize_with :active
215 where: { any: ['contains', '7f9102c395f4ffc5e3'] }
217 assert_response :success
218 found = assigns(:objects).collect(&:uuid)
219 assert_equal 1, found.count
220 assert_equal true, !!found.index('1f4b0bc7583c2a7f9102c395f4ffc5e3+45')