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 "preload links for objects and uuids" do
39 ac = ApplicationController.new
41 link1_head_uuid = api_fixture('links')['foo_file_readable_by_active']['head_uuid']
42 link2_uuid = api_fixture('links')['bar_file_readable_by_active']['uuid']
43 link3_head_uuid = api_fixture('links')['bar_file_readable_by_active']['head_uuid']
45 link2_object = User.find(api_fixture('users')['active']['uuid'])
46 link2_object_uuid = link2_object['uuid']
48 uuids = [link1_head_uuid, link2_object, link3_head_uuid]
49 links = ac.send :preload_links_for_objects, uuids
51 assert links, 'Expected links'
52 assert links.is_a?(Hash), 'Expected a hash'
53 assert links.size == 3, 'Expected two objects in the preloaded links hash'
54 assert links[link1_head_uuid], 'Expected links for the passed in link head_uuid'
55 assert links[link2_object_uuid], 'Expected links for the passed in object uuid'
56 assert links[link3_head_uuid], 'Expected links for the passed in link head_uuid'
58 # invoke again for this same input. this time, the preloaded data will be returned
59 links = ac.send :preload_links_for_objects, uuids
60 assert links, 'Expected links'
61 assert links.is_a?(Hash), 'Expected a hash'
62 assert links.size == 3, 'Expected two objects in the preloaded links hash'
63 assert links[link1_head_uuid], 'Expected links for the passed in link head_uuid'
66 test "preload links for empty array input" do
69 ac = ApplicationController.new
71 links = ac.send :preload_links_for_objects, []
73 assert links, 'Expected links'
74 assert links.is_a?(Hash), 'Expected a hash'
75 assert links.size == 0, 'Expected no objects in the preloaded links hash'
78 [ [:preload_links_for_objects, 'input not an array'],
79 [:preload_links_for_objects, nil],
80 [:links_for_object, nil],
81 [:preload_collections_for_objects, 'input not an array'],
82 [:preload_collections_for_objects, nil],
83 [:collections_for_object, nil],
84 [:preload_log_collections_for_objects, 'input not an array'],
85 [:preload_log_collections_for_objects, nil],
86 [:log_collections_for_object, nil],
87 [:preload_objects_for_dataclass, 'input not an array'],
88 [:preload_objects_for_dataclass, nil],
89 [:object_for_dataclass, 'some_dataclass', nil],
90 [:object_for_dataclass, nil, 'some_uuid'],
92 test "preload data for wrong type input #{input}" do
95 ac = ApplicationController.new
97 if input[0] == :object_for_dataclass
98 assert_raise ArgumentError do
99 ac.send input[0], input[1], input[2]
102 assert_raise ArgumentError do
103 ac.send input[0], input[1]
109 test "get 10 objects of data class user" do
112 ac = ApplicationController.new
114 objects = ac.send :get_n_objects_of_class, @user_dataclass, 10
116 assert objects, 'Expected objects'
117 assert objects.is_a?(ArvadosResourceList), 'Expected an ArvadosResourceList'
119 first_object = objects.first
120 assert first_object, 'Expected at least one object'
121 assert_equal 'User', first_object.class.name, 'Expected user object'
123 # invoke it again. this time, the preloaded info will be returned
124 objects = ac.send :get_n_objects_of_class, @user_dataclass, 10
125 assert objects, 'Expected objects'
126 assert_equal 'User', objects.first.class.name, 'Expected user object'
131 [@user_dataclass, 0],
132 [@user_dataclass, -1],
133 [@user_dataclass, nil] ].each do |input|
134 test "get_n_objects for incorrect input #{input}" do
137 ac = ApplicationController.new
139 assert_raise ArgumentError do
140 ac.send :get_n_objects_of_class, input[0], input[1]
145 test "collections for object" do
148 ac = ApplicationController.new
150 uuid = api_fixture('collections')['foo_file']['uuid']
152 collections = ac.send :collections_for_object, uuid
154 assert collections, 'Expected collections'
155 assert collections.is_a?(Array), 'Expected an array'
156 assert collections.size == 1, 'Expected one collection object'
157 assert_equal collections[0][:uuid], uuid, 'Expected uuid not found in collections'
160 test "collections for no such object" do
163 ac = ApplicationController.new
165 collections = ac.send :collections_for_object, "no-such-uuid"
167 assert collections, 'Expected collections'
168 assert collections.is_a?(Array), 'Expected an array'
169 assert collections.size == 0, 'Expected no collections in response'
172 test "preload collections for given uuids" do
175 ac = ApplicationController.new
177 uuid1 = api_fixture('collections')['foo_file']['uuid']
178 uuid2 = api_fixture('collections')['bar_file']['uuid']
180 uuids = [uuid1, uuid2]
181 collections = ac.send :preload_collections_for_objects, uuids
183 assert collections, 'Expected collection'
184 assert collections.is_a?(Hash), 'Expected a hash'
185 assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
186 assert collections[uuid1], 'Expected collections for the passed in uuid'
187 assert_equal collections[uuid1].size, 1, 'Expected one collection for the passed in uuid'
188 assert collections[uuid2], 'Expected collections for the passed in uuid'
189 assert_equal collections[uuid2].size, 1, 'Expected one collection for the passed in uuid'
191 # invoke again for this same input. this time, the preloaded data will be returned
192 collections = ac.send :preload_collections_for_objects, uuids
193 assert collections, 'Expected collection'
194 assert collections.is_a?(Hash), 'Expected a hash'
195 assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
196 assert collections[uuid1], 'Expected collections for the passed in uuid'
199 test "preload collections for empty array input" do
202 ac = ApplicationController.new
204 collections = ac.send :preload_links_for_objects, []
206 assert collections, 'Expected collections'
207 assert collections.is_a?(Hash), 'Expected a hash'
208 assert collections.size == 0, 'Expected no objects in the preloaded collections hash'