[ARVADOS] updated: 5641c4b171f72dd600e17e6db46b3723ab861a4c

git at public.curoverse.com git at public.curoverse.com
Wed Aug 5 17:52:21 EDT 2015


Summary of changes:
 services/api/app/models/collection.rb              |  2 +-
 .../arvados/v1/collections_controller_test.rb      | 68 +++++++++++++++-------
 services/api/test/unit/collection_test.rb          | 41 +++++++++----
 3 files changed, 77 insertions(+), 34 deletions(-)

       via  5641c4b171f72dd600e17e6db46b3723ab861a4c (commit)
      from  27daf08f38eec505c224e7776678b32d50241e13 (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 5641c4b171f72dd600e17e6db46b3723ab861a4c
Author: radhika <radhika at curoverse.com>
Date:   Wed Aug 5 17:51:52 2015 -0400

    6277: slightly improved tests

diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index ff58f1f..f1e7b4f 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -202,7 +202,7 @@ class Collection < ArvadosModel
     begin
       Keep::Manifest.validate! manifest_text
       true
-    rescue => e
+    rescue ArgumentError => e
       errors.add :manifest_text, e.message
       false
     end
diff --git a/services/api/test/functional/arvados/v1/collections_controller_test.rb b/services/api/test/functional/arvados/v1/collections_controller_test.rb
index 99b0333..a8583be 100644
--- a/services/api/test/functional/arvados/v1/collections_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb
@@ -811,13 +811,12 @@ EOS
   end
 
   [
-    nil,
     ". 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
     "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
   ].each do |manifest_text|
-    test "create collection with invalid manifest #{manifest_text}" do
+    test "create collection with invalid manifest #{manifest_text} and expect error" do
       authorize_with :active
       post :create, {
         collection: {
@@ -825,26 +824,38 @@ EOS
           portable_data_hash: "d41d8cd98f00b204e9800998ecf8427e+0"
         }
       }
-      if manifest_text
-        assert_response 422
-        response_errors = json_response['errors']
-        assert_not_nil response_errors, 'Expected error in response'
-        assert(response_errors.first.include?('Invalid manifest'),
-               "Expected 'Invalid manifest' error in #{response_errors.first}")
-      else
-        assert_response 200
-      end
+      assert_response 422
+      response_errors = json_response['errors']
+      assert_not_nil response_errors, 'Expected error in response'
+      assert(response_errors.first.include?('Invalid manifest'),
+             "Expected 'Invalid manifest' error in #{response_errors.first}")
+    end
+  end
+
+  [
+    [nil, "d41d8cd98f00b204e9800998ecf8427e+0"],
+    ["", "d41d8cd98f00b204e9800998ecf8427e+0"],
+    [". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n", "d30fe8ae534397864cb96c544f4cf102+47"],
+  ].each do |manifest_text, pdh|
+    test "create collection with valid manifest #{manifest_text.inspect} and expect success" do
+      authorize_with :active
+      post :create, {
+        collection: {
+          manifest_text: manifest_text,
+          portable_data_hash: pdh
+        }
+      }
+      assert_response 200
     end
   end
 
   [
-    nil,
     ". 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
     "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
   ].each do |manifest_text|
-    test "update collection with invalid manifest #{manifest_text}" do
+    test "update collection with invalid manifest #{manifest_text} and expect error" do
       authorize_with :active
       post :update, {
         id: 'zzzzz-4zz18-bv31uwvy3neko21',
@@ -852,15 +863,28 @@ EOS
           manifest_text: manifest_text,
         }
       }
-      if manifest_text
-        assert_response 422
-        response_errors = json_response['errors']
-        assert_not_nil response_errors, 'Expected error in response'
-        assert(response_errors.first.include?('Invalid manifest'),
-               "Expected 'Invalid manifest' error in #{response_errors.first}")
-      else
-        assert_response 200
-      end
+      assert_response 422
+      response_errors = json_response['errors']
+      assert_not_nil response_errors, 'Expected error in response'
+      assert(response_errors.first.include?('Invalid manifest'),
+             "Expected 'Invalid manifest' error in #{response_errors.first}")
+    end
+  end
+
+  [
+    nil,
+    "",
+    ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
+  ].each do |manifest_text|
+    test "update collection with valid manifest #{manifest_text.inspect} and expect success" do
+      authorize_with :active
+      post :update, {
+        id: 'zzzzz-4zz18-bv31uwvy3neko21',
+        collection: {
+          manifest_text: manifest_text,
+        }
+      }
+      assert_response 200
     end
   end
 end
diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb
index 0b45144..c81d543 100644
--- a/services/api/test/unit/collection_test.rb
+++ b/services/api/test/unit/collection_test.rb
@@ -40,7 +40,6 @@ class CollectionTest < ActiveSupport::TestCase
   end
 
   [
-    nil,
     ". 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
     "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
@@ -49,17 +48,25 @@ class CollectionTest < ActiveSupport::TestCase
     test "create collection with invalid manifest text #{manifest_text} and expect error" do
       act_as_system_user do
         c = Collection.create(manifest_text: manifest_text)
-        if manifest_text
-          assert !c.valid?
-        else
-          assert c.valid?
-        end
+        assert !c.valid?
       end
     end
   end
 
   [
     nil,
+    "",
+    ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
+  ].each do |manifest_text|
+    test "create collection with valid manifest text #{manifest_text.inspect} and expect success" do
+      act_as_system_user do
+        c = Collection.create(manifest_text: manifest_text)
+        assert c.valid?
+      end
+    end
+  end
+
+  [
     ". 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
     "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
@@ -71,11 +78,23 @@ class CollectionTest < ActiveSupport::TestCase
         assert c.valid?
 
         c.update_attribute 'manifest_text', manifest_text
-        if manifest_text
-          assert !c.valid?
-        else
-          assert c.valid?
-        end
+        assert !c.valid?
+      end
+    end
+  end
+
+  [
+    nil,
+    "",
+    ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
+  ].each do |manifest_text|
+    test "update collection with valid manifest text #{manifest_text.inspect} and expect success" do
+      act_as_system_user do
+        c = create_collection 'foo', Encoding::US_ASCII
+        assert c.valid?
+
+        c.update_attribute 'manifest_text', manifest_text
+        assert c.valid?
       end
     end
   end

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list