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 2018/11/08 21:53:47 UTC

[06/10] allura git commit: [#8253] Add unit cases for reaction endpoint

[#8253] Add unit cases for reaction endpoint


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/de72730c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/de72730c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/de72730c

Branch: refs/heads/master
Commit: de72730c21558c1c4d75a244cbe296391b766cd4
Parents: 7181877
Author: Shalitha Suranga <sh...@gmail.com>
Authored: Wed Oct 31 14:25:04 2018 +0530
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Nov 8 21:53:25 2018 +0000

----------------------------------------------------------------------
 Allura/allura/tests/functional/test_discuss.py | 63 +++++++++++++++++++++
 1 file changed, 63 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/de72730c/Allura/allura/tests/functional/test_discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_discuss.py b/Allura/allura/tests/functional/test_discuss.py
index 74a490c..5539710 100644
--- a/Allura/allura/tests/functional/test_discuss.py
+++ b/Allura/allura/tests/functional/test_discuss.py
@@ -216,6 +216,69 @@ class TestDiscuss(TestDiscussBase):
             extra_environ=dict(username='*anonymous'))
         assert response.json['status'] == 'no_permission'
 
+    def test_comment_post_reaction_new(self):
+        r = self._make_post('This is a post')
+        post_id = str(
+            r.html.find('div', {'class': 'discussion-post'})['id'])
+        react_link = str(self._thread_link() + post_id + '/post_reaction')
+        response = self.app.post(
+            react_link,
+            params={
+                'r': 'heart'})
+        assert response.json['status'] == 'ok' and response.json['react_heart'] == 1
+        response = self.app.post(
+            react_link,
+            params={
+                'r': 'invalid'})
+        assert response.json['status'] == 'error' and response.json['react_heart'] == 1
+        # anon users can't react comments
+        response = self.app.post(
+            react_link,
+            params={
+                'r': 'heart'},
+            extra_environ=dict(username='*anonymous'))
+        assert response.json['error'] == 'no_permission'
+        # even anon can't send invalid reactions
+        response = self.app.post(
+            react_link,
+            params={
+                'r': 'invalid'},
+            extra_environ=dict(username='*anonymous'))
+        assert response.json['error'] == 'no_permission'
+
+    def test_comment_post_reaction_change(self):
+        r = self._make_post('This is a post')
+        post_id = str(
+            r.html.find('div', {'class': 'discussion-post'})['id'])
+        react_link = str(self._thread_link() + post_id + '/post_reaction')
+        response = self.app.post(
+            react_link,
+            params={
+                'r': 'thumbs_down'})
+        assert response.json['status'] == 'ok' and response.json['react_thumbs_down'] == 1
+        response = self.app.post(
+            react_link,
+            params={
+                'r': 'thumbs_up'})
+        assert response.json['status'] == 'ok' and response.json['react_thumbs_up'] == 1
+        assert response.json['status'] == 'ok' and response.json['react_thumbs_down'] == 0
+
+    def test_comment_post_reaction_undo(self):
+        r = self._make_post('This is a post')
+        post_id = str(
+            r.html.find('div', {'class': 'discussion-post'})['id'])
+        react_link = str(self._thread_link() + post_id + '/post_reaction')
+        response = self.app.post(
+            react_link,
+            params={
+                'r': 'hooray'})
+        assert response.json['status'] == 'ok' and response.json['react_hooray'] == 1
+        response = self.app.post(
+            react_link,
+            params={
+                'r': 'hooray'})
+        assert response.json['status'] == 'ok' and response.json['react_hooray'] == 0
+
     def test_user_filter(self):
         r = self._make_post('Test post')
         post_link = str(