3 class Arvados::V1::FiltersTest < ActionController::TestCase
4 test '"not in" filter passes null values' do
5 @controller = Arvados::V1::GroupsController.new
8 filters: [ ['group_class', 'not in', ['project']] ],
11 assert_response :success
12 found = assigns(:objects)
13 assert_includes(found.collect(&:group_class), nil,
14 "'group_class not in ['project']' filter should pass null")
17 test 'error message for non-array element in filters array' do
18 @controller = Arvados::V1::CollectionsController.new
19 authorize_with :active
21 filters: [{bogus: 'filter'}],
24 assert_match(/Invalid element in filters array/,
25 json_response['errors'].join(' '))
28 test 'error message for full text search on a specific column' do
29 @controller = Arvados::V1::CollectionsController.new
30 authorize_with :active
32 filters: [['uuid', '@@', 'abcdef']],
35 assert_match /not supported/, json_response['errors'].join(' ')
38 test 'difficult characters in full text search' do
39 @controller = Arvados::V1::CollectionsController.new
40 authorize_with :active
42 filters: [['any', '@@', 'a|b"c']],
44 assert_response :success
45 # (Doesn't matter so much which results are returned.)
48 test 'array operand in full text search' do
49 @controller = Arvados::V1::CollectionsController.new
50 authorize_with :active
52 filters: [['any', '@@', ['abc', 'def']]],
55 assert_match /not supported/, json_response['errors'].join(' ')
58 test 'api responses provide timestamps with nanoseconds' do
59 @controller = Arvados::V1::CollectionsController.new
60 authorize_with :active
62 assert_response :success
63 assert_not_empty json_response['items']
64 json_response['items'].each do |item|
65 %w(created_at modified_at).each do |attr|
66 # Pass fixtures with null timestamps.
67 next if item[attr].nil?
68 assert_match /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d{9}Z$/, item[attr]
73 %w(< > <= >= =).each do |operator|
74 test "timestamp #{operator} filters work with nanosecond precision" do
75 # Python clients like Node Manager rely on this exact format.
76 # If you must change this format for some reason, make sure you
77 # coordinate the change with them.
78 expect_match = !!operator.index('=')
79 mine = act_as_user users(:active) do
80 Collection.create!(manifest_text: '')
82 timestamp = mine.modified_at.strftime('%Y-%m-%dT%H:%M:%S.%NZ')
83 @controller = Arvados::V1::CollectionsController.new
84 authorize_with :active
86 filters: [['modified_at', operator, timestamp],
87 ['uuid', '=', mine.uuid]],
89 assert_response :success
90 uuids = json_response['items'].map { |item| item['uuid'] }
92 assert_includes uuids, mine.uuid
94 assert_not_includes uuids, mine.uuid