1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class Arvados::V1::FiltersTest < ActionController::TestCase
8 test '"not in" filter passes null values' do
9 @controller = Arvados::V1::GroupsController.new
12 filters: [ ['group_class', 'not in', ['project']] ],
15 assert_response :success
16 found = assigns(:objects)
17 assert_includes(found.collect(&:group_class), nil,
18 "'group_class not in ['project']' filter should pass null")
21 test 'error message for non-array element in filters array' do
22 @controller = Arvados::V1::CollectionsController.new
23 authorize_with :active
25 filters: [{bogus: 'filter'}],
28 assert_match(/Invalid element in filters array/,
29 json_response['errors'].join(' '))
32 test 'error message for full text search on a specific column' do
33 @controller = Arvados::V1::CollectionsController.new
34 authorize_with :active
36 filters: [['uuid', '@@', 'abcdef']],
39 assert_match(/not supported/, json_response['errors'].join(' '))
42 test 'difficult characters in full text search' do
43 @controller = Arvados::V1::CollectionsController.new
44 authorize_with :active
46 filters: [['any', '@@', 'a|b"c']],
48 assert_response :success
49 # (Doesn't matter so much which results are returned.)
52 test 'array operand in full text search' do
53 @controller = Arvados::V1::CollectionsController.new
54 authorize_with :active
56 filters: [['any', '@@', ['abc', 'def']]],
59 assert_match(/not supported/, json_response['errors'].join(' '))
62 test 'api responses provide timestamps with nanoseconds' do
63 @controller = Arvados::V1::CollectionsController.new
64 authorize_with :active
66 assert_response :success
67 assert_not_empty json_response['items']
68 json_response['items'].each do |item|
69 %w(created_at modified_at).each do |attr|
70 # Pass fixtures with null timestamps.
71 next if item[attr].nil?
72 assert_match(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d{9}Z$/, item[attr])
77 %w(< > <= >= =).each do |operator|
78 test "timestamp #{operator} filters work with nanosecond precision" do
79 # Python clients like Node Manager rely on this exact format.
80 # If you must change this format for some reason, make sure you
81 # coordinate the change with them.
82 expect_match = !!operator.index('=')
83 mine = act_as_user users(:active) do
84 Collection.create!(manifest_text: '')
86 timestamp = mine.modified_at.strftime('%Y-%m-%dT%H:%M:%S.%NZ')
87 @controller = Arvados::V1::CollectionsController.new
88 authorize_with :active
90 filters: [['modified_at', operator, timestamp],
91 ['uuid', '=', mine.uuid]],
93 assert_response :success
94 uuids = json_response['items'].map { |item| item['uuid'] }
96 assert_includes uuids, mine.uuid
98 assert_not_includes uuids, mine.uuid
103 test "full text search with count='none'" do
104 @controller = Arvados::V1::GroupsController.new
105 authorize_with :admin
111 filters: [['any', '@@', Rails.configuration.uuid_prefix]],
114 assert_response :success
116 all_objects = Hash.new(0)
117 json_response['items'].map{|o| o['kind']}.each{|t| all_objects[t] += 1}
119 assert_equal true, all_objects['arvados#group']>0
120 assert_equal true, all_objects['arvados#job']>0
121 assert_equal true, all_objects['arvados#pipelineInstance']>0
122 assert_equal true, all_objects['arvados#pipelineTemplate']>0
124 # Perform test again mimicking a second page request with:
125 # last_object_class = PipelineInstance
126 # and hence groups and jobs should not be included in the response
127 # offset = 5, which means first 5 pipeline instances were already received in page 1
128 # and hence the remaining pipeline instances and all other object types should be included in the response
130 @test_counter = 0 # Reset executed action counter
132 @controller = Arvados::V1::GroupsController.new
139 last_object_class: 'PipelineInstance',
140 filters: [['any', '@@', Rails.configuration.uuid_prefix]],
143 assert_response :success
145 second_page = Hash.new(0)
146 json_response['items'].map{|o| o['kind']}.each{|t| second_page[t] += 1}
148 assert_equal false, second_page.include?('arvados#group')
149 assert_equal false, second_page.include?('arvados#job')
150 assert_equal true, second_page['arvados#pipelineInstance']>0
151 assert_equal all_objects['arvados#pipelineInstance'], second_page['arvados#pipelineInstance']+5
152 assert_equal true, second_page['arvados#pipelineTemplate']>0