require 'test_helper'
class UserTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
+ test "get owned_items" do
+ use_token :active
+ oi = User.find(api_fixture('users')['active']['uuid']).owned_items
+ assert_operator(0, :<, oi.count,
+ "Expected to find some items belonging to :active user")
- assert_operator(0, :<, oi.items_available
++ assert_operator(0, :<, oi.items_available,
+ "Expected owned_items response to have items_available > 0")
+ oi_uuids = oi.collect { |i| i['uuid'] }
+ expect = api_fixture('specimens')['owned_by_active_user']['uuid']
+ assert_includes(oi_uuids, expect,
+ "Expected active user's owned_items to include #{expect}")
+ end
end
operand = Time.parse operand
end
param_out << operand
+ elsif operand.nil? and operator == '='
+ cond_out << "#{ar_table_name}.#{attr} is null"
else
- raise ArgumentError.new("Invalid operand type '#{operand.class}' for '#{operator}' operator in filter")
- raise ArgumentError.new("Invalid operand type '#{attr.class}' "\
++ raise ArgumentError.new("Invalid operand type '#{operand.class}' "\
+ "for '#{operator}' operator in filters")
end
when 'in'
if operand.is_a? Array
- cond_out << "#{table_name}.#{attr} IN (?)"
+ cond_out << "#{ar_table_name}.#{attr} IN (?)"
param_out << operand
else
- raise ArgumentError.new("Invalid argument '#{operand}' for 'in' operator in filter")
- raise ArgumentError.new("Invalid operand type '#{attr.class}' "\
++ raise ArgumentError.new("Invalid operand type '#{operand.class}' "\
+ "for '#{operator}' operator in filters")
end
when 'is_a'
operand = [operand] unless operand.is_a? Array
namespace :arvados do
namespace :v1 do
- match '/nodes/:uuid/ping' => 'nodes#ping', :as => :ping_node
- match '/keep_disks/ping' => 'keep_disks#ping', :as => :ping_keep_disk
- match '/links/from/:tail_uuid' => 'links#index', :as => :arvados_v1_links_from
- match '/users/current' => 'users#current'
- match '/users/system' => 'users#system'
- match '/jobs/queue' => 'jobs#queue'
- match '/jobs/:uuid/log_tail_follow' => 'jobs#log_tail_follow'
- post '/jobs/:uuid/cancel' => 'jobs#cancel'
- match '/users/:uuid/event_stream' => 'users#event_stream'
- post '/users/:uuid/activate' => 'users#activate'
- post '/users/setup' => 'users#setup'
- post '/users/:uuid/unsetup' => 'users#unsetup'
- match '/virtual_machines/get_all_logins' => 'virtual_machines#get_all_logins'
- match '/virtual_machines/:uuid/logins' => 'virtual_machines#logins'
- post '/api_client_authorizations/create_system_auth' => 'api_client_authorizations#create_system_auth'
- match '/repositories/get_all_permissions' => 'repositories#get_all_permissions'
- get '/user_agreements/signatures' => 'user_agreements#signatures'
- post '/user_agreements/sign' => 'user_agreements#sign'
- get '/collections/:uuid/provenance' => 'collections#provenance'
- get '/collections/:uuid/used_by' => 'collections#used_by'
- resources :collections
- resources :links
- resources :nodes
- resources :pipeline_templates
- resources :pipeline_instances
- resources :specimens
+ resources :api_client_authorizations do
+ post 'create_system_auth', on: :collection
+ end
+ resources :api_clients
+ resources :authorized_keys
+ resources :collections do
+ get 'provenance', on: :member
+ get 'used_by', on: :member
+ end
- resources :groups
+ resources :groups do
+ get 'owned_items', on: :member
+ end
+ resources :humans
+ resources :job_tasks
+ resources :jobs do
+ get 'queue', on: :collection
+ get 'log_tail_follow', on: :member
+ post 'cancel', on: :member
+ end
+ resources :keep_disks do
+ post 'ping', on: :collection
+ end
+ resources :links
resources :logs
+ resources :nodes do
+ post 'ping', on: :member
+ end
+ resources :pipeline_instances
+ resources :pipeline_templates
+ resources :repositories do
+ get 'get_all_permissions', on: :collection
+ end
+ resources :specimens
+ resources :traits
+ resources :user_agreements do
+ get 'signatures', on: :collection
+ post 'sign', on: :collection
+ end
resources :users do
+ get 'current', on: :collection
+ get 'system', on: :collection
+ get 'event_stream', on: :member
+ post 'activate', on: :member
+ post 'setup', on: :collection
+ post 'unsetup', on: :member
+ get 'owned_items', on: :member
end
- resources :api_clients
- resources :api_client_authorizations
- resources :jobs
- resources :job_tasks
- resources :keep_disks
- resources :authorized_keys
- resources :virtual_machines
- resources :repositories
- resources :traits
- resources :humans
- resources :user_agreements
+ resources :virtual_machines do
+ get 'logins', on: :member
+ get 'get_all_logins', on: :collection
+ end
end
end
test "get index with filters= (empty string)" do
get "/arvados/v1/collections", {:format => :json, :filters => ''}, auth(:active)
assert_response :success
- assert_equal "arvados#collectionList", jresponse['kind']
+ assert_equal "arvados#collectionList", json_response['kind']
end
- assert_match /nvalid element.*not an array/, jresponse['errors'].join(' ')
+ test "get index with invalid filters (array of strings) responds 422" do
+ get "/arvados/v1/collections", {
+ :format => :json,
+ :filters => ['uuid', '=', 'ad02e37b6a7f45bbe2ead3c29a109b8a+54'].to_json
+ }, auth(:active)
+ assert_response 422
- assert_match /nvalid attribute/, jresponse['errors'].join(' ')
++ assert_match /nvalid element.*not an array/, json_response['errors'].join(' ')
+ end
+
+ test "get index with invalid filters (unsearchable column) responds 422" do
+ get "/arvados/v1/collections", {
+ :format => :json,
+ :filters => [['this_column_does_not_exist', '=', 'bogus']].to_json
+ }, auth(:active)
+ assert_response 422
- assert_match /nvalid operator/, jresponse['errors'].join(' ')
++ assert_match /nvalid attribute/, json_response['errors'].join(' ')
+ end
+
+ test "get index with invalid filters (invalid operator) responds 422" do
+ get "/arvados/v1/collections", {
+ :format => :json,
+ :filters => [['uuid', ':-(', 'displeased']].to_json
+ }, auth(:active)
+ assert_response 422
- assert_match /nvalid operand type/, jresponse['errors'].join(' ')
++ assert_match /nvalid operator/, json_response['errors'].join(' ')
+ end
+
+ test "get index with invalid filters (invalid operand type) responds 422" do
+ get "/arvados/v1/collections", {
+ :format => :json,
+ :filters => [['uuid', '=', {foo: 'bar'}]].to_json
+ }, auth(:active)
+ assert_response 422
++ assert_match /nvalid operand type/, json_response['errors'].join(' ')
+ end
+
test "get index with where= (empty string)" do
get "/arvados/v1/collections", {:format => :json, :where => ''}, auth(:active)
assert_response :success
--- /dev/null
- assert_not_nil jresponse['errors']
+require 'test_helper'
+
+class ErrorsTest < ActionDispatch::IntegrationTest
+ fixtures :api_client_authorizations
+
+ %w(/arvados/v1/shoes /arvados/shoes /shoes /nodes /users).each do |path|
+ test "non-existent route #{path}" do
+ get path, {:format => :json}, auth(:active)
+ assert_nil assigns(:objects)
+ assert_nil assigns(:object)
++ assert_not_nil json_response['errors']
+ assert_response 404
+ end
+ end
+
+ n=0
+ Rails.application.routes.routes.each do |route|
+ test "route #{n += 1} '#{route.path.spec.to_s}' is not an accident" do
+ # Generally, new routes should appear under /arvados/v1/. If
+ # they appear elsewhere, that might have been caused by default
+ # rails generator behavior that we don't want.
+ assert_match(/^\/(|\*a|arvados\/v1\/.*|auth\/.*|login|logout|discovery\/.*|static\/.*|themes\/.*)(\(\.:format\))?$/,
+ route.path.spec.to_s,
+ "Unexpected new route: #{route.path.spec}")
+ end
+ end
+end