3410: Merge branch 'master' into 3410-replication-attrs
authorTom Clegg <tom@curoverse.com>
Mon, 16 Feb 2015 19:13:00 +0000 (14:13 -0500)
committerTom Clegg <tom@curoverse.com>
Mon, 16 Feb 2015 19:13:00 +0000 (14:13 -0500)
Conflicts:
services/api/test/fixtures/collections.yml
services/api/test/unit/collection_test.rb

1  2 
sdk/python/tests/test_arv_put.py
services/api/app/controllers/arvados/v1/schema_controller.rb
services/api/app/models/collection.rb
services/api/test/fixtures/collections.yml
services/api/test/functional/arvados/v1/collections_controller_test.rb
services/api/test/unit/collection_test.rb

Simple merge
Simple merge
index c14650c2f469ceff1a7b1fe1bb670428d09b698b,a6387406ed8582e2c4b5c9d364ca235e35edf40b..220122533bea050ef23cb70cef5ba9f5454ef89b
@@@ -391,48 -401,33 +401,75 @@@ collection_with_unique_words_to_test_fu
    name: collection_with_some_unique_words
    description: The quick_brown_fox jumps over the lazy_dog
  
 +replication_undesired_unconfirmed:
 +  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
 +  created_at: 2015-02-07 00:19:28.596506247 Z
 +  modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
 +  modified_at: 2015-02-07 00:19:28.596338465 Z
 +  portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
 +  replication_desired: ~
 +  replication_confirmed_at: ~
 +  replication_confirmed: ~
 +  updated_at: 2015-02-07 00:19:28.596236608 Z
 +  uuid: zzzzz-4zz18-wjxq7uzx2m9jj4a
 +  manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
 +  name: replication want=null have=null
 +
 +replication_desired_2_unconfirmed:
 +  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
 +  created_at: 2015-02-07 00:21:35.050333515 Z
 +  modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
 +  modified_at: 2015-02-07 00:21:35.050189104 Z
 +  portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
 +  replication_desired: 2
 +  replication_confirmed_at: ~
 +  replication_confirmed: ~
 +  updated_at: 2015-02-07 00:21:35.050126576 Z
 +  uuid: zzzzz-4zz18-3t236wrz4769h7x
 +  manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
 +  name: replication want=2 have=null
 +
 +replication_desired_2_confirmed_2:
 +  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
 +  created_at: 2015-02-07 00:19:28.596506247 Z
 +  modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
 +  modified_at: 2015-02-07 00:19:28.596338465 Z
 +  portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
 +  replication_desired: 2
 +  replication_confirmed_at: 2015-02-07 00:24:52.983381227 Z
 +  replication_confirmed: 2
 +  updated_at: 2015-02-07 00:24:52.983381227 Z
 +  uuid: zzzzz-4zz18-434zv1tnnf2rygp
 +  manifest_text: ". acbd18db4cc2f85cedef654fccc4a4d8+3 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 3:6:bar\n"
 +  name: replication want=2 have=2
 +
+ collection_with_empty_properties:
+   uuid: zzzzz-4zz18-emptyproperties
+   portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
+   owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+   created_at: 2015-02-13T17:22:54Z
+   modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+   modified_by_user_uuid: zzzzz-tpzed-d9tiejq69daie8f
+   modified_at: 2015-02-13T17:22:54Z
+   updated_at: 2015-02-13T17:22:54Z
+   manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+   name: collection with empty properties
+   properties: {}
+ collection_with_one_property:
+   uuid: zzzzz-4zz18-withoneproperty
+   portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
+   owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+   created_at: 2015-02-13T17:22:54Z
+   modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+   modified_by_user_uuid: zzzzz-tpzed-d9tiejq69daie8f
+   modified_at: 2015-02-13T17:22:54Z
+   updated_at: 2015-02-13T17:22:54Z
+   manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+   name: collection with one property
+   properties:
+     property1: value1
  # Test Helper trims the rest of the file
  
  # Do not add your fixtures below this line as the rest of this file will be trimmed by test_helper
index 42059e7bd7201404de943cf148e8d8726ddce62d,91802255e1b5a53084597bba586c9bd07bf2489d..54ffe66f174baf341ae19a00a58c71b578f9b3ce
@@@ -708,7 -712,30 +708,30 @@@ EO
          },
        }
        assert_response :success
 -      assert_equal (ask or 2), json_response['replication_desired']
 +      assert_equal ask, json_response['replication_desired']
      end
    end
+   test "get collection with properties" do
+     authorize_with :active
+     get :show, {id: collections(:collection_with_one_property).uuid}
+     assert_response :success
+     assert_not_nil json_response['uuid']
+     assert_equal 'value1', json_response['properties']['property1']
+   end
+   test "create collection with properties" do
+     authorize_with :active
+     manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
+     post :create, {
+       collection: {
+         manifest_text: manifest_text,
+         portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47",
+         properties: {'property_1' => 'value_1'}
+       }
+     }
+     assert_response :success
+     assert_not_nil json_response['uuid']
+     assert_equal 'value_1', json_response['properties']['property_1']
+   end
  end
index 10ef2b4469ac12f2380031fd7b4af2fad4a26bc3,08f46fddccced0974db6cf12f51f04827f862734..37ab1d3172b2a72c488e5512776cec88dba3482f
@@@ -145,83 -129,12 +145,92 @@@ class CollectionTest < ActiveSupport::T
      end
    end
  
 +  test "replication_confirmed* can be set by admin user" do
 +    c = collections(:replication_desired_2_unconfirmed)
 +    act_as_user users(:admin) do
 +      assert c.update_attributes(replication_confirmed: 2,
 +                                 replication_confirmed_at: Time.now)
 +    end
 +  end
 +
 +  test "replication_confirmed* cannot be set by non-admin user" do
 +    act_as_user users(:active) do
 +      c = collections(:replication_desired_2_unconfirmed)
 +      # Cannot set just one at a time.
 +      assert_raise ArvadosModel::PermissionDeniedError do
 +        c.update_attributes replication_confirmed: 1
 +      end
 +      assert_raise ArvadosModel::PermissionDeniedError do
 +        c.update_attributes replication_confirmed_at: Time.now
 +      end
 +      # Cannot set both at once, either.
 +      assert_raise ArvadosModel::PermissionDeniedError do
 +        c.update_attributes(replication_confirmed: 1,
 +                            replication_confirmed_at: Time.now)
 +      end
 +    end
 +  end
 +
 +  test "replication_confirmed* can be cleared (but only together) by non-admin user" do
 +    act_as_user users(:active) do
 +      c = collections(:replication_desired_2_confirmed_2)
 +      # Cannot clear just one at a time.
 +      assert_raise ArvadosModel::PermissionDeniedError do
 +        c.update_attributes replication_confirmed: nil
 +      end
 +      c.reload
 +      assert_raise ArvadosModel::PermissionDeniedError do
 +        c.update_attributes replication_confirmed_at: nil
 +      end
 +      # Can clear both at once.
 +      c.reload
 +      assert c.update_attributes(replication_confirmed: nil,
 +                                 replication_confirmed_at: nil)
 +    end
 +  end
 +
 +  test "clear replication_confirmed* when introducing a new block in manifest" do
 +    c = collections(:replication_desired_2_confirmed_2)
 +    act_as_user users(:active) do
 +      assert c.update_attributes(manifest_text: collections(:user_agreement).signed_manifest_text)
 +      assert_nil c.replication_confirmed
 +      assert_nil c.replication_confirmed_at
 +    end
 +  end
 +
 +  test "don't clear replication_confirmed* when just renaming a file" do
 +    c = collections(:replication_desired_2_confirmed_2)
 +    act_as_user users(:active) do
 +      new_manifest = c.signed_manifest_text.sub(':bar', ':foo')
 +      assert c.update_attributes(manifest_text: new_manifest)
 +      assert_equal 2, c.replication_confirmed
 +      assert_not_nil c.replication_confirmed_at
 +    end
 +  end
 +
 +  test "don't clear replication_confirmed* when just deleting a data block" do
 +    c = collections(:replication_desired_2_confirmed_2)
 +    act_as_user users(:active) do
 +      new_manifest = c.signed_manifest_text
 +      new_manifest.sub!(/ \S+:bar/, '')
 +      new_manifest.sub!(/ acbd\S+/, '')
 +
 +      # Confirm that we did just remove a block from the manifest (if
 +      # not, this test would pass without testing the relevant case):
 +      assert_operator new_manifest.length+40, :<, c.signed_manifest_text.length
 +
 +      assert c.update_attributes(manifest_text: new_manifest)
 +      assert_equal 2, c.replication_confirmed
 +      assert_not_nil c.replication_confirmed_at
 +    end
 +  end
++
+   test "create collection with properties" do
+     act_as_system_user do
+       c = Collection.create(manifest_text: ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo\n",
+                             properties: {'property_1' => 'value_1'})
+       assert c.valid?
+       assert_equal 'value_1', c.properties['property_1']
+     end
+   end
  end