Small style and code fixes
authorMarek Marecki <triviuss@gmail.com>
Mon, 10 Jun 2013 15:00:44 +0000 (17:00 +0200)
committerMarek Marecki <triviuss@gmail.com>
Mon, 10 Jun 2013 15:00:44 +0000 (17:00 +0200)
diaspy/connection.py
diaspy/notifications.py
diaspy/streams.py
tests.py

index 43f8ce19f2c26631a4a7bff3654c5bfbdca80cd3..c2d185b0f344fbd3d1abd0b25fd8a4263ff48bd6 100644 (file)
@@ -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.
index 55b7035f104ba97f37da73f958333274db5e0fd8..418c93944800c13eb913ffd073bd73c75ee50d3d 100644 (file)
@@ -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))
 
index f9c323164459270995222a364c189c98fea55516..7bbc70f231d81c2994e5f33945e30dfa1bf6f996 100644 (file)
@@ -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.
index 6bf07d78d53546fbf3020074fba526d70c076082..652788399a28b51d2c90786ba152f969231c1477 100644 (file)
--- 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)