Comment rating: fixed bug where new ratings weren't returned on no-op.
This commit is contained in:
parent
7365fb10cd
commit
ed863447cf
@ -82,15 +82,15 @@ def patch_comment(node_id, patch):
|
|||||||
action = actions[patch['op']]
|
action = actions[patch['op']]
|
||||||
mongo_update = action()
|
mongo_update = action()
|
||||||
|
|
||||||
if not mongo_update:
|
if mongo_update:
|
||||||
return jsonify({'_status': 'OK', 'result': 'no-op'})
|
|
||||||
|
|
||||||
log.info('Running %s', mongo_update)
|
log.info('Running %s', mongo_update)
|
||||||
if rating:
|
if rating:
|
||||||
result = nodes_coll.update_one({'_id': node_id, 'properties.ratings.user': user_id},
|
result = nodes_coll.update_one({'_id': node_id, 'properties.ratings.user': user_id},
|
||||||
mongo_update)
|
mongo_update)
|
||||||
else:
|
else:
|
||||||
result = nodes_coll.update_one({'_id': node_id}, mongo_update)
|
result = nodes_coll.update_one({'_id': node_id}, mongo_update)
|
||||||
|
else:
|
||||||
|
result = 'no-op'
|
||||||
|
|
||||||
# Fetch the new ratings, so the client can show these without querying again.
|
# Fetch the new ratings, so the client can show these without querying again.
|
||||||
node = nodes_coll.find_one(node_id,
|
node = nodes_coll.find_one(node_id,
|
||||||
|
@ -36,9 +36,11 @@ class PatchCommentTest(AbstractPillarTest):
|
|||||||
|
|
||||||
def test_upvote_other_comment(self):
|
def test_upvote_other_comment(self):
|
||||||
# Patch the node
|
# Patch the node
|
||||||
self.patch(self.node_url,
|
res = self.patch(self.node_url,
|
||||||
json={'op': 'upvote'},
|
json={'op': 'upvote'},
|
||||||
auth_token='token')
|
auth_token='token').json()
|
||||||
|
self.assertEqual(1, res['properties']['rating_positive'])
|
||||||
|
self.assertEqual(0, res['properties']['rating_negative'])
|
||||||
|
|
||||||
# Get the node again, to inspect its changed state.
|
# Get the node again, to inspect its changed state.
|
||||||
patched_node = self.get(self.node_url, auth_token='token').json()
|
patched_node = self.get(self.node_url, auth_token='token').json()
|
||||||
@ -55,9 +57,11 @@ class PatchCommentTest(AbstractPillarTest):
|
|||||||
|
|
||||||
def test_downvote_other_comment(self):
|
def test_downvote_other_comment(self):
|
||||||
# Patch the node
|
# Patch the node
|
||||||
self.patch(self.node_url,
|
res = self.patch(self.node_url,
|
||||||
json={'op': 'downvote'},
|
json={'op': 'downvote'},
|
||||||
auth_token='token').json()
|
auth_token='token').json()
|
||||||
|
self.assertEqual(0, res['properties']['rating_positive'])
|
||||||
|
self.assertEqual(1, res['properties']['rating_negative'])
|
||||||
|
|
||||||
# Get the node again, to inspect its changed state.
|
# Get the node again, to inspect its changed state.
|
||||||
patched_node = self.get(self.node_url, auth_token='token').json()
|
patched_node = self.get(self.node_url, auth_token='token').json()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user