[ARVADOS] created: 7ef27804d92e2c38ff6b22aab4b113b3e1817bf5
git at public.curoverse.com
git at public.curoverse.com
Sun Feb 15 15:52:53 EST 2015
at 7ef27804d92e2c38ff6b22aab4b113b3e1817bf5 (commit)
commit 7ef27804d92e2c38ff6b22aab4b113b3e1817bf5
Author: Radhika Chippada <radhika at curoverse.com>
Date: Sun Feb 15 15:48:46 2015 -0500
5186: collection properties attribute is a hash
diff --git a/apps/workbench/test/controllers/collections_controller_test.rb b/apps/workbench/test/controllers/collections_controller_test.rb
index 45124f7..0e2606f 100644
--- a/apps/workbench/test/controllers/collections_controller_test.rb
+++ b/apps/workbench/test/controllers/collections_controller_test.rb
@@ -355,4 +355,37 @@ class CollectionsControllerTest < ActionController::TestCase
assert /#{stage3_id}->#{stage3_out}/.match(used_by_svg)
end
+
+ test "view collection with empty properties" do
+ fixture_name = :collection_with_empty_properties
+ show_collection(fixture_name, :active)
+ assert_equal(api_fixture('collections')[fixture_name.to_s]['name'], assigns(:object).name)
+ assert_not_nil(assigns(:object).properties)
+ assert_empty(assigns(:object).properties)
+ end
+
+ test "view collection with one property" do
+ fixture_name = :collection_with_one_property
+ show_collection(fixture_name, :active)
+ fixture = api_fixture('collections')[fixture_name.to_s]
+ assert_equal(fixture['name'], assigns(:object).name)
+ assert_equal(fixture['properties'][0], assigns(:object).properties[0])
+ end
+
+ test "create collection with properties" do
+ post :create, {
+ collection: {
+ name: 'collection created with properties',
+ manifest_text: '',
+ properties: {
+ property_1: 'value_1'
+ },
+ },
+ format: :json
+ }, session_for(:active)
+ assert_response :success
+ assert_not_nil assigns(:object).uuid
+ assert_equal 'collection created with properties', assigns(:object).name
+ assert_equal 'value_1', assigns(:object).properties[:property_1]
+ end
end
diff --git a/services/api/app/controllers/arvados/v1/collections_controller.rb b/services/api/app/controllers/arvados/v1/collections_controller.rb
index 956de8e..321cb72 100644
--- a/services/api/app/controllers/arvados/v1/collections_controller.rb
+++ b/services/api/app/controllers/arvados/v1/collections_controller.rb
@@ -1,6 +1,8 @@
require "arvados/keep"
class Arvados::V1::CollectionsController < ApplicationController
+ accept_attribute_as_json :properties, Hash
+
def create
if resource_attrs[:uuid] and (loc = Keep::Locator.parse(resource_attrs[:uuid]))
resource_attrs[:portable_data_hash] = loc.to_s
diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index 334f3c6..07dcbb5 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -5,6 +5,8 @@ class Collection < ArvadosModel
include KindAndEtag
include CommonApiTemplate
+ serialize :properties, Hash
+
before_validation :check_encoding
before_validation :check_signatures
before_validation :strip_manifest_text
diff --git a/services/api/test/fixtures/collections.yml b/services/api/test/fixtures/collections.yml
index d5b78aa..a638740 100644
--- a/services/api/test/fixtures/collections.yml
+++ b/services/api/test/fixtures/collections.yml
@@ -401,6 +401,33 @@ collection_with_unique_words_to_test_full_text_search:
name: collection_with_some_unique_words
description: The quick_brown_fox jumps over the lazy_dog
+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
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 61b0557..3af96e2 100644
--- a/services/api/test/functional/arvados/v1/collections_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb
@@ -715,4 +715,19 @@ EOS
assert_equal (ask or 2), json_response['replication_desired']
end
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
diff --git a/services/api/test/integration/collections_api_test.rb b/services/api/test/integration/collections_api_test.rb
index 93ed156..6fba5f7 100644
--- a/services/api/test/integration/collections_api_test.rb
+++ b/services/api/test/integration/collections_api_test.rb
@@ -273,4 +273,24 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
assert_equal first_item['description'], 'The quick_brown_fox jumps over the lazy_dog'
end
end
+
+ test "create and get collection with properties" do
+ # create collection to be searched for
+ signed_manifest = Collection.sign_manifest(". bad42fa702ae3ea7d888fef11b46f450+44 0:44:my_test_file.txt\n", api_token(:active))
+ post "/arvados/v1/collections", {
+ format: :json,
+ collection: {manifest_text: signed_manifest,
+ properties: {'property_1' => 'value_1'}}.to_json,
+ }, auth(:active)
+ assert_response 200
+ assert_not_nil json_response['uuid']
+ assert_equal 'value_1', json_response['properties']['property_1']
+
+ # get it
+ get "/arvados/v1/collections/#{json_response['uuid']}", {
+ format: :json,
+ }, auth(:active)
+ assert_response 200
+ assert_equal 'value_1', json_response['properties']['property_1']
+ end
end
diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb
index 59f9d3d..08f46fd 100644
--- a/services/api/test/unit/collection_test.rb
+++ b/services/api/test/unit/collection_test.rb
@@ -128,4 +128,13 @@ class CollectionTest < ActiveSupport::TestCase
end
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
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list