Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Comments tests #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions pypodio2/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

72 changes: 72 additions & 0 deletions tests/test_areas_comment.py
Original file line number Diff line number Diff line change
@@ -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))