From 2ec93347bcd13f819be6c100f4525450c9366f90 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Mon, 10 Jun 2013 17:00:44 +0200 Subject: [PATCH] Small style and code fixes --- diaspy/connection.py | 2 +- diaspy/notifications.py | 7 +++++-- diaspy/streams.py | 2 +- tests.py | 10 ++++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/diaspy/connection.py b/diaspy/connection.py index 43f8ce1..c2d185b 100644 --- a/diaspy/connection.py +++ b/diaspy/connection.py @@ -154,7 +154,7 @@ class Connection(): request = self.get('stream') token = self._token_regex.search(request.text).group(1) return token - + def get_token(self, new=False): """This function returns a token needed for authentication in most cases. Each time it is run a _fetchtoken() is called and refreshed token is stored. diff --git a/diaspy/notifications.py b/diaspy/notifications.py index 55b7035..418c939 100644 --- a/diaspy/notifications.py +++ b/diaspy/notifications.py @@ -2,6 +2,7 @@ import time + from diaspy.models import Notification @@ -19,6 +20,9 @@ class Notifications(): def __iter__(self): return iter(self._notifications) + def __getitem__(self, n): + return self._notifications[n] + def last(self): """Returns list of most recent notifications. """ @@ -31,7 +35,6 @@ class Notifications(): raise Exception('status code: {0}: cannot retreive notifications'.format(request.status_code)) return [Notification(self._connection, n) for n in request.json()] - def get(self, per_page=5, page=1): """Returns list of notifications. """ @@ -39,7 +42,7 @@ class Notifications(): headers = {'x-csrf-token': self._connection.get_token()} request = self._connection.get('notifications.json', headers=headers, params=params) - + if request.status_code != 200: raise Exception('status code: {0}: cannot retreive notifications'.format(request.status_code)) diff --git a/diaspy/streams.py b/diaspy/streams.py index f9c3231..7bbc70f 100644 --- a/diaspy/streams.py +++ b/diaspy/streams.py @@ -346,7 +346,7 @@ class FollowedTags(Generic): if request.status_code not in [201, 403]: raise Exception('wrong error code: {0}'.format(request.status_code)) return request.status_code - + class Tag(Generic): """This stream contains all posts containing a tag. diff --git a/tests.py b/tests.py index 6bf07d7..6527883 100644 --- a/tests.py +++ b/tests.py @@ -3,9 +3,11 @@ import unittest # failure to import any of the modules below indicates failed tests +# ================================================================= # modules used by diaspy -import requests import re +import requests +import warnings # actual diaspy code import diaspy @@ -66,8 +68,8 @@ class ClientTests(unittest.TestCase): def testGettingNotifications(self): client = diaspy.client.Client(test_connection) notifications = client.get_notifications() - self.assertEqual(list, type(notifications)) - if notifications: self.assertEqual(dict, type(notifications[0])) + 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) @@ -120,7 +122,7 @@ class StreamTest(unittest.TestCase): def testAspectsAdd(self): aspects = diaspy.streams.Aspects(test_connection) aspects.add(testconf.test_aspect_name_fake) - testconf.test_aspect_id = aspects.add(testconf.test_aspect_name) + testconf.test_aspect_id = aspects.add(testconf.test_aspect_name).id def testAspectsGettingID(self): aspects = diaspy.streams.Aspects(test_connection) -- 2.25.1