3 class ApplicationControllerTest < ActionController::TestCase
6 @user_dataclass = ArvadosBase.resource_class_for_uuid(api_fixture('users')['active']['uuid'])
9 test "links for object" do
12 ac = ApplicationController.new
14 link_head_uuid = api_fixture('links')['foo_file_readable_by_active']['head_uuid']
16 links = ac.send :links_for_object, link_head_uuid
18 assert links, 'Expected links'
19 assert links.is_a?(Array), 'Expected an array'
20 assert links.size > 0, 'Expected at least one link'
21 assert links[0][:uuid], 'Expected uuid for the head_link'
24 test "links for no such object" do
27 ac = ApplicationController.new
29 links = ac.send :links_for_object, "no-such-uuid"
31 assert links, 'Expected links'
32 assert links.is_a?(Array), 'Expected an array'
33 assert links.size == 0, 'Expected no links'
36 test "links for nil object" do
39 ac = ApplicationController.new
41 assert_raise ArgumentError do
42 ac.send :links_for_object, nil
46 test "preload links for objects and uuids" do
49 ac = ApplicationController.new
51 link1_head_uuid = api_fixture('links')['foo_file_readable_by_active']['head_uuid']
52 link2_uuid = api_fixture('links')['bar_file_readable_by_active']['uuid']
53 link3_head_uuid = api_fixture('links')['bar_file_readable_by_active']['head_uuid']
55 link2_object = User.find(api_fixture('users')['active']['uuid'])
56 link2_object_uuid = link2_object['uuid']
58 uuids = [link1_head_uuid, link2_object, link3_head_uuid]
59 links = ac.send :preload_links_for_objects, uuids
61 assert links, 'Expected links'
62 assert links.is_a?(Hash), 'Expected a hash'
63 assert links.size == 3, 'Expected two objects in the preloaded links hash'
64 assert links[link1_head_uuid], 'Expected links for the passed in link head_uuid'
65 assert links[link2_object_uuid], 'Expected links for the passed in object uuid'
66 assert links[link3_head_uuid], 'Expected links for the passed in link head_uuid'
68 # invoke again for this same input. this time, the preloaded data will be returned
69 links = ac.send :preload_links_for_objects, uuids
70 assert links, 'Expected links'
71 assert links.is_a?(Hash), 'Expected a hash'
72 assert links.size == 3, 'Expected two objects in the preloaded links hash'
73 assert links[link1_head_uuid], 'Expected links for the passed in link head_uuid'
76 test "preload links for empty array input" do
79 ac = ApplicationController.new
81 links = ac.send :preload_links_for_objects, []
83 assert links, 'Expected links'
84 assert links.is_a?(Hash), 'Expected a hash'
85 assert links.size == 0, 'Expected no objects in the preloaded links hash'
88 [ [:preload_links_for_objects, 'input not an array'],
89 [:preload_links_for_objects, nil],
90 [:preload_collections_for_objects, 'input not an array'],
91 [:preload_collections_for_objects, nil],
92 [:preload_log_collections_for_objects, 'input not an array'],
93 [:preload_log_collections_for_objects, nil],
94 [:preload_objects_for_dataclass, 'input not an array'],
95 [:preload_objects_for_dataclass, nil],
97 test "preload links for wrong type input #{input}" do
100 ac = ApplicationController.new
102 assert_raise ArgumentError do
103 ac.send input[0], input[1]
108 test "get 10 objects of data class user" do
111 ac = ApplicationController.new
113 objects = ac.send :get_n_objects_of_class, @user_dataclass, 10
115 assert objects, 'Expected objects'
116 assert objects.is_a?(ArvadosResourceList), 'Expected an ArvadosResourceList'
118 first_object = objects.first
119 assert first_object, 'Expected at least one object'
120 assert_equal 'User', first_object.class.name, 'Expected user object'
122 # invoke it again. this time, the preloaded info will be returned
123 objects = ac.send :get_n_objects_of_class, @user_dataclass, 10
124 assert objects, 'Expected objects'
125 assert_equal 'User', objects.first.class.name, 'Expected user object'
130 [@user_dataclass, 0],
131 [@user_dataclass, -1],
132 [@user_dataclass, nil] ].each do |input|
133 test "get_n_objects for incorrect input #{input}" do
136 ac = ApplicationController.new
138 assert_raise ArgumentError do
139 ac.send :get_n_objects_of_class, input[0], input[1]
144 test "collections for object" do
147 ac = ApplicationController.new
149 uuid = api_fixture('collections')['foo_file']['uuid']
151 collections = ac.send :collections_for_object, uuid
153 assert collections, 'Expected collections'
154 assert collections.is_a?(Array), 'Expected an array'
155 assert collections.size == 1, 'Expected one collection object'
156 assert_equal collections[0][:uuid], uuid, 'Expected uuid not found in collections'
159 test "collections for no such object" do
162 ac = ApplicationController.new
164 collections = ac.send :collections_for_object, "no-such-uuid"
166 assert collections, 'Expected collections'
167 assert collections.is_a?(Array), 'Expected an array'
168 assert collections.size == 0, 'Expected no collections in response'
171 test "preload collections for given uuids" do
174 ac = ApplicationController.new
176 uuid1 = api_fixture('collections')['foo_file']['uuid']
177 uuid2 = api_fixture('collections')['bar_file']['uuid']
179 uuids = [uuid1, uuid2]
180 collections = ac.send :preload_collections_for_objects, uuids
182 assert collections, 'Expected collection'
183 assert collections.is_a?(Hash), 'Expected a hash'
184 assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
185 assert collections[uuid1], 'Expected collections for the passed in uuid'
186 assert_equal collections[uuid1].size, 1, 'Expected one collection for the passed in uuid'
187 assert collections[uuid2], 'Expected collections for the passed in uuid'
188 assert_equal collections[uuid2].size, 1, 'Expected one collection for the passed in uuid'
190 # invoke again for this same input. this time, the preloaded data will be returned
191 collections = ac.send :preload_collections_for_objects, uuids
192 assert collections, 'Expected collection'
193 assert collections.is_a?(Hash), 'Expected a hash'
194 assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
195 assert collections[uuid1], 'Expected collections for the passed in uuid'
198 test "preload collections for empty array input" do
201 ac = ApplicationController.new
203 collections = ac.send :preload_links_for_objects, []
205 assert collections, 'Expected collections'
206 assert collections.is_a?(Hash), 'Expected a hash'
207 assert collections.size == 0, 'Expected no objects in the preloaded collections hash'