1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class DatabaseResetTest < ActionDispatch::IntegrationTest
8 slow_test "reset fails when Rails.env != 'test'" do
9 rails_env_was = Rails.env
11 Rails.env = 'production'
12 Rails.application.reload_routes!
13 post '/database/reset', {}, auth(:admin)
16 Rails.env = rails_env_was
17 Rails.application.reload_routes!
21 test "reset fails with non-admin token" do
22 post '/database/reset', {}, auth(:active)
26 slow_test "database reset doesn't break basic CRUD operations" do
27 active_auth = auth(:active)
28 admin_auth = auth(:admin)
31 post '/database/reset', {}, admin_auth
32 assert_response :success
34 post '/arvados/v1/specimens', {specimen: '{}'}, active_auth
35 assert_response :success
36 new_uuid = json_response['uuid']
38 get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
39 assert_response :success
41 put('/arvados/v1/specimens/'+new_uuid,
42 {specimen: '{"properties":{}}'}, active_auth)
43 assert_response :success
45 delete '/arvados/v1/specimens/'+new_uuid, {}, active_auth
46 assert_response :success
48 get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
52 slow_test "roll back database change" do
53 active_auth = auth(:active)
54 admin_auth = auth(:admin)
56 old_uuid = specimens(:owned_by_active_user).uuid
58 post '/database/reset', {}, admin_auth
59 assert_response :success
61 delete '/arvados/v1/specimens/' + old_uuid, {}, active_auth
62 assert_response :success
63 post '/arvados/v1/specimens', {specimen: '{}'}, active_auth
64 assert_response :success
65 new_uuid = json_response['uuid']
68 post '/database/reset', {}, admin_auth
69 assert_response :success
71 # New specimen should disappear. Old specimen should reappear.
72 get '/arvados/v1/specimens/'+new_uuid, {}, active_auth
74 get '/arvados/v1/specimens/'+old_uuid, {}, active_auth
75 assert_response :success