Small fixes in code and tests (added fancy test counter)
authorMarek Marecki <triviuss@gmail.com>
Thu, 2 May 2013 23:31:59 +0000 (01:31 +0200)
committerMarek Marecki <triviuss@gmail.com>
Thu, 2 May 2013 23:31:59 +0000 (01:31 +0200)
.gitignore
Makefile
diaspy/__init__.py
diaspy/client.py
diaspy/connection.py
tests.py

index a9a611764e736a76c18251bf78a1987e91af30a5..91de4f27f3039daf559816497183bea79a7e9fa0 100644 (file)
@@ -7,3 +7,4 @@ __pycache__/*
 .env
 
 testconf.py
+TEST_COUNT
index 91ab8cec56ed445a2cc6240e9e44afd4cc8e9aba..c0859273ca340e1039de3b24b408e13d8282e3e0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,3 +5,6 @@ style-check:
 
 test:
        python3 -m unittest --verbose --catch --failfast tests.py
+
+test-python2:
+       python3 -m unittest --verbose --catch --failfast tests.py
index e047ea54afd7020f5506e44d15fe1b66e0f9b7d3..c824fa50409ffe83491054ebd8952f66e0406e9c 100644 (file)
@@ -1,4 +1,10 @@
+import diaspy.models as models
+import diaspy.conversations as conversations
+import diaspy.streams as streams
+import diaspy.client as client
+"""
 from diaspy import client
 from diaspy import models
 from diaspy import conversations
 from diaspy import streams
+"""
index 09e376dc8c4b04715bbeddb27cfa569ff595b771..1a43689c15aca507f71998d379680ebf968c8210 100644 (file)
@@ -89,12 +89,12 @@ class Client:
         :returns: list -- list of Post objects
         """
         if stream:
+            tagged_posts = diaspy.streams.Generic(self.connection, location='tags/{0}.json'.format(tag))
+        else:
             r = self.connection.get('tags/{0}.json'.format(tag))
             if r.status_code != 200:
                 raise Exception('wrong status code: {0}'.format(r.status_code))
             tagged_posts = [diaspy.models.Post(str(post['id']), self.connection) for post in r.json()]
-        else:
-            tagged_posts = diaspy.streams.Generic(self.connection, location='tags/{0}.json'.format(tag))
         return tagged_posts
 
     def get_notifications(self):
index 2f0329e271288bd2e4f79ad239bf014be994947f..af978d674123027feeef9fb4e488fd7575699d64 100644 (file)
@@ -26,6 +26,7 @@ class Connection():
         self.session = requests.Session()
         self._token_regex = re.compile(r'content="(.*?)"\s+name="csrf-token')
         self._userinfo_regex = re.compile(r'window.current_user_attributes = ({.*})')
+        self.login_data = {}
         self._setlogin(username, password)
 
     def get(self, string):
index 83799246a3d40aa3c061fc8a2d055588a50125ac..549e6c3c0e8efd5696223a9c33c35c5f9d1e8d9b 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -10,49 +10,64 @@ import re
 import diaspy
 
 
+####    SETUP STUFF
 ####    test suite configuration variables: can be adjusted to your liking
 import testconf
 __pod__ = testconf.__pod__
 __username__ = testconf.__username__
 __passwd__ = testconf.__passwd__
 
-__connection__ = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__)
-__connection__.login()
 
+# Test counter
+try:
+    test_count_file = open('TEST_COUNT', 'r')
+    test_count = int(test_count_file.read())
+    test_count_file.close()
+except (IOError, ValueError):
+    test_count = 0
+finally:
+    test_count += 1
+test_count_file = open('TEST_COUNT', 'w')
+test_count_file.write(str(test_count))
+test_count_file.close()
+print('Running test no. {0}'.format(test_count))
 
+print('Running tests on connection to pod: "{0}"\n'.format(__pod__))
+test_connection = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__)
+test_connection.login()
+
+
+#### Test suite code
 class StreamTest(unittest.TestCase):
     def testGetting(self):
         c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__)
         c.login()
-        stream = diaspy.streams.Stream(c)
-        stream.update()
+        stream = diaspy.streams.Generic(c)
 
     def testGettingLength(self):
         c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__)
         c.login()
-        stream = diaspy.streams.Stream(c)
-        stream.update()
+        stream = diaspy.streams.Generic(c)
         len(stream)
 
     def testClearing(self):
-        stream = diaspy.streams.Stream(__connection__)
-        stream.update()
+        stream = diaspy.streams.Stream(test_connection)
         stream.clear()
         self.assertEqual(0, len(stream))
 
     def testPurging(self):
-        stream = diaspy.streams.Stream(__connection__)
+        stream = diaspy.streams.Stream(test_connection)
         post = stream.post('#diaspy test')
         stream.update()
         post.delete()
         stream.purge()
-        self.assertNotIn(post.post_id, [post.post_id for post in stream])
+        self.assertNotIn(post.post_id, [p.post_id for p in stream])
 
     def testPostingText(self):
         c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__)
         c.login()
         stream = diaspy.streams.Stream(c)
-        post = stream.post('#diaspy test')
+        post = stream.post('#diaspy test no. {0}'.format(test_count))
         self.assertEqual(diaspy.models.Post, type(post))
 
     def testPostingImage(self):
@@ -90,12 +105,18 @@ class ClientTests(unittest.TestCase):
         self.assertEqual(list, type(notifications))
         if notifications: self.assertEqual(dict, type(notifications[0]))
 
-    def testGettingTag(self):
+    def testGettingTagAsList(self):
         client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__)
         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(pod=__pod__, username=__username__, password=__passwd__)
+        tag = client.get_tag('foo', stream=True)
+        self.assertEqual(diaspy.streams.Generic, type(tag))
+        if tag: self.assertEqual(diaspy.models.Post, type(tag[0]))
+
     def testGettingMailbox(self):
         client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__)
         mailbox = client.get_mailbox()