12414: Add tests for projects (and their contents) deletion.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 2 Apr 2018 15:57:29 +0000 (12:57 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 2 Apr 2018 15:57:29 +0000 (12:57 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

services/api/lib/sweep_trashed_objects.rb
services/api/test/fixtures/groups.yml
services/api/test/fixtures/jobs.yml
services/api/test/unit/group_test.rb

index 1dc45a0ca14a6f8ff6205ae5dd21f6aff42734ac..c4db856f5195f144c003780380572950401e293f 100644 (file)
@@ -7,7 +7,7 @@ require 'current_api_client'
 module SweepTrashedObjects
   extend CurrentApiClient
 
-  def delete_project_and_contents(p_uuid)
+  def self.delete_project_and_contents(p_uuid)
     p = Group.find_by_uuid(p_uuid)
     if !p || p.group_class != 'project'
       raise "can't sweep group '#{p_uuid}', it may not exist or not be a project"
index 07d46d86495c6cec831d0d3428fbda0f2a111c22..68cc76949afc5b21e0f7586fb777944788a9f6cd 100644 (file)
@@ -305,7 +305,7 @@ trashed_project:
   name: trashed project
   group_class: project
   trash_at: 2001-01-01T00:00:00Z
-  delete_at: 2038-03-01T00:00:00Z
+  delete_at: 2008-03-01T00:00:00Z
   is_trashed: true
   modified_at: 2001-01-01T00:00:00Z
 
@@ -325,4 +325,14 @@ trashed_subproject3:
   trash_at: 2001-01-01T00:00:00Z
   delete_at: 2038-03-01T00:00:00Z
   is_trashed: true
+  modified_at: 2001-01-01T00:00:00Z
+
+trashed_on_next_sweep:
+  uuid: zzzzz-j7d0g-soontobetrashed
+  owner_uuid: zzzzz-j7d0g-xurymjxw79nv3jz
+  name: soon to be trashed project
+  group_class: project
+  trash_at: 2001-01-01T00:00:00Z
+  delete_at: 2038-03-01T00:00:00Z
+  is_trashed: false
   modified_at: 2001-01-01T00:00:00Z
\ No newline at end of file
index 7b1fb90b56100b5a0319d62db1178330b777424a..4b26edc83791eadfece909653187db9574d2efe9 100644 (file)
@@ -415,6 +415,17 @@ job_in_subproject:
   state: Complete
   script_parameters_digest: 99914b932bd37a50b983c5e7c90ae93b
 
+job_in_trashed_project:
+  uuid: zzzzz-8i9sb-subprojectjob02
+  created_at: 2014-10-15 12:00:00
+  owner_uuid: zzzzz-j7d0g-trashedproject1
+  log: ~
+  repository: active/foo
+  script: hash
+  script_version: 4fe459abe02d9b365932b8f5dc419439ab4e2577
+  state: Complete
+  script_parameters_digest: 99914b932bd37a50b983c5e7c90ae93b
+
 running_will_be_completed:
   uuid: zzzzz-8i9sb-rshmckwoma9pjh8
   owner_uuid: zzzzz-j7d0g-v955i6s2oi1cbso
index a5dc0ece840d9117c14f051ab583451d3f46fec0..892086b1994e7d5bd663c665023855c017c2fe02 100644 (file)
@@ -60,7 +60,7 @@ class GroupTest < ActiveSupport::TestCase
     assert g_foo.errors.messages[:owner_uuid].join(" ").match(/ownership cycle/)
   end
 
-  test "delete group hides contents" do
+  test "trash group hides contents" do
     set_user_from_auth :active_trustedclient
 
     g_foo = Group.create!(name: "foo")
@@ -74,7 +74,7 @@ class GroupTest < ActiveSupport::TestCase
     assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any?
   end
 
-  test "delete group" do
+  test "trash group" do
     set_user_from_auth :active_trustedclient
 
     g_foo = Group.create!(name: "foo")
@@ -95,7 +95,7 @@ class GroupTest < ActiveSupport::TestCase
   end
 
 
-  test "delete subgroup" do
+  test "trash subgroup" do
     set_user_from_auth :active_trustedclient
 
     g_foo = Group.create!(name: "foo")
@@ -115,7 +115,7 @@ class GroupTest < ActiveSupport::TestCase
     assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_baz.uuid).any?
   end
 
-  test "delete subsubgroup" do
+  test "trash subsubgroup" do
     set_user_from_auth :active_trustedclient
 
     g_foo = Group.create!(name: "foo")
@@ -133,7 +133,7 @@ class GroupTest < ActiveSupport::TestCase
   end
 
 
-  test "delete group propagates to subgroups" do
+  test "trash group propagates to subgroups" do
     set_user_from_auth :active_trustedclient
 
     g_foo = groups(:trashed_project)
@@ -158,7 +158,7 @@ class GroupTest < ActiveSupport::TestCase
     assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any?
     assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any?
 
-    # this one should still be deleted.
+    # this one should still be trashed.
     assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty?
 
     g_baz.update! is_trashed: false
@@ -189,4 +189,32 @@ class GroupTest < ActiveSupport::TestCase
     assert User.readable_by(users(:admin)).where(uuid:  u_bar.uuid).any?
   end
 
+  test "move projects to trash in SweepTrashedObjects" do
+    p = groups(:trashed_on_next_sweep)
+    assert_empty Group.where('uuid=? and is_trashed=true', p.uuid)
+    SweepTrashedObjects.sweep_now
+    assert_not_empty Group.where('uuid=? and is_trashed=true', p.uuid)
+  end
+
+  test "delete projects and their contents in SweepTrashedObjects" do
+    g_foo = groups(:trashed_project)
+    g_bar = groups(:trashed_subproject)
+    g_baz = groups(:trashed_subproject3)
+    col = collections(:collection_in_trashed_subproject)
+    job = jobs(:job_in_trashed_project)
+    cr = container_requests(:cr_in_trashed_project)
+    assert_not_empty Group.where(uuid: g_foo.uuid)
+    assert_not_empty Group.where(uuid: g_bar.uuid)
+    assert_not_empty Group.where(uuid: g_baz.uuid)
+    assert_not_empty Collection.where(uuid: col.uuid)
+    assert_not_empty Job.where(uuid: job.uuid)
+    assert_not_empty ContainerRequest.where(uuid: cr.uuid)
+    SweepTrashedObjects.sweep_now
+    assert_empty Group.where(uuid: g_foo.uuid)
+    assert_empty Group.where(uuid: g_bar.uuid)
+    assert_empty Group.where(uuid: g_baz.uuid)
+    assert_empty Collection.where(uuid: col.uuid)
+    assert_empty Job.where(uuid: job.uuid)
+    assert_empty ContainerRequest.where(uuid: cr.uuid)
+  end
 end