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 "get index with limit=2 offset=99999" do
24 # Assume there are not that many test fixtures.
25 authorize_with :active
26 get :index, limit: 2, offset: 99999
27 assert_response :success
28 assert_equal 0, assigns(:objects).count
29 resp = JSON.parse(@response.body)
30 assert_equal 2, resp['limit']
31 assert_equal 99999, resp['offset']
34 test "should create" do
35 authorize_with :active
38 . d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt
39 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
40 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
41 ./baz acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
44 test_collection[:uuid] =
45 Digest::MD5.hexdigest(test_collection[:manifest_text]) +
47 test_collection[:manifest_text].length.to_s
49 collection: test_collection
51 assert_response :success
52 assert_nil assigns(:objects)
55 id: test_collection[:uuid]
57 assert_response :success
58 assert_not_nil assigns(:object)
59 resp = JSON.parse(@response.body)
60 assert_equal test_collection[:uuid], resp['uuid']
61 assert_equal test_collection[:manifest_text], resp['manifest_text']
62 assert_equal 9, resp['data_size']
63 assert_equal [['.', 'foo.txt', 0],
65 ['./baz', 'bar.txt', 3]], resp['files']
68 test "list of files is correct for empty manifest" do
69 authorize_with :active
72 uuid: "d41d8cd98f00b204e9800998ecf8427e+0"
75 collection: test_collection
77 assert_response :success
80 id: "d41d8cd98f00b204e9800998ecf8427e+0"
82 assert_response :success
83 resp = JSON.parse(@response.body)
84 assert_equal [], resp['files']
87 test "create with owner_uuid set to owned group" do
88 authorize_with :active
89 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
92 owner_uuid: 'zzzzz-j7d0g-rew6elm53kancon',
93 manifest_text: manifest_text,
94 uuid: "d30fe8ae534397864cb96c544f4cf102"
97 assert_response :success
98 resp = JSON.parse(@response.body)
99 assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
102 test "create with owner_uuid set to group i can_manage" do
103 authorize_with :active
104 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
107 owner_uuid: 'zzzzz-j7d0g-8ulrifv67tve5sx',
108 manifest_text: manifest_text,
109 uuid: "d30fe8ae534397864cb96c544f4cf102"
112 assert_response :success
113 resp = JSON.parse(@response.body)
114 assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
117 test "create with owner_uuid set to group with no can_manage permission" do
118 authorize_with :active
119 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
122 owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
123 manifest_text: manifest_text,
124 uuid: "d30fe8ae534397864cb96c544f4cf102"
130 test "admin create with owner_uuid set to group with no permission" do
131 authorize_with :admin
132 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
135 owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
136 manifest_text: manifest_text,
137 uuid: "d30fe8ae534397864cb96c544f4cf102"
140 assert_response :success
143 test "should create with collection passed as json" do
144 authorize_with :active
148 "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",\
149 "uuid":"d30fe8ae534397864cb96c544f4cf102"\
153 assert_response :success
156 test "should fail to create with checksum mismatch" do
157 authorize_with :active
161 "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:bar.txt\n",\
162 "uuid":"d30fe8ae534397864cb96c544f4cf102"\
169 test "get full provenance for baz file" do
170 authorize_with :active
171 get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
172 assert_response :success
173 resp = JSON.parse(@response.body)
174 assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
175 assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
176 assert_not_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
177 assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
178 assert_not_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
181 test "get no provenance for foo file" do
182 # spectator user cannot even see baz collection
183 authorize_with :spectator
184 get :provenance, uuid: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
188 test "get partial provenance for baz file" do
189 # spectator user can see bar->baz job, but not foo->bar job
190 authorize_with :spectator
191 get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
192 assert_response :success
193 resp = JSON.parse(@response.body)
194 assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
195 assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
196 assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
197 assert_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
198 assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo