Compare commits

...

1 Commits

Author SHA1 Message Date
d0e12401c0 Introduce support for confidence calculations 2018-11-26 23:44:16 +01:00
2 changed files with 16 additions and 0 deletions

View File

@ -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']

View File

@ -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()