Removed internal uses of _kind column in API server. Tests pass.
[arvados.git] / services / api / test / functional / arvados / v1 / links_controller_test.rb
1 require 'test_helper'
2
3 class Arvados::V1::LinksControllerTest < ActionController::TestCase
4
5   test "no symbol keys in serialized hash" do
6     link = {
7       properties: {username: 'testusername'},
8       link_class: 'test',
9       name: 'encoding',
10       tail_kind: 'arvados#user',
11       tail_uuid: users(:admin).uuid,
12       head_kind: 'arvados#virtualMachine',
13       head_uuid: virtual_machines(:testvm).uuid
14     }
15     authorize_with :admin
16     [link, link.to_json].each do |formatted_link|
17       post :create, link: formatted_link
18       assert_response :success
19       assert_not_nil assigns(:object)
20       assert_equal 'testusername', assigns(:object).properties['username']
21       assert_equal false, assigns(:object).properties.has_key?(:username)
22     end
23   end
24   
25   test "head must exist" do
26     link = {
27       link_class: 'test',
28       name: 'stuff',
29       tail_uuid: users(:active).uuid,
30       head_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
31     }
32     authorize_with :admin
33     post :create, link: link
34     assert_response 422
35   end
36
37   test "tail must exist" do
38     link = {
39       link_class: 'test',
40       name: 'stuff',
41       head_uuid: users(:active).uuid,
42       tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
43     }
44     authorize_with :admin
45     post :create, link: link
46     assert_response 422
47   end
48
49   test "tail must be visible by user" do
50     link = {
51       link_class: 'test',
52       name: 'stuff',
53       head_uuid: users(:active).uuid,
54       tail_uuid: virtual_machines(:testvm).uuid
55     }
56     authorize_with :active
57     post :create, link: link
58     assert_response 422
59   end
60
61   test "filter links with 'is_a' operator" do
62     authorize_with :admin
63     get :index, {
64       filters: [ ['tail_uuid', 'is_a', 'arvados#user'] ]
65     }
66     assert_response :success
67     found = assigns(:objects)
68     assert_not_equal 0, found.count
69     assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
70   end
71
72   test "filter links with 'is_a' operator with more than one" do
73     authorize_with :admin
74     get :index, {
75       filters: [ ['tail_uuid', 'is_a', ['arvados#user', 'arvados#group'] ] ],
76     }
77     assert_response :success
78     found = assigns(:objects)
79     assert_not_equal 0, found.count
80     assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-(tpzed|j7d0g)-[a-z0-9]{15}/}).count
81   end
82
83   test "filter links with 'is_a' operator with bogus type" do
84     authorize_with :admin
85     get :index, {
86       filters: [ ['tail_uuid', 'is_a', ['arvados#bogus'] ] ],
87     }
88     assert_response :success
89     found = assigns(:objects)
90     assert_equal 0, found.count
91   end
92
93   test "filter links with 'is_a' operator with collection" do
94     authorize_with :admin
95     get :index, {
96       filters: [ ['head_uuid', 'is_a', ['arvados#collection'] ] ],
97     }
98     assert_response :success
99     found = assigns(:objects)
100     assert_response :success
101     found = assigns(:objects)
102     assert_not_equal 0, found.count
103     assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-f0-9]{32}\+\d+/}).count
104   end
105
106
107 end