self._connection = connection
self.post_id = post_id
+ def __str__(self):
+ """Returns text of a post.
+ """
+ return self.get_data['text']
+
def get_data(self):
"""This function retrieves data of the post.
"""
post = Post(str(request.json()['id']), self._connection)
return post
- def post_picture(self, filename):
- """This method posts a picture to D*.
+ def _photoupload(self, filename):
+ """Uploads picture to the pod.
- :param filename: Path to picture file.
+ :param filename: path to picture file
:type filename: str
+
+ :returns: id of the photo being uploaded
"""
data = open(filename, 'rb')
image = data.read()
request = self._connection.post('photos', data=image, params=params, headers=headers)
if request.status_code != 200:
- raise Exception('wrong error code: {0}'.format())
- return request
+ raise Exception('wrong error code: {0}'.format(request.status_code))
+ return request.json()['data']['photo']['id']
+
+ def _photopost(self, id, text, aspect_ids):
+ """Posts a photo after it has been uploaded.
+ """
+ post = self.post(text=text, aspect_ids=aspect_ids, photos=id)
+ return post
+
+ def post_picture(self, filename, text='', aspect_ids='public'):
+ """This method posts a picture to D*.
+
+ :param filename: path to picture file
+ :type filename: str
+
+ :returns: Post object
+ """
+ id = self._photoupload(filename)
+ return self._photopost(id, text, aspect_ids)
class Activity(Generic):
test_connection.login()
print('[ CONNECTED ]\n')
+post_text = '#diaspy test no. {0}'.format(test_count)
+
#### Test suite code
class StreamTest(unittest.TestCase):
def testPostingText(self):
stream = diaspy.streams.Stream(test_connection)
- post = stream.post('#diaspy test no. {0}'.format(test_count))
+ post = stream.post(post_text)
self.assertEqual(diaspy.models.Post, type(post))
def testPostingImage(self):
stream = diaspy.streams.Stream(test_connection)
- stream.post_picture('./test-image.png')
+ stream.post_picture('./test-image.png', post_text)
def testingAddingTag(self):
ft = diaspy.streams.FollowedTags(test_connection)
self.assertEqual(list, type(notifications))
if notifications: self.assertEqual(dict, type(notifications[0]))
- def testGettingTagAsList(self):
+ def testGettingTag(self):
client = diaspy.client.Client(test_connection)
tag = client.get_tag('foo')
- self.assertEqual(list, type(tag))
- if tag: self.assertEqual(diaspy.models.Post, type(tag[0]))
-
- def testGettingTagAsStream(self):
- client = diaspy.client.Client(test_connection)
- tag = client.get_tag('foo', stream=True)
self.assertEqual(diaspy.streams.Generic, type(tag))
if tag: self.assertEqual(diaspy.models.Post, type(tag[0]))