X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/11c6f1d759040f2af8a68d80ae78dd57a9b2d976..1a599ec69ad8d533da1f12ad5d2c5789aa1c14e2:/services/api/test/integration/select_test.rb diff --git a/services/api/test/integration/select_test.rb b/services/api/test/integration/select_test.rb index b5f09df7c7..7fbab3b3b0 100644 --- a/services/api/test/integration/select_test.rb +++ b/services/api/test/integration/select_test.rb @@ -1,29 +1,42 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class SelectTest < ActionDispatch::IntegrationTest test "should select just two columns" do - get "/arvados/v1/links", {:format => :json, :select => ['uuid', 'link_class']}, auth(:active) + get "/arvados/v1/links", + params: {:format => :json, :select => ['uuid', 'link_class']}, + headers: auth(:active) assert_response :success assert_equal json_response['items'].count, json_response['items'].select { |i| - i.count == 2 and i['uuid'] != nil and i['link_class'] != nil + i.count == 3 and i['uuid'] != nil and i['link_class'] != nil }.count end test "fewer distinct than total count" do - get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => false}, auth(:active) + get "/arvados/v1/links", + params: {:format => :json, :select => ['link_class'], :distinct => false}, + headers: auth(:active) assert_response :success links = json_response['items'] - get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => true}, auth(:active) + get "/arvados/v1/links", + params: {:format => :json, :select => ['link_class'], :distinct => true}, + headers: auth(:active) assert_response :success distinct = json_response['items'] - assert distinct.count < links.count, "distinct count should be less than link count" + assert_operator(distinct.count, :<, links.count, + "distinct count should be less than link count") assert_equal links.uniq.count, distinct.count end test "select with order" do - get "/arvados/v1/links", {:format => :json, :select => ['uuid'], :order => ["uuid asc"]}, auth(:active) + get "/arvados/v1/links", + params: {:format => :json, :select => ['uuid'], :order => ["uuid asc"]}, + headers: auth(:active) assert_response :success assert json_response['items'].length > 0 @@ -35,8 +48,32 @@ class SelectTest < ActionDispatch::IntegrationTest end end + test "select with default order" do + get "/arvados/v1/links", + params: {format: :json, select: ['uuid']}, + headers: auth(:admin) + assert_response :success + uuids = json_response['items'].collect { |i| i['uuid'] } + assert_equal uuids, uuids.sort + end + + def assert_link_classes_ascend(current_class, prev_class) + # Databases and Ruby don't always agree about string ordering with + # punctuation. If the strings aren't ascending normally, check + # that they're equal up to punctuation. + if current_class < prev_class + class_prefix = current_class.split(/\W/).first + assert prev_class.start_with?(class_prefix) + end + end + test "select two columns with order" do - get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]}, auth(:active) + get "/arvados/v1/links", + params: { + :format => :json, + :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"] + }, + headers: auth(:active) assert_response :success assert json_response['items'].length > 0 @@ -49,7 +86,7 @@ class SelectTest < ActionDispatch::IntegrationTest prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz" end - assert i['link_class'] >= prev_link_class + assert_link_classes_ascend(i['link_class'], prev_link_class) assert i['uuid'] < prev_uuid prev_link_class = i['link_class'] @@ -58,7 +95,12 @@ class SelectTest < ActionDispatch::IntegrationTest end test "select two columns with old-style order syntax" do - get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc'}, auth(:active) + get "/arvados/v1/links", + params: { + :format => :json, + :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc' + }, + headers: auth(:active) assert_response :success assert json_response['items'].length > 0 @@ -71,7 +113,7 @@ class SelectTest < ActionDispatch::IntegrationTest prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz" end - assert i['link_class'] >= prev_link_class + assert_link_classes_ascend(i['link_class'], prev_link_class) assert i['uuid'] < prev_uuid prev_link_class = i['link_class']