From d0e12401c001d41271d6c4bef7e68b39e9960cfe Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Mon, 26 Nov 2018 23:44:16 +0100 Subject: [PATCH] Introduce support for confidence calculations --- pillar/api/nodes/custom/comment.py | 8 ++++++++ tests/test_api/{test_patch.py => test_nodes_comments.py} | 8 ++++++++ 2 files changed, 16 insertions(+) rename tests/test_api/{test_patch.py => test_nodes_comments.py} (98%) diff --git a/pillar/api/nodes/custom/comment.py b/pillar/api/nodes/custom/comment.py index 44bf9fe5..a83c05ed 100644 --- a/pillar/api/nodes/custom/comment.py +++ b/pillar/api/nodes/custom/comment.py @@ -6,6 +6,7 @@ from flask import current_app import werkzeug.exceptions as wz_exceptions from pillar.api.utils import authorization, authentication, jsonify +from pillar.api.utils.rating import confidence from . import register_patch_handler @@ -25,6 +26,13 @@ def patch_comment(node_id, patch): assert patch['op'] == 'edit', 'Invalid patch operation %s' % patch['op'] result, node = edit_comment(user_id, node_id, patch) + # Calculate and update confidence. + rating_confidence = confidence( + node['properties']['rating_positive'], node['properties']['rating_negative']) + current_app.data.driver.db['nodes'].update_one( + {'_id': node_id}, + {'$set': {'properties.confidence': rating_confidence}}) + return jsonify({'_status': 'OK', 'result': result, 'properties': node['properties'] diff --git a/tests/test_api/test_patch.py b/tests/test_api/test_nodes_comments.py similarity index 98% rename from tests/test_api/test_patch.py rename to tests/test_api/test_nodes_comments.py index bd3a3eae..da0cc3f8 100644 --- a/tests/test_api/test_patch.py +++ b/tests/test_api/test_nodes_comments.py @@ -179,6 +179,14 @@ class VoteCommentTest(AbstractPatchCommentTest): ], patched_node['properties'].get('ratings', [])) +class CommentsSortingTest(AbstractPatchCommentTest): + def default_sorting(self): + pass + + def sorting_with_confidence(self): + pass + + class EditCommentTest(AbstractPatchCommentTest): def test_comment_edit_happy(self, token='owner-token'): pre_node = self.get(self.node_url, auth_token=token).get_json()