From 3311aa0c5c14b588b7c07e7dfd9f725ba783de0a Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Tue, 20 Aug 2013 14:03:29 +0200 Subject: [PATCH] people.User._fetchguid() will now raise an exception when GUID is empty --- .gitignore | 2 ++ diaspy/people.py | 7 +++++-- tests.py | 16 +++------------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index dd5cdc1..12d09bc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,10 @@ __pycache__/* check-*.py +# Testing testconf.py TEST_COUNT +sketch.py *.py[cod] diff --git a/diaspy/people.py b/diaspy/people.py index 1ea8eca..c86067d 100644 --- a/diaspy/people.py +++ b/diaspy/people.py @@ -105,8 +105,11 @@ class User(): def fetchguid(self): """Fetch user data and posts using guid. """ - request = self._connection.get('people/{0}.json'.format(self.guid)) - self._postproc(request) + if self.guid: + request = self._connection.get('people/{0}.json'.format(self.guid)) + self._postproc(request) + else: + raise errors.UserError('GUID not set') def fetchprofile(self): """Fetches user data. diff --git a/tests.py b/tests.py index 57fac86..5e0adfa 100644 --- a/tests.py +++ b/tests.py @@ -10,6 +10,7 @@ import requests import warnings # actual diaspy code import diaspy +from diaspy import client as dclient #### SETUP STUFF @@ -60,25 +61,14 @@ class ConnectionTest(unittest.TestCase): class ClientTests(unittest.TestCase): - def testGettingStream(self): - client = diaspy.client.Client(test_connection) - stream = client.get_stream() - if len(stream): self.assertEqual(diaspy.models.Post, type(stream[0])) - - def testGettingNotifications(self): - client = diaspy.client.Client(test_connection) - notifications = client.get_notifications() - self.assertEqual(diaspy.notifications.Notifications, type(notifications)) - if notifications: self.assertEqual(diaspy.models.Notification, type(notifications[0])) - def testGettingTag(self): - client = diaspy.client.Client(test_connection) + client = dclient.Client(test_connection) tag = client.get_tag('foo') self.assertEqual(diaspy.streams.Generic, type(tag)) if tag: self.assertEqual(diaspy.models.Post, type(tag[0])) def testGettingMailbox(self): - client = diaspy.client.Client(test_connection) + client = dclient.Client(test_connection) mailbox = client.get_mailbox() self.assertEqual(list, type(mailbox)) self.assertEqual(diaspy.conversations.Conversation, type(mailbox[0])) -- 2.25.1