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:11 UTC
[allura] 19/50: [#7935] Added test for unicode characters
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 ecaa8d442b97ed8295733f0eb493981073ee9d02
Author: Fahri Korkmaz <f....@codesys.com>
AuthorDate: Wed Mar 4 13:02:10 2020 +0100
[#7935] Added test for unicode characters
---
.../forgeimporters/tests/forge/test_discussion.py | 107 +++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/ForgeImporters/forgeimporters/tests/forge/test_discussion.py b/ForgeImporters/forgeimporters/tests/forge/test_discussion.py
index 161f518..9526ffc 100644
--- a/ForgeImporters/forgeimporters/tests/forge/test_discussion.py
+++ b/ForgeImporters/forgeimporters/tests/forge/test_discussion.py
@@ -19,6 +19,8 @@ from unittest import TestCase
import mock
+from dateutil.parser import parse
+
from ming.odm import ThreadLocalORMSession
from allura import model as M
@@ -128,6 +130,111 @@ class TestDiscussionImporter(TestCase):
g.post_event.assert_called_once_with("project_updated")
+ @mock.patch.object(discussion, 'c')
+ @mock.patch.object(discussion, 'g')
+ @mock.patch.object(discussion, 'M')
+ @mock.patch.object(discussion, 'session')
+ @mock.patch.object(discussion, 'h')
+ @mock.patch.object(discussion, 'ThreadLocalORMSession')
+ def test_import_tool_unicode(self, tlos, h, session, m, g, c):
+ """ This method tests if the import tool method supports unicode characters """
+
+ importer = discussion.ForgeDiscussionImporter()
+
+ # Creating the json to test for
+ _json = {
+ "forums": [{
+ "shortname": "general",
+ "_id": "538f7240f697c62562ed9e6f",
+ "description": "Forum about anything you want to talk about.",
+ "name": "General Discussion",
+ "threads": [{
+ "limit": None,
+ "discussion_id": "538f7240f697c62562ed9e6f",
+ "_id": "88983164e3",
+ "posts": [
+ {
+ "attachments": [],
+ "author": "admin1",
+ "timestamp": "2020-01-29 22:32:00.584000",
+ "author_icon_url": "https://secure.gravatar.com/avatar/2ba5bfa33e6faca31f7dd150960ce926?r=pg&d=https%3A%2F%2F4.xb.sf.net%2Fnf%2F0%2F_ew_%2Ftheme%2Fsftheme%2Fimages%2Fsandiego%2Ficons%2Fdefault-avatar.png",
+ "text": "test with un\u00ef\u00e7\u00f8\u2202\u00e9 text",
+ "last_edited": None,
+ "slug": "0e0e",
+ "subject": "post with un\u00ef\u00e7\u00f8\u2202\u00e9"
+ }
+ ],
+ "page": None,
+ "subject": "post with un\u00ef\u00e7\u00f8\u2202\u00e9"
+ }]
+ }]
+ }
+
+ importer._load_json = mock.Mock(return_value=_json)
+
+ project, user = mock.Mock(), mock.Mock()
+ app = project.install_app.return_value
+ app.config.options.mount_point = 'mount_point'
+ app.config.options.import_id = { 'source': 'Allura' }
+ app.config.options.get = lambda *a: getattr(app.config.options, *a)
+ app.url = 'foo'
+ app.forums = []
+ utils.create_forum = mock.Mock()
+ forum = mock.Mock()
+ thread1 = mock.Mock()
+ p = mock.Mock()
+ thread1.add_post = mock.Mock(return_value=p)
+ forum.get_discussion_thread.return_value = (thread1, mock.Mock())
+ utils.create_forum.return_value = forum
+ g.post_event = mock.Mock()
+ m.AuditLog.log = mock.Mock()
+ admin = mock.Mock(is_anonymous=lambda: False)
+ admin._id = 1
+ importer.get_user = mock.Mock(return_value=admin)
+ importer.annotate_text = mock.Mock(return_value='aa')
+
+ importer.import_tool(project, user, mount_point='mount_point', mount_label='mount_label')
+
+ project.install_app.assert_called_once_with(
+ 'discussion', 'mount_point', 'mount_label',
+ import_id={ 'source': 'Allura' }
+ )
+
+ forum_json = _json["forums"][0]
+ new_forum = dict(
+ app_config_id = app.config._id,
+ shortname=forum_json['shortname'],
+ description=forum_json['description'],
+ name=forum_json['name'],
+ create='on',
+ parent='',
+ members_only=False,
+ anon_posts=False,
+ monitoring_email=None
+ )
+ utils.create_forum.assert_called_once_with(app, new_forum=new_forum)
+ forum.get_discussion_thread.assert_called_once_with(dict(headers=dict(Subject=_json["forums"][0]["threads"][0]["subject"])))
+
+ importer.get_user.assert_called_once_with('admin1')
+
+ self.assertEqual(h.push_config.call_args_list, [
+ mock.call(c, app=app),
+ mock.call(c, user=admin, app=app)
+ ])
+
+ post = _json["forums"][0]["threads"][0]["posts"][0]
+ thread1.add_post.assert_called_once_with(
+ subject=post["subject"],
+ text='aa',
+ timestamp=parse(post["timestamp"]),
+ ignore_security=True
+ )
+ importer.annotate_text.assert_called_once_with(post["text"], admin, post["author"])
+ p.add_multiple_attachments.assert_called_once_with([])
+
+ g.post_event.assert_called_once_with('project_updated')
+
+
def test_annotate_text_with_existing_user(self):
""" This test tests the annotate_text method if an existing user is passed as argument """