3 class Arvados::V1::LinksControllerTest < ActionController::TestCase
5 test "no symbol keys in serialized hash" do
7 properties: {username: 'testusername'},
10 tail_uuid: users(:admin).uuid,
11 head_uuid: virtual_machines(:testvm).uuid
14 [link, link.to_json].each do |formatted_link|
15 post :create, link: formatted_link
16 assert_response :success
17 assert_not_nil assigns(:object)
18 assert_equal 'testusername', assigns(:object).properties['username']
19 assert_equal false, assigns(:object).properties.has_key?(:username)
23 %w(created_at updated_at modified_at).each do |attr|
24 {nil: nil, bogus: 2.days.ago}.each do |bogustype, bogusvalue|
25 test "cannot set #{bogustype} #{attr} in create" do
26 authorize_with :active
32 }.merge(attr => bogusvalue)
34 assert_response :success
35 resp = JSON.parse @response.body
36 assert_in_delta Time.now, Time.parse(resp[attr]), 3.0
38 test "cannot set #{bogustype} #{attr} in update" do
39 really_created_at = links(:test_timestamps).created_at
40 authorize_with :active
42 id: links(:test_timestamps).uuid,
44 :properties => {test: 'test'},
48 assert_response :success
49 resp = JSON.parse @response.body
52 assert_in_delta really_created_at, Time.parse(resp[attr]), 0.001
54 assert_in_delta Time.now, Time.parse(resp[attr]), 3.0
60 test "head must exist" do
64 tail_uuid: users(:active).uuid,
65 head_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
68 post :create, link: link
72 test "tail must exist" do
76 head_uuid: users(:active).uuid,
77 tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
80 post :create, link: link
84 test "head and tail exist, head_kind and tail_kind are returned" do
88 head_uuid: users(:active).uuid,
89 tail_uuid: users(:spectator).uuid,
92 post :create, link: link
93 assert_response :success
94 l = JSON.parse(@response.body)
95 assert 'arvados#user', l['head_kind']
96 assert 'arvados#user', l['tail_kind']
99 test "can supply head_kind and tail_kind without error" do
103 head_uuid: users(:active).uuid,
104 tail_uuid: users(:spectator).uuid,
105 head_kind: "arvados#user",
106 tail_kind: "arvados#user",
108 authorize_with :admin
109 post :create, link: link
110 assert_response :success
111 l = JSON.parse(@response.body)
112 assert 'arvados#user', l['head_kind']
113 assert 'arvados#user', l['tail_kind']
116 test "tail must be visible by user" do
120 head_uuid: users(:active).uuid,
121 tail_uuid: virtual_machines(:testvm).uuid
123 authorize_with :active
124 post :create, link: link
128 test "filter links with 'is_a' operator" do
129 authorize_with :admin
131 filters: [ ['tail_uuid', 'is_a', 'arvados#user'] ]
133 assert_response :success
134 found = assigns(:objects)
135 assert_not_equal 0, found.count
136 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
139 test "filter links with 'is_a' operator with more than one" do
140 authorize_with :admin
142 filters: [ ['tail_uuid', 'is_a', ['arvados#user', 'arvados#group'] ] ],
144 assert_response :success
145 found = assigns(:objects)
146 assert_not_equal 0, found.count
147 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-(tpzed|j7d0g)-[a-z0-9]{15}/}).count
150 test "filter links with 'is_a' operator with bogus type" do
151 authorize_with :admin
153 filters: [ ['tail_uuid', 'is_a', ['arvados#bogus'] ] ],
155 assert_response :success
156 found = assigns(:objects)
157 assert_equal 0, found.count
160 test "filter links with 'is_a' operator with collection" do
161 authorize_with :admin
163 filters: [ ['head_uuid', 'is_a', ['arvados#collection'] ] ],
165 assert_response :success
166 found = assigns(:objects)
167 assert_not_equal 0, found.count
168 assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-f0-9]{32}\+\d+/}).count
171 test "test can still use where tail_kind" do
172 authorize_with :admin
174 where: { tail_kind: 'arvados#user' }
176 assert_response :success
177 found = assigns(:objects)
178 assert_not_equal 0, found.count
179 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
182 test "test can still use where head_kind" do
183 authorize_with :admin
185 where: { head_kind: 'arvados#user' }
187 assert_response :success
188 found = assigns(:objects)
189 assert_not_equal 0, found.count
190 assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
193 test "test can still use filter tail_kind" do
194 authorize_with :admin
196 filters: [ ['tail_kind', '=', 'arvados#user'] ]
198 assert_response :success
199 found = assigns(:objects)
200 assert_not_equal 0, found.count
201 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
204 test "test can still use filter head_kind" do
205 authorize_with :admin
207 filters: [ ['head_kind', '=', 'arvados#user'] ]
209 assert_response :success
210 found = assigns(:objects)
211 assert_not_equal 0, found.count
212 assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
215 test "head_kind matches head_uuid" do
219 head_uuid: groups(:public).uuid,
220 head_kind: "arvados#user",
221 tail_uuid: users(:spectator).uuid,
222 tail_kind: "arvados#user",
224 authorize_with :admin
225 post :create, link: link
229 test "tail_kind matches tail_uuid" do
233 head_uuid: users(:active).uuid,
234 head_kind: "arvados#user",
235 tail_uuid: groups(:public).uuid,
236 tail_kind: "arvados#user",
238 authorize_with :admin
239 post :create, link: link