[ARVADOS] updated: 83fa2045a190732f8dd9bed3e5c6071ce66da07f

git at public.curoverse.com git at public.curoverse.com
Sun Mar 23 17:22:12 EDT 2014


Summary of changes:
 services/api/app/models/user.rb                    |   20 ++++++---
 .../functional/arvados/v1/users_controller_test.rb |   41 +++++++++++++++++--
 2 files changed, 49 insertions(+), 12 deletions(-)

       via  83fa2045a190732f8dd9bed3e5c6071ce66da07f (commit)
      from  8c021e4b54a8179e86dd887e1eb8db9ef4dd9672 (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 83fa2045a190732f8dd9bed3e5c6071ce66da07f
Author: radhika chippada <radhika at radhika.curoverse>
Date:   Sun Mar 23 17:20:37 2014 -0400

    Raise exceptions on errors such as 'All users' group does not exist and a vm for the vm_uuid param does not exist. Add additional functional tests and update previous tests accordingly.

diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb
index 672dd19..54ea3e5 100644
--- a/services/api/app/models/user.rb
+++ b/services/api/app/models/user.rb
@@ -242,6 +242,7 @@ class User < ArvadosModel
   end
 
   def create_user_repo_link(repo_name)
+    # repo_name is optional
     if not repo_name
       logger.warn ("Repository name not given for #{self.uuid}.")
       return
@@ -282,13 +283,18 @@ class User < ArvadosModel
 
   # create login permission for the given vm_uuid, if it does not already exist
   def create_vm_login_permission_link(vm_uuid, repo_name)
-    # Look up the given virtual machine just to make sure it really exists.
     begin
-      vm = VirtualMachine.where(uuid: vm_uuid).first
-
-      if not vm
-        logger.warn "Could not find virtual machine for #{vm_uuid.inspect}"
-        return
+              
+      # vm uuid is optional
+      if vm_uuid 
+        vm = VirtualMachine.where(uuid: vm_uuid).first
+
+        if not vm
+          logger.warn "Could not find virtual machine for #{vm_uuid.inspect}"
+          raise "No vm found for #{vm_uuid}"
+        end
+      else
+        return 
       end
 
       logger.info { "vm uuid: " + vm[:uuid] }
@@ -322,7 +328,7 @@ class User < ArvadosModel
 
     if not group
       logger.warn "No 'All users' group with uuid '*-*-fffffffffffffff'."
-      return
+      raise "No 'All users' group with uuid '*-*-fffffffffffffff' is found"
     else
       logger.info { "\"All users\" group uuid: " + group[:uuid] }
 
diff --git a/services/api/test/functional/arvados/v1/users_controller_test.rb b/services/api/test/functional/arvados/v1/users_controller_test.rb
index ee158d1..474c1da 100644
--- a/services/api/test/functional/arvados/v1/users_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/users_controller_test.rb
@@ -64,7 +64,6 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
 
     post :setup, {
       repo_name: repo_name,
-      vm_uuid: 'no_such_vm',
       user: {
         uuid: "this_is_agreeable",        
         first_name: "in_create_test_first_name",
@@ -106,7 +105,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     post :setup, {
       uuid: 'not_an_existing_uuid_and_not_email_format',
       repo_name: 'test_repo',
-      vm_uuid: 'no_such_vm'
+      vm_uuid: @vm_uuid,
     }
     response_body = JSON.parse(@response.body)
     response_errors = response_body['errors']
@@ -146,12 +145,11 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
         @vm_uuid, resp_obj['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
   end
 
-  test "create user with valid email, vm and repo as input" do
+  test "create user with valid email and repo as input" do
     authorize_with :admin
 
     post :setup, {
       repo_name: 'test_repo',
-      vm_uuid: 'no_such_vm',
       user: {email: 'abc at xyz.com'}
     }
 
@@ -164,6 +162,40 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     verify_num_links @all_links_at_start, 3
   end
 
+  test "create user with valid email, repo and fake vm as input" do
+    authorize_with :admin
+
+    post :setup, {
+      repo_name: 'test_repo',
+      vm_uuid: 'no_such_vm',
+      user: {email: 'abc at xyz.com'}
+    }
+
+    response_body = JSON.parse(@response.body)
+    response_errors = response_body['errors']
+    assert_not_nil response_errors, 'Expected error in response'
+    assert (response_errors.first.include? "No vm found for no_such_vm"), 
+          'Expected RuntimeError: No vm found for no_such_vm'
+  end
+
+  test "create user with valid email, repo and real vm as input" do
+    authorize_with :admin
+
+    post :setup, {
+      repo_name: 'test_repo',
+      vm_uuid: @vm_uuid,
+      user: {email: 'abc at xyz.com'}
+    }
+
+    assert_response :success
+    response_object = JSON.parse(@response.body)['items']['user']
+    assert_not_nil response_object['uuid'], 'expected uuid for the new user'
+    assert_equal response_object['email'], 'abc at xyz.com', 'expected given email'
+
+    # three extra links; login link, group link and repo link
+    verify_num_links @all_links_at_start, 4
+  end
+
   test "create user with valid email, no vm and repo as input" do
     authorize_with :admin
 
@@ -239,7 +271,6 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
 
     post :setup, {
       repo_name: 'test_repo',
-      vm_uuid: 'no_such_vm',
       openid_prefix: 'http://www.xyz.com/account',
       user: {
         first_name: "in_create_test_first_name",

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list