[ARVADOS] updated: 2af59ce37d2332db14e880aff0ba8e38fdc4781a
git at public.curoverse.com
git at public.curoverse.com
Thu Apr 9 10:24:57 EDT 2015
Summary of changes:
.../app/controllers/application_controller.rb | 2 +-
.../controllers/application_controller_test.rb | 34 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
via 2af59ce37d2332db14e880aff0ba8e38fdc4781a (commit)
from 23c44c899b783a784bd9c60e3efda63cab2f6cc8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 2af59ce37d2332db14e880aff0ba8e38fdc4781a
Author: Radhika Chippada <radhika at curoverse.com>
Date: Thu Apr 9 10:08:36 2015 -0400
5365: add controller tests for preload_for_pdhs and collection_for_pdh methods
diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index 69c273c..db00be3 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -1094,7 +1094,7 @@ class ApplicationController < ActionController::Base
pdhs.each do |x|
@all_pdhs_for[x] = []
end
- # TODO: make sure we get every page of results from API server
+
Collection.select(%w(portable_data_hash)).where(portable_data_hash: pdhs).distinct().each do |collection|
@all_pdhs_for[collection.portable_data_hash] << collection
end
diff --git a/apps/workbench/test/controllers/application_controller_test.rb b/apps/workbench/test/controllers/application_controller_test.rb
index 9785243..7e9c0bc 100644
--- a/apps/workbench/test/controllers/application_controller_test.rb
+++ b/apps/workbench/test/controllers/application_controller_test.rb
@@ -59,6 +59,7 @@ class ApplicationControllerTest < ActionController::TestCase
[:preload_collections_for_objects, [] ],
[:preload_log_collections_for_objects, [] ],
[:preload_objects_for_dataclass, [] ],
+ [:preload_for_pdhs, [] ],
].each do |input|
test "preload data for empty array input #{input}" do
use_token :active
@@ -90,6 +91,8 @@ class ApplicationControllerTest < ActionController::TestCase
[:preload_objects_for_dataclass, nil],
[:object_for_dataclass, 'some_dataclass', nil],
[:object_for_dataclass, nil, 'some_uuid'],
+ [:preload_for_pdhs, 'input not an array'],
+ [:preload_for_pdhs, nil],
].each do |input|
test "preload data for wrong type input #{input}" do
use_token :active
@@ -112,6 +115,7 @@ class ApplicationControllerTest < ActionController::TestCase
[:collections_for_object, 'no-such-uuid' ],
[:log_collections_for_object, 'no-such-uuid' ],
[:object_for_dataclass, 'no-such-uuid' ],
+ [:collection_for_pdh, 'no-such-pdh' ],
].each do |input|
test "get data for no such uuid #{input}" do
use_token :active
@@ -125,6 +129,7 @@ class ApplicationControllerTest < ActionController::TestCase
objects = ac.send input[0], input[1]
assert objects, 'Expected objects'
assert objects.is_a?(Array), 'Expected a array'
+ assert_empty objects
end
end
end
@@ -300,6 +305,35 @@ class ApplicationControllerTest < ActionController::TestCase
assert users.size == 3, 'Expected two objects in the preloaded hash'
end
+ test "preload one collection each for given portable_data_hash list" do
+ use_token :active
+
+ ac = ApplicationController.new
+
+ pdh1 = api_fixture('collections')['foo_file']['portable_data_hash']
+ pdh2 = api_fixture('collections')['bar_file']['portable_data_hash']
+
+ pdhs = [pdh1, pdh2]
+ collections = ac.send :preload_for_pdhs, pdhs
+
+ assert collections, 'Expected collections map'
+ assert collections.is_a?(Hash), 'Expected a hash'
+ # Each pdh has more than one collection; however, we should get only one for each
+ assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
+ assert collections[pdh1], 'Expected collections for the passed in pdh #{pdh1}'
+ assert_equal collections[pdh1].size, 1, 'Expected one collection for the passed in pdh #{pdh1}'
+ assert collections[pdh2], 'Expected collections for the passed in pdh #{pdh2}'
+ assert_equal collections[pdh2].size, 1, 'Expected one collection for the passed in pdh #{pdh2}'
+
+ # invoke again for this same input. this time, the preloaded data will be returned
+ collections = ac.send :preload_collections_for_objects, pdhs
+ assert collections, 'Expected collections map'
+ assert collections.is_a?(Hash), 'Expected a hash'
+ assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
+ assert collections[pdh1], 'Expected collection for the passed in pdh #{pdh1}'
+ assert collections[pdh2], 'Expected collection for the passed in pdh #{pdh2}'
+ end
+
test "requesting a nonexistent object returns 404" do
# We're really testing ApplicationController's find_object_by_uuid.
# It's easiest to do that by instantiating a concrete controller.
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list