Further work being done on streams; all basic streams implemented
[diaspy.git] / tests.py
index 3030510a411ea054d334c306a955a1cd8a9cc475..83799246a3d40aa3c061fc8a2d055588a50125ac 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -16,18 +16,73 @@ __pod__ = testconf.__pod__
 __username__ = testconf.__username__
 __passwd__ = testconf.__passwd__
 
+__connection__ = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__)
+__connection__.login()
+
+
+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()
+
+    def testGettingLength(self):
+        c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__)
+        c.login()
+        stream = diaspy.streams.Stream(c)
+        stream.update()
+        len(stream)
+
+    def testClearing(self):
+        stream = diaspy.streams.Stream(__connection__)
+        stream.update()
+        stream.clear()
+        self.assertEqual(0, len(stream))
+
+    def testPurging(self):
+        stream = diaspy.streams.Stream(__connection__)
+        post = stream.post('#diaspy test')
+        stream.update()
+        post.delete()
+        stream.purge()
+        self.assertNotIn(post.post_id, [post.post_id for post 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')
+        self.assertEqual(diaspy.models.Post, type(post))
+
+    def testPostingImage(self):
+        c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__)
+        c.login()
+        stream = diaspy.streams.Stream(c)
+        stream.post_picture('./test-image.png')
+
+
+class ConnectionTest(unittest.TestCase):
+    def testLoginWithoutUsername(self):
+        connection = diaspy.connection.Connection(pod=__pod__)
+        self.assertRaises(diaspy.connection.LoginError, connection.login, password='foo')
+
+    def testLoginWithoutPassword(self):
+        connection = diaspy.connection.Connection(pod=__pod__)
+        self.assertRaises(diaspy.connection.LoginError, connection.login, username='user')
 
-class ClientTests(unittest.TestCase):
     def testGettingUserInfo(self):
-        client = diaspy.client.Client(__pod__, __username__, __passwd__)
-        info = client.get_user_info()
+        connection = diaspy.connection.Connection(__pod__, __username__, __passwd__)
+        connection.login()
+        info = connection.getUserInfo()
         self.assertEqual(dict, type(info))
 
+
+class ClientTests(unittest.TestCase):
     def testGettingStream(self):
         client = diaspy.client.Client(__pod__, __username__, __passwd__)
         stream = client.get_stream()
-        self.assertEqual(list, type(stream))
-        if stream: self.assertEqual(diaspy.models.Post, type(stream[0]))
+        if len(stream): self.assertEqual(diaspy.models.Post, type(stream[0]))
 
     def testGettingNotifications(self):
         client = diaspy.client.Client(__pod__, __username__, __passwd__)
@@ -47,4 +102,11 @@ class ClientTests(unittest.TestCase):
         self.assertEqual(list, type(mailbox))
         self.assertEqual(diaspy.conversations.Conversation, type(mailbox[0]))
 
-if __name__ == '__main__': unittest.main()
+
+if __name__ == '__main__':
+    unittest.main()
+    c = diaspy.connection.Connection(__pod__, __username__, __passwd__)
+    c.login()
+    stream = diaspy.modules.Stream(c)
+    for post in stream:
+        if post['text'] == '#diaspy test': post.delete()