From 0fcafddbd15a653ee56abd00fe9d49f5288b47e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 5 Sep 2018 14:54:08 +0200 Subject: [PATCH] Added unit test for creating comments We had an issue creating comments, so I wrote a test for it. The test succeeds on a new project, so the problem lies with the older projects. In the end it was the comment node type that still had `{'coerce': 'markdown'}`. --- ...test_comments_edit.py => test_comments.py} | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) rename tests/test_web/{test_comments_edit.py => test_comments.py} (57%) diff --git a/tests/test_web/test_comments_edit.py b/tests/test_web/test_comments.py similarity index 57% rename from tests/test_web/test_comments_edit.py rename to tests/test_web/test_comments.py index 2917c0a7..5d658518 100644 --- a/tests/test_web/test_comments_edit.py +++ b/tests/test_web/test_comments.py @@ -1,11 +1,51 @@ import json from bson import ObjectId +import flask from pillar.tests import AbstractPillarTest from pillar.tests import common_test_data as ctd +class CommentTest(AbstractPillarTest): + def setUp(self, **kwargs): + super().setUp(**kwargs) + + self.pid, self.project = self.ensure_project_exists() + self.owner_uid = self.create_user(24 * 'a', + groups=[ctd.EXAMPLE_ADMIN_GROUP_ID], + token='admin-token') + + # Create a node people can comment on. + self.node_id = self.create_node({ + '_id': ObjectId('572761099837730efe8e120d'), + 'description': 'This is an asset without file', + 'node_type': 'asset', + 'user': self.owner_uid, + 'properties': { + 'status': 'published', + 'content_type': 'image', + }, + 'name': 'Image test', + 'project': self.pid, + }) + + self.user_uid = self.create_user(24 * 'b', groups=[ctd.EXAMPLE_ADMIN_GROUP_ID], + token='user-token') + + def test_write_comment(self): + with self.login_as(self.user_uid): + comment_url = flask.url_for('nodes.comments_create') + self.post( + comment_url, + data={ + 'content': 'je möder lives at [home](https://cloud.blender.org/)', + 'parent_id': str(self.node_id), + }, + expected_status=201, + ) + + class CommentEditTest(AbstractPillarTest): def setUp(self, **kwargs): super().setUp(**kwargs)