From 1451907a02140a74cc16cb7ad495d7410d287bc0 Mon Sep 17 00:00:00 2001 From: Rolando Evaristo Date: Mon, 6 Nov 2017 08:58:47 +0800 Subject: [PATCH 1/3] Area updated. Adds Comment object. Added the following methods: Comment.create() Comment.update() Comment.find_all() Comment.revisions() Comment.find() Comment.delete() --- pypodio2/areas.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/pypodio2/areas.py b/pypodio2/areas.py index cfd60f0..d0473b6 100644 --- a/pypodio2/areas.py +++ b/pypodio2/areas.py @@ -613,3 +613,78 @@ def update_view(self, view_id, attributes): return self.transport.PUT(url='/view/{}'.format(view_id), body=attribute_data, type='application/json') + +class Comment(Area): + + def create(self, ref_type, ref_id, attributes): + """ + Post a comment on specified app item + + :param ref_type: Object Reference type + :param ref_id: Object Reference ID + :param attributes: the body of the request as a dictionary + :return: Details of comment + :rtype: dict + """ + if type(attributes) != dict: + raise TypeError('Must be of type dict') + attributes = json.dumps(attributes) + return self.transport.POST(url='/comment/{}/{}/'.format(ref_type, ref_id), + body=attributes, type='application/json') + + + def update(self, comment_id, attributes, silent=False, hook=True): + """ + Edit or update a comment + + :param comment_id: Comment ID to edit + :param attributes: the body of the request as a dictionary + """ + if not isinstance(attributes, dict): + raise TypeError('Must be of type dict') + attributes = json.dumps(attributes) + return self.transport.PUT(body=attributes, + type='application/json', + url='/comment/%d%s' % (comment_id, self.get_options(silent=silent, + hook=hook))) + + def find_all(self, ref_type, ref_id): + """ + Find all of the comments of an object reference + + :param ref_type: Object reference type + :param ref_id: Object Reference ID + :return: Details of comments + :rtype: dict + """ + return self.transport.GET(url='/comment/{}/{}'.format(ref_type, ref_id)) + + def revisions(self, comment_id): + """ + Returns revisions of given comment + + :param comment_id: Comment ID + :return: Details of comments revisions + :rtype: dict + """ + return self.transport.GET(url='/comment/{}/revision'.format(comment_id)) + + + def find(self, comment_id): + """ + Find single comment details + + :param comment_id: Comment ID + :return: Details of comment + :rtype: dict + """ + return self.transport.GET(url='/comment//{}'.format(comment_id)) + + def delete(self, comment_id): + """ + Remove comment from reference + + :param comment_id: Comment ID + """ + return self.transport.DELETE(url='/comment/{}'.format(comment_id)) + From 1ac684401924efe3bd68b3f70954de2ff84cca87 Mon Sep 17 00:00:00 2001 From: Rolando Evaristo Date: Mon, 6 Nov 2017 09:23:57 +0800 Subject: [PATCH 2/3] remove double slash on transport URL of Comment.find() method --- pypodio2/areas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypodio2/areas.py b/pypodio2/areas.py index d0473b6..0221e38 100644 --- a/pypodio2/areas.py +++ b/pypodio2/areas.py @@ -678,7 +678,7 @@ def find(self, comment_id): :return: Details of comment :rtype: dict """ - return self.transport.GET(url='/comment//{}'.format(comment_id)) + return self.transport.GET(url='/comment/{}'.format(comment_id)) def delete(self, comment_id): """ From adb6603c4b7cf6d8c24a27b059dbeb4177701741 Mon Sep 17 00:00:00 2001 From: Rolando Evaristo Date: Mon, 6 Nov 2017 09:36:30 +0800 Subject: [PATCH 3/3] added comment tests --- tests/test_areas_comment.py | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/test_areas_comment.py diff --git a/tests/test_areas_comment.py b/tests/test_areas_comment.py new file mode 100644 index 0000000..3c33521 --- /dev/null +++ b/tests/test_areas_comment.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +""" +Unit tests for pypodio2.areas.Comment (via pypodio2.client.Client). Works +by mocking httplib2, and making assertions about how pypodio2 calls +it. +""" + +import json + +from tests.utils import check_client_method + + +def test_create(): + item_id = 12345 + ref_type = "item" + attributes = {"values":"test value"} + + client, check_assertions = check_client_method() + result = client.Comment.create(ref_type,item_id,attributes) + check_assertions(result, 'POST', '/comment/{}/{}/'.format(ref_type,item_id), + json.dumps(attributes), + {'content-type': 'application/json'}) + +def test_update(): + + comment_id= 1231231 + attributes= {"value" : "New updated value"} + + client, check_assertions = check_client_method() + result = client.Comment.update(comment_id, attributes) + check_assertions(result, + 'PUT', + '/comment/%d' % comment_id, + json.dumps(attributes), + {'content-type': 'application/json'}) + + client, check_assertions = check_client_method() + result = client.Comment.update(comment_id, attributes, silent=True) + check_assertions(result, + 'PUT', + '/comment/%s?silent=true' % comment_id, + json.dumps(attributes), + {'content-type': 'application/json'}) + +def test_find(): + comment_id = 67423 + + client, check_assertions = check_client_method() + result = client.Comment.find(comment_id) + check_assertions(result, 'GET', '/comment/{}'.format(comment_id)) + +def test_find_all(): + item_id = 67423 + ref_type = "item" + + client, check_assertions = check_client_method() + result = client.Comment.find_all(ref_type,item_id) + check_assertions(result, 'GET', '/comment/{}/{}'.format(ref_type, item_id)) + +def test_revisions(): + comment_id = 67423 + + client, check_assertions = check_client_method() + result = client.Comment.revisions(comment_id) + check_assertions(result, 'GET', '/comment/{}/revision'.format(comment_id)) + +def test_delete(): + comment_id = 67423 + + client, check_assertions = check_client_method() + result = client.Comment.delete(comment_id) + check_assertions(result, 'DELETE', '/comment/{}'.format(comment_id)) \ No newline at end of file