This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 20019590aacda3fb98d2468abd4c3e94a1481f6a
Author: Dillon Walls <[email protected]>
AuthorDate: Fri Jul 21 03:35:14 2023 +0000

    [#8516] Comprehensive tests around deleting discussions
---
 Allura/allura/tests/model/test_artifact.py   |   1 -
 Allura/allura/tests/model/test_discussion.py | 110 +++++++++++++++++++++++++--
 2 files changed, 104 insertions(+), 7 deletions(-)

diff --git a/Allura/allura/tests/model/test_artifact.py 
b/Allura/allura/tests/model/test_artifact.py
index ce5fdd4e7..d62c01cd5 100644
--- a/Allura/allura/tests/model/test_artifact.py
+++ b/Allura/allura/tests/model/test_artifact.py
@@ -127,7 +127,6 @@ class TestArtifact:
         assert not M.Shortlink.lookup('[Wiki:TestPage2]')
         assert not M.Shortlink.lookup('[TestPage2_no_such_page]')
 
-        pg.delete()
         c.project.uninstall_app('wiki')
         assert not M.Shortlink.lookup('[wiki:TestPage2]')
         assert q_shortlink.count() == 0
diff --git a/Allura/allura/tests/model/test_discussion.py 
b/Allura/allura/tests/model/test_discussion.py
index f50f2af79..5cb6b764c 100644
--- a/Allura/allura/tests/model/test_discussion.py
+++ b/Allura/allura/tests/model/test_discussion.py
@@ -489,16 +489,114 @@ class TestDiscussion:
         p1.spam()
         assert t.num_replies == 1
 
-    def test_deleted_thread_index(self):
+    def test_delete_discussion(self):
         d = M.Discussion(shortname='test', name='test')
-        t = M.Thread(discussion_id=d._id, subject='Test Thread')
-        p = M.Post(discussion_id=d._id, thread_id=t._id, status='ok')
+        t = M.Thread.new(discussion_id=d._id, subject='Test Thread')
+        p = t.post('This is a post')  # type: M.Post
+        d.attach('discussion.txt', BytesIO(b'Hello, discussion!'),
+                 discussion_id=d._id)
+        t.attach('thread.txt', BytesIO(b'Hello, thread!'),
+                 discussion_id=d._id,
+                 thread_id=t._id)
+        p.attach('post.txt', BytesIO(b'Hello, world!'),
+                 discussion_id=d._id,
+                 thread_id=t._id,
+                 post_id=p._id)
+        ThreadLocalODMSession.flush_all()
+
+        assert M.BaseAttachment.query.get(filename='discussion.txt')
+        assert M.BaseAttachment.query.get(filename='thread.txt')
+        assert M.BaseAttachment.query.get(filename='post.txt')
+
+        d.delete()
+
+        ThreadLocalODMSession.flush_all()
+        ThreadLocalODMSession.close_all()
+
+        # discussion is higher in hierarchy than thread, so should still exist
+        d = M.Discussion.query.get(_id=d._id)
+
+        assert not d
+        # post 'belongs to' thread, so should be deleted
+        t = M.Thread.query.get(_id=t._id)
+        assert not t
+        p = M.Post.query.get(_id=p._id)
+        assert not p
+
+        assert not M.BaseAttachment.query.get(filename='discussion.txt')
+        assert not M.BaseAttachment.query.get(filename='thread.txt')
+        assert not M.BaseAttachment.query.get(filename='post.txt')
+
+    def test_delete_thread(self):
+        d = M.Discussion(shortname='test', name='test')
+        t = M.Thread.new(discussion_id=d._id, subject='Test Thread')
+        p = t.post('This is a post')  # type: M.Post
+        d.attach('discussion.txt', BytesIO(b'Hello, discussion!'),
+                 discussion_id=d._id)
+        t.attach('thread.txt', BytesIO(b'Hello, thread!'),
+                 discussion_id=d._id,
+                 thread_id=t._id)
+        p.attach('post.txt', BytesIO(b'Hello, world!'),
+                 discussion_id=d._id,
+                 thread_id=t._id,
+                 post_id=p._id)
+        ThreadLocalODMSession.flush_all()
+
+        assert M.BaseAttachment.query.get(filename='discussion.txt')
+        assert M.BaseAttachment.query.get(filename='thread.txt')
+        assert M.BaseAttachment.query.get(filename='post.txt')
+
         t.delete()
         ThreadLocalODMSession.flush_all()
+        ThreadLocalODMSession.close_all()
+
+        # discussion is higher in hierarchy than thread, so should still exist
+        d = M.Discussion.query.get(_id=d._id)
+        assert d
+
+        # post 'belongs to' thread, so should be deleted
+        t = M.Thread.query.get(_id=t._id)
+        assert not t
+        p = M.Post.query.get(_id=p._id)
+        assert not p
+
+        assert M.BaseAttachment.query.get(filename='discussion.txt')
+        assert not M.BaseAttachment.query.get(filename='thread.txt')
+        assert not M.BaseAttachment.query.get(filename='post.txt')
+
+    def test_delete_post(self):
+        d = M.Discussion(shortname='test', name='test')
+        t = M.Thread.new(discussion_id=d._id, subject='Test Thread')
+        p = t.post('This is a post')  # type: M.Post
+        d.attach('discussion.txt', BytesIO(b'Hello, discussion!'),
+                 discussion_id=d._id)
+        t.attach('thread.txt', BytesIO(b'Hello, thread!'),
+                 discussion_id=d._id,
+                 thread_id=t._id)
+        p.attach('post.txt', BytesIO(b'Hello, world!'),
+                 discussion_id=d._id,
+                 thread_id=t._id,
+                 post_id=p._id)
+        ThreadLocalODMSession.flush_all()
 
-        # re-query, so relationships get reloaded
+        assert M.BaseAttachment.query.get(filename='discussion.txt')
+        assert M.BaseAttachment.query.get(filename='thread.txt')
+        assert M.BaseAttachment.query.get(filename='post.txt')
+
+        p.delete()
+
+        ThreadLocalODMSession.flush_all()
         ThreadLocalODMSession.close_all()
+
+        # discussion is higher in hierarchy than thread, so should still exist
+        d = M.Discussion.query.get(_id=d._id)
+        assert d
+        # post 'belongs to' thread, so should be deleted
+        t = M.Thread.query.get(_id=t._id)
+        assert t
         p = M.Post.query.get(_id=p._id)
+        assert not p
 
-        # just make sure this doesn't fail
-        p.index()
+        assert M.BaseAttachment.query.get(filename='discussion.txt')
+        assert M.BaseAttachment.query.get(filename='thread.txt')
+        assert not M.BaseAttachment.query.get(filename='post.txt')
\ No newline at end of file

Reply via email to