X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ec27ba2a576189755d443d54213318741f73d125..b67167e763608af2909ce4e4e25c03d0e7db8b84:/apps/workbench/test/controllers/application_controller_test.rb diff --git a/apps/workbench/test/controllers/application_controller_test.rb b/apps/workbench/test/controllers/application_controller_test.rb index 463a131b52..22ff7d4b2b 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 @@ -212,7 +217,7 @@ class ApplicationControllerTest < ActionController::TestCase ac = ApplicationController.new - uuid = api_fixture('logs')['log4']['object_uuid'] + uuid = api_fixture('logs')['system_adds_foo_file']['object_uuid'] collections = ac.send :log_collections_for_object, uuid @@ -227,7 +232,7 @@ class ApplicationControllerTest < ActionController::TestCase ac = ApplicationController.new - uuid1 = api_fixture('logs')['log4']['object_uuid'] + uuid1 = api_fixture('logs')['system_adds_foo_file']['object_uuid'] uuid2 = api_fixture('collections')['bar_file']['uuid'] uuids = [uuid1, uuid2] @@ -300,6 +305,27 @@ 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}' + 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. @@ -328,17 +354,28 @@ class ApplicationControllerTest < ActionController::TestCase [ [CollectionsController.new, api_fixture('collections')['user_agreement_in_anonymously_accessible_project']], + [CollectionsController.new, api_fixture('collections')['user_agreement_in_anonymously_accessible_project'], false], [JobsController.new, api_fixture('jobs')['running_job_in_publicly_accessible_project']], + [JobsController.new, api_fixture('jobs')['running_job_in_publicly_accessible_project'], false], [PipelineInstancesController.new, api_fixture('pipeline_instances')['pipeline_in_publicly_accessible_project']], + [PipelineInstancesController.new, api_fixture('pipeline_instances')['pipeline_in_publicly_accessible_project'], false], [PipelineTemplatesController.new, api_fixture('pipeline_templates')['pipeline_template_in_publicly_accessible_project']], + [PipelineTemplatesController.new, api_fixture('pipeline_templates')['pipeline_template_in_publicly_accessible_project'], false], [ProjectsController.new, api_fixture('groups')['anonymously_accessible_project']], - ].each do |controller, fixture| + [ProjectsController.new, api_fixture('groups')['anonymously_accessible_project'], false], + ].each do |controller, fixture, anon_config=true| test "#{controller} show method with anonymous config enabled" do + if anon_config + Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token'] + else + Rails.configuration.anonymous_user_token = false + end + @controller = controller get(:show, {id: fixture['uuid']}) - if Rails.configuration.anonymous_user_token + if anon_config assert_response 200 if controller.class == JobsController assert_includes @response.inspect, fixture['script'] @@ -351,4 +388,18 @@ class ApplicationControllerTest < ActionController::TestCase end end end + + [ + true, + false, + ].each do |config| + test "invoke show with include_accept_encoding_header config #{config}" do + Rails.configuration.include_accept_encoding_header_in_api_requests = config + + @controller = CollectionsController.new + get(:show, {id: api_fixture('collections')['foo_file']['uuid']}, session_for(:admin)) + + assert_equal([['.', 'foo', 3]], assigns(:object).files) + end + end end