[ARVADOS] updated: 2cdc648b5367efd4c8e7b2ede93a2b3ba0871c17

git at public.curoverse.com git at public.curoverse.com
Mon Jun 9 16:57:52 EDT 2014


Summary of changes:
 .../app/controllers/application_controller.rb      |   8 +-
 .../test/functional/application_controller_test.rb | 177 ++++++++++++++++-----
 services/api/Gemfile                               |   2 +
 services/api/Gemfile.lock                          |   3 +
 4 files changed, 145 insertions(+), 45 deletions(-)

       via  2cdc648b5367efd4c8e7b2ede93a2b3ba0871c17 (commit)
       via  97a1da1dfde9ef3ef195f7513309da8c6bb17978 (commit)
       via  73688a1ef6387fe8a8b1b2f09a8936198f79d66e (commit)
       via  a2bcc06c1bda757ed8c869d7f9ad235f56abdcf4 (commit)
       via  dd6e25d53f9cf02f91b419584ff4c331e0618a24 (commit)
      from  400829b3835f0a129116a2eed926d12a0636aeab (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 2cdc648b5367efd4c8e7b2ede93a2b3ba0871c17
Merge: 97a1da1 73688a1
Author: radhika <radhika at curoverse.com>
Date:   Mon Jun 9 16:40:39 2014 -0400

    Merge branch 'master' into 2871-preload-objects


commit 97a1da1dfde9ef3ef195f7513309da8c6bb17978
Author: radhika <radhika at curoverse.com>
Date:   Mon Jun 9 16:39:31 2014 -0400

    2871: test preload_objects_for_dataclass helper method

diff --git a/apps/workbench/test/functional/application_controller_test.rb b/apps/workbench/test/functional/application_controller_test.rb
index bb86305..8183443 100644
--- a/apps/workbench/test/functional/application_controller_test.rb
+++ b/apps/workbench/test/functional/application_controller_test.rb
@@ -245,4 +245,55 @@ class ApplicationControllerTest < ActionController::TestCase
     assert collections[uuid1], 'Expected collections for the passed in uuid'
   end
 
+  test "object for dataclass" do
+    use_token :active
+
+    ac = ApplicationController.new
+
+    dataclass = ArvadosBase.resource_class_for_uuid(api_fixture('jobs')['running']['uuid'])
+    uuid = api_fixture('jobs')['running']['uuid']
+
+    obj = ac.send :object_for_dataclass, dataclass, uuid
+
+    assert obj, 'Expected object'
+    assert 'Job', obj.class
+    assert_equal uuid, obj['uuid'], 'Expected uuid not found'
+    assert_equal api_fixture('jobs')['running']['script_version'], obj['script_version'],
+      'Expected script_version not found'
+  end
+
+  test "preload objects for dataclass" do
+    use_token :active
+
+    ac = ApplicationController.new
+
+    dataclass = ArvadosBase.resource_class_for_uuid(api_fixture('jobs')['running']['uuid'])
+
+    uuid1 = api_fixture('jobs')['running']['uuid']
+    uuid2 = api_fixture('jobs')['running_cancelled']['uuid']
+
+    uuids = [uuid1, uuid2]
+    users = ac.send :preload_objects_for_dataclass, dataclass, uuids
+
+    assert users, 'Expected objects'
+    assert users.is_a?(Hash), 'Expected a hash'
+
+    assert users.size == 2, 'Expected two objects in the preloaded hash'
+    assert users[uuid1], 'Expected user object for the passed in uuid'
+    assert users[uuid2], 'Expected user object for the passed in uuid'
+
+    # invoke again for this same input. this time, the preloaded data will be returned
+    users = ac.send :preload_objects_for_dataclass, dataclass, uuids
+    assert users, 'Expected objects'
+    assert users.is_a?(Hash), 'Expected a hash'
+    assert users.size == 2, 'Expected two objects in the preloaded hash'
+
+    # invoke again for this with one more uuid
+    uuids << api_fixture('jobs')['foobar']['uuid']
+    users = ac.send :preload_objects_for_dataclass, dataclass, uuids
+    assert users, 'Expected objects'
+    assert users.is_a?(Hash), 'Expected a hash'
+    assert users.size == 3, 'Expected two objects in the preloaded hash'
+  end
+
 end

commit a2bcc06c1bda757ed8c869d7f9ad235f56abdcf4
Author: radhika <radhika at curoverse.com>
Date:   Mon Jun 9 15:37:39 2014 -0400

    2871: preload_log_collections tests

diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index eabf3c5..a87d986 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -612,7 +612,7 @@ class ApplicationController < ActionController::Base
     raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? Class
     raise ArgumentError, 'Argument is not an array' unless uuids.is_a? Array
 
-    return @all_collections_for if uuids.empty?
+    return @objects_for if uuids.empty?
 
     # if already preloaded for all of these uuids, return
     if not uuids.select { |x| @objects_for[x].nil? }.any?
diff --git a/apps/workbench/test/functional/application_controller_test.rb b/apps/workbench/test/functional/application_controller_test.rb
index d4adc1c..bb86305 100644
--- a/apps/workbench/test/functional/application_controller_test.rb
+++ b/apps/workbench/test/functional/application_controller_test.rb
@@ -21,18 +21,6 @@ class ApplicationControllerTest < ActionController::TestCase
     assert links[0][:uuid], 'Expected uuid for the head_link'
   end
 
-  test "links for no such object" do
-    use_token :active
-
-    ac = ApplicationController.new
-
-    links = ac.send :links_for_object, "no-such-uuid"
-
-    assert links, 'Expected links'
-    assert links.is_a?(Array), 'Expected an array'
-    assert links.size == 0, 'Expected no links'
-  end
-
   test "preload links for objects and uuids" do
     use_token :active
 
@@ -63,16 +51,26 @@ class ApplicationControllerTest < ActionController::TestCase
     assert links[link1_head_uuid], 'Expected links for the passed in link head_uuid'
   end
 
-  test "preload links for empty array input" do
-    use_token :active
+  [ [:preload_links_for_objects, [] ],
+    [:preload_collections_for_objects, [] ],
+    [:preload_log_collections_for_objects, [] ],
+    [:preload_objects_for_dataclass, [] ],
+  ].each do |input|
+    test "preload data for empty array input #{input}" do
+      use_token :active
 
-    ac = ApplicationController.new
+      ac = ApplicationController.new
 
-    links = ac.send :preload_links_for_objects, []
+      if input[0] == :preload_objects_for_dataclass
+        objects = ac.send input[0], @user_dataclass, input[1]
+      else
+        objects = ac.send input[0], input[1]
+      end
 
-    assert links, 'Expected links'
-    assert links.is_a?(Hash), 'Expected a hash'
-    assert links.size == 0, 'Expected no objects in the preloaded links hash'
+      assert objects, 'Expected objects'
+      assert objects.is_a?(Hash), 'Expected a hash'
+      assert objects.size == 0, 'Expected no objects in the preloaded hash'
+    end
   end
 
   [ [:preload_links_for_objects, 'input not an array'],
@@ -106,6 +104,27 @@ class ApplicationControllerTest < ActionController::TestCase
     end
   end
 
+  [ [:links_for_object, 'no-such-uuid' ],
+    [:collections_for_object, 'no-such-uuid' ],
+    [:log_collections_for_object, 'no-such-uuid' ],
+    [:object_for_dataclass, 'no-such-uuid' ],
+  ].each do |input|
+    test "get data for no such uuid #{input}" do
+      use_token :active
+
+      ac = ApplicationController.new
+
+      if input[0] == :object_for_dataclass
+        object = ac.send input[0], @user_dataclass, input[1]
+        assert_not object, 'Expected no object'
+      else
+        objects = ac.send input[0], input[1]
+        assert objects, 'Expected objects'
+        assert objects.is_a?(Array), 'Expected a array'
+      end
+    end
+  end
+
   test "get 10 objects of data class user" do
     use_token :active
 
@@ -157,18 +176,6 @@ class ApplicationControllerTest < ActionController::TestCase
     assert_equal collections[0][:uuid], uuid, 'Expected uuid not found in collections'
   end
 
-  test "collections for no such object" do
-    use_token :active
-
-    ac = ApplicationController.new
-
-    collections = ac.send :collections_for_object, "no-such-uuid"
-
-    assert collections, 'Expected collections'
-    assert collections.is_a?(Array), 'Expected an array'
-    assert collections.size == 0, 'Expected no collections in response'
-  end
-
   test "preload collections for given uuids" do
     use_token :active
 
@@ -196,16 +203,46 @@ class ApplicationControllerTest < ActionController::TestCase
     assert collections[uuid1], 'Expected collections for the passed in uuid'
   end
 
-  test "preload collections for empty array input" do
+  test "log collections for object" do
     use_token :active
 
     ac = ApplicationController.new
 
-    collections = ac.send :preload_links_for_objects, []
+    uuid = api_fixture('logs')['log4']['object_uuid']
+
+    collections = ac.send :log_collections_for_object, uuid
 
     assert collections, 'Expected collections'
+    assert collections.is_a?(Array), 'Expected an array'
+    assert collections.size == 1, 'Expected one collection object'
+    assert_equal collections[0][:uuid], uuid, 'Expected uuid not found in collections'
+  end
+
+  test "preload log collections for given uuids" do
+    use_token :active
+
+    ac = ApplicationController.new
+
+    uuid1 = api_fixture('logs')['log4']['object_uuid']
+    uuid2 = api_fixture('collections')['bar_file']['uuid']
+
+    uuids = [uuid1, uuid2]
+    collections = ac.send :preload_log_collections_for_objects, uuids
+
+    assert collections, 'Expected collection'
+    assert collections.is_a?(Hash), 'Expected a hash'
+    assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
+    assert collections[uuid1], 'Expected collections for the passed in uuid'
+    assert_equal collections[uuid1].size, 1, 'Expected one collection for the passed in uuid'
+    assert collections[uuid2], 'Expected collections for the passed in uuid'
+    assert_equal collections[uuid2].size, 1, 'Expected one collection for the passed in uuid'
+
+    # invoke again for this same input. this time, the preloaded data will be returned
+    collections = ac.send :preload_log_collections_for_objects, uuids
+    assert collections, 'Expected collection'
     assert collections.is_a?(Hash), 'Expected a hash'
-    assert collections.size == 0, 'Expected no objects in the preloaded collections hash'
+    assert collections.size == 2, 'Expected two objects in the preloaded collection hash'
+    assert collections[uuid1], 'Expected collections for the passed in uuid'
   end
 
 end

commit dd6e25d53f9cf02f91b419584ff4c331e0618a24
Author: radhika <radhika at curoverse.com>
Date:   Mon Jun 9 14:00:53 2014 -0400

    2871: more testing

diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index 29b76db..eabf3c5 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -517,6 +517,7 @@ class ApplicationController < ActionController::Base
   # helper method to get collections for the given uuid
   helper_method :collections_for_object
   def collections_for_object uuid
+    raise ArgumentError, 'No input argument' unless uuid
     preload_collections_for_objects([uuid])
     @all_collections_for[uuid] ||= []
   end
@@ -548,6 +549,8 @@ class ApplicationController < ActionController::Base
   # helper method to get log collections for the given log
   helper_method :log_collections_for_object
   def log_collections_for_object log
+    raise ArgumentError, 'No input argument' unless log
+
     preload_log_collections_for_objects([log])
 
     uuid = log
@@ -596,6 +599,7 @@ class ApplicationController < ActionController::Base
   # helper method to get object of a given dataclass and uuid
   helper_method :object_for_dataclass
   def object_for_dataclass dataclass, uuid
+    raise ArgumentError, 'No input argument dataclass' unless (dataclass && uuid)
     preload_objects_for_dataclass(dataclass, [uuid])
     @objects_for[uuid]
   end
@@ -605,7 +609,9 @@ class ApplicationController < ActionController::Base
   def preload_objects_for_dataclass dataclass, uuids
     @objects_for ||= {}
 
+    raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? Class
     raise ArgumentError, 'Argument is not an array' unless uuids.is_a? Array
+
     return @all_collections_for if uuids.empty?
 
     # if already preloaded for all of these uuids, return
diff --git a/apps/workbench/test/functional/application_controller_test.rb b/apps/workbench/test/functional/application_controller_test.rb
index fbad1d7..d4adc1c 100644
--- a/apps/workbench/test/functional/application_controller_test.rb
+++ b/apps/workbench/test/functional/application_controller_test.rb
@@ -33,16 +33,6 @@ class ApplicationControllerTest < ActionController::TestCase
     assert links.size == 0, 'Expected no links'
   end
 
-  test "links for nil object" do
-    use_token :active
-
-    ac = ApplicationController.new
-
-    assert_raise ArgumentError do
-      ac.send :links_for_object, nil
-    end
-  end
-
   test "preload links for objects and uuids" do
     use_token :active
 
@@ -87,20 +77,31 @@ class ApplicationControllerTest < ActionController::TestCase
 
   [ [:preload_links_for_objects, 'input not an array'],
     [:preload_links_for_objects, nil],
+    [:links_for_object, nil],
     [:preload_collections_for_objects, 'input not an array'],
     [:preload_collections_for_objects, nil],
+    [:collections_for_object, nil],
     [:preload_log_collections_for_objects, 'input not an array'],
     [:preload_log_collections_for_objects, nil],
+    [:log_collections_for_object, nil],
     [:preload_objects_for_dataclass, 'input not an array'],
     [:preload_objects_for_dataclass, nil],    
+    [:object_for_dataclass, 'some_dataclass', nil],
+    [:object_for_dataclass, nil, 'some_uuid'],
   ].each do |input|
-    test "preload links for wrong type input #{input}" do
+    test "preload data for wrong type input #{input}" do
       use_token :active
 
       ac = ApplicationController.new
 
-      assert_raise ArgumentError do
-        ac.send input[0], input[1]
+      if input[0] == :object_for_dataclass
+        assert_raise ArgumentError do
+          ac.send input[0], input[1], input[2]
+        end
+      else
+        assert_raise ArgumentError do
+          ac.send input[0], input[1]
+        end
       end
     end
   end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list