You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/04/13 17:43:18 UTC

[allura] 26/50: [#7935] Created tests for add_posts with last_edited key

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 a69ddf2abfc0249da4bcf4e149e9282560f8eec6
Author: Fahri Korkmaz <f....@codesys.com>
AuthorDate: Wed Mar 4 18:05:10 2020 +0100

    [#7935] Created tests for add_posts with last_edited key
---
 .../forgeimporters/tests/forge/test_discussion.py  | 84 ++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/ForgeImporters/forgeimporters/tests/forge/test_discussion.py b/ForgeImporters/forgeimporters/tests/forge/test_discussion.py
index 5a73f72..feb9dfc 100644
--- a/ForgeImporters/forgeimporters/tests/forge/test_discussion.py
+++ b/ForgeImporters/forgeimporters/tests/forge/test_discussion.py
@@ -803,6 +803,90 @@ class TestDiscussionImporter(TestCase):
         post.add_multiple_attachments.assert_called_once_with([])
         
 
+    @mock.patch.object(discussion, 'c')
+    @mock.patch.object(discussion, 'h')
+    def test_add_posts_with_last_edited(self, h, c):
+        """ This method tests if the last edited attribute of a post is correctly updated if specified """
+
+        # Test with legit timestamp
+        importer, app, thread, user, post = self.__init_add_posts_tests()
+
+        _json = [
+            {
+                "attachments": [],
+                "author": "admin1",
+                "timestamp": "2020-01-29 22:30:42.497000",
+                "text": "test",
+                "subject": "post with last edited",
+                "last_edited": "2020-01-29 22:47:52.951000"
+            }
+        ]
+
+        importer.add_posts(thread, _json, app)
+
+        self.assertEqual(post.last_edit_date, parse(_json[0]['last_edited']))
+
+
+        # Test with none
+        importer, app, thread, user, post = self.__init_add_posts_tests()
+
+        _json = [
+            {
+                "attachments": [],
+                "author": "admin1",
+                "timestamp": "2020-01-29 22:30:42.497000",
+                "text": "test",
+                "subject": "post with last edited",
+                "last_edited": None
+            }
+        ]
+
+        post.last_edit_date = '-'
+        importer.add_posts(thread, _json, app)
+
+        self.assertEqual(post.last_edit_date, '-')
+
+       
+        # Test with no last edited 
+        importer, app, thread, user, post = self.__init_add_posts_tests()
+
+        _json = [
+            {
+                "attachments": [],
+                "author": "admin1",
+                "timestamp": "2020-01-29 22:30:42.497000",
+                "text": "test",
+                "subject": "post with last edited",
+            }
+        ]
+
+        post.last_edit_date = '-'
+        importer.add_posts(thread, _json, app)
+
+        self.assertEqual(post.last_edit_date, '-')
+
+        
+        # Test with junk last edited 
+        importer, app, thread, user, post = self.__init_add_posts_tests()
+
+        _json = [
+            {
+                "attachments": [],
+                "author": "admin1",
+                "timestamp": "2020-01-29 22:30:42.497000",
+                "text": "test",
+                "subject": "post with last edited",
+                "last_edited": "asdf asd"
+            }
+        ]
+
+        try:
+            importer.add_posts(thread, _json, app)
+            self.fail("add_posts() didn't throw exception even last_edited was junk data")
+        except:
+            pass
+
+
     def __init_add_posts_tests(self):
         importer = discussion.ForgeDiscussionImporter()