3 class Arvados::V1::GroupsControllerTest < ActionController::TestCase
5 test "attempt to delete group without read or write access" do
7 post :destroy, id: groups(:empty_lonely_group).uuid
11 test "attempt to delete group without write access" do
12 authorize_with :active
13 post :destroy, id: groups(:all_users).uuid
17 test "get list of folders" do
18 authorize_with :active
19 get :index, filters: [['group_class', '=', 'folder']], format: :json
20 assert_response :success
22 json_response['items'].each do |group|
23 assert_equal 'folder', group['group_class']
24 group_uuids << group['uuid']
26 assert_includes group_uuids, groups(:afolder).uuid
27 assert_includes group_uuids, groups(:asubfolder).uuid
28 assert_not_includes group_uuids, groups(:system_group).uuid
29 assert_not_includes group_uuids, groups(:private).uuid
32 test "get list of groups that are not folders" do
33 authorize_with :active
34 get :index, filters: [['group_class', '=', nil]], format: :json
35 assert_response :success
37 json_response['items'].each do |group|
38 assert_equal nil, group['group_class']
39 group_uuids << group['uuid']
41 assert_not_includes group_uuids, groups(:afolder).uuid
42 assert_not_includes group_uuids, groups(:asubfolder).uuid
43 assert_includes group_uuids, groups(:private).uuid
46 test "get list of groups with bogus group_class" do
47 authorize_with :active
49 filters: [['group_class', '=', 'nogrouphasthislittleclass']],
52 assert_response :success
53 assert_equal [], json_response['items']
54 assert_equal 0, json_response['items_available']
57 test 'get group-owned objects' do
58 authorize_with :active
60 id: groups(:afolder).uuid,
64 assert_response :success
65 assert_operator 2, :<=, json_response['items_available']
66 assert_operator 2, :<=, json_response['items'].count
67 kinds = json_response['items'].collect { |i| i['kind'] }.uniq
68 expect_kinds = %w'arvados#group arvados#specimen arvados#pipelineTemplate arvados#job'
69 assert_equal expect_kinds, (expect_kinds & kinds)
72 test 'get group-owned objects with limit' do
73 authorize_with :active
75 id: groups(:afolder).uuid,
79 assert_response :success
80 assert_operator 1, :<, json_response['items_available']
81 assert_equal 1, json_response['items'].count
84 test 'get group-owned objects with limit and offset' do
85 authorize_with :active
87 id: groups(:afolder).uuid,
92 assert_response :success
93 assert_operator 1, :<, json_response['items_available']
94 assert_equal 0, json_response['items'].count
97 test 'get group-owned objects with additional filter matching nothing' do
98 authorize_with :active
100 id: groups(:afolder).uuid,
101 filters: [['uuid', 'in', ['foo_not_a_uuid','bar_not_a_uuid']]],
104 assert_response :success
105 assert_equal [], json_response['items']
106 assert_equal 0, json_response['items_available']
109 test 'get group-owned objects without include_linked' do
110 unexpected_uuid = specimens(:in_afolder_linked_from_asubfolder).uuid
111 authorize_with :active
113 id: groups(:asubfolder).uuid,
116 assert_response :success
117 uuids = json_response['items'].collect { |i| i['uuid'] }
118 assert_equal nil, uuids.index(unexpected_uuid)
121 test 'get group-owned objects with include_linked' do
122 expected_uuid = specimens(:in_afolder_linked_from_asubfolder).uuid
123 authorize_with :active
125 id: groups(:asubfolder).uuid,
126 include_linked: true,
129 assert_response :success
130 uuids = json_response['items'].collect { |i| i['uuid'] }
131 assert_includes uuids, expected_uuid, "Did not get #{expected_uuid}"
133 expected_name = links(:specimen_is_in_two_folders).name
134 found_specimen_name = false
135 assert(json_response['links'].any?,
136 "Expected a non-empty array of links in response")
137 json_response['links'].each do |link|
138 if link['head_uuid'] == expected_uuid
139 if link['name'] == expected_name
140 found_specimen_name = true
144 assert(found_specimen_name,
145 "Expected to find name '#{expected_name}' in response")
148 [false, true].each do |inc_ind|
149 test "get all pages of group-owned #{'and -linked ' if inc_ind}objects" do
150 authorize_with :active
153 items_available = nil
157 # Behaving badly here, using the same controller multiple
158 # times within a test.
161 id: groups(:afolder).uuid,
162 include_linked: inc_ind,
167 assert_response :success
168 assert_operator(0, :<, json_response['items'].count,
169 "items_available=#{items_available} but received 0 "\
170 "items with offset=#{offset}")
171 items_available ||= json_response['items_available']
172 assert_equal(items_available, json_response['items_available'],
173 "items_available changed between page #{offset/limit} "\
174 "and page #{1+offset/limit}")
175 json_response['items'].each do |item|
177 assert_equal(nil, uuid_received[uuid],
178 "Received '#{uuid}' again on page #{1+offset/limit}")
179 uuid_received[uuid] = true
180 owner_received[item['owner_uuid']] = true
183 assert_equal groups(:afolder).uuid, item['owner_uuid']
186 break if offset >= items_available
189 assert_operator 0, :<, (json_response.keys - [users(:active).uuid]).count,
190 "Set include_linked=true but did not receive any non-owned items"
195 %w(offset limit).each do |arg|
196 ['foo', '', '1234five', '0x10', '-8'].each do |val|
197 test "Raise error on bogus #{arg} parameter #{val.inspect}" do
198 authorize_with :active
200 :id => groups(:afolder).uuid,
209 test 'get writable_by list for owned group' do
210 authorize_with :active
212 id: groups(:afolder).uuid,
215 assert_response :success
216 assert_not_nil(json_response['writable_by'],
217 "Should receive uuid list in 'writable_by' field")
218 assert_includes(json_response['writable_by'], users(:active).uuid,
219 "owner should be included in writable_by list")
222 test 'no writable_by list for group with read-only access' do
223 authorize_with :rominiadmin
225 id: groups(:testusergroup_admins).uuid,
228 assert_response :success
229 assert_nil(json_response['writable_by'],
230 "Should not receive uuid list in 'writable_by' field")
233 test 'get writable_by list by admin user' do
234 authorize_with :admin
236 id: groups(:testusergroup_admins).uuid,
239 assert_response :success
240 assert_not_nil(json_response['writable_by'],
241 "Should receive uuid list in 'writable_by' field")
242 assert_includes(json_response['writable_by'],
244 "Current user should be included in 'writable_by' field")