Commit | Line | Data |
---|---|---|
94c2d637 MM |
1 | #!/usr/bin/env python3 |
2 | ||
3 | import unittest | |
4 | ||
313c9233 | 5 | # failure to import any of the modules below indicates failed tests |
94c2d637 | 6 | # modules used by diaspy |
88ec6cda MM |
7 | import requests |
8 | import re | |
94c2d637 MM |
9 | # actual diaspy code |
10 | import diaspy | |
11 | ||
12 | ||
13 | #### test suite configuration variables: can be adjusted to your liking | |
fab8b736 MM |
14 | import testconf |
15 | __pod__ = testconf.__pod__ | |
16 | __username__ = testconf.__username__ | |
17 | __passwd__ = testconf.__passwd__ | |
94c2d637 MM |
18 | |
19 | ||
7a31b4aa MM |
20 | class StreamTest(unittest.TestCase): |
21 | def testGetting(self): | |
22 | c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) | |
23 | c.login() | |
24 | stream = diaspy.models.Stream(c) | |
25 | stream.update() | |
26 | ||
27 | def testGettingLength(self): | |
28 | c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) | |
29 | c.login() | |
30 | stream = diaspy.models.Stream(c) | |
31 | stream.update() | |
32 | len(stream) | |
33 | ||
34 | def testClearing(self): | |
35 | c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) | |
36 | c.login() | |
37 | stream = diaspy.models.Stream(c) | |
38 | stream.update() | |
39 | stream.clear() | |
40 | self.assertEqual(0, len(stream)) | |
41 | ||
42 | def testPostingText(self): | |
43 | c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) | |
44 | c.login() | |
45 | stream = diaspy.models.Stream(c) | |
f2eaa3c7 | 46 | post = stream.post('#diaspy test') |
7a31b4aa MM |
47 | self.assertEqual(diaspy.models.Post, type(post)) |
48 | ||
49 | def testPostingImage(self): | |
50 | c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) | |
51 | c.login() | |
52 | stream = diaspy.models.Stream(c) | |
53 | stream.post_picture('./test-image.png') | |
54 | ||
55 | ||
385e7ebe MM |
56 | class ConnectionTest(unittest.TestCase): |
57 | def testLoginWithoutUsername(self): | |
58 | connection = diaspy.connection.Connection(pod=__pod__) | |
59 | self.assertRaises(diaspy.connection.LoginError, connection.login, password='foo') | |
60 | ||
61 | def testLoginWithoutPassword(self): | |
62 | connection = diaspy.connection.Connection(pod=__pod__) | |
63 | self.assertRaises(diaspy.connection.LoginError, connection.login, username='user') | |
64 | ||
264336e2 | 65 | def testGettingUserInfo(self): |
7a31b4aa MM |
66 | connection = diaspy.connection.Connection(__pod__, __username__, __passwd__) |
67 | connection.login() | |
68 | info = connection.getUserInfo() | |
264336e2 MM |
69 | self.assertEqual(dict, type(info)) |
70 | ||
7a31b4aa MM |
71 | |
72 | class ClientTests(unittest.TestCase): | |
264336e2 MM |
73 | def testGettingStream(self): |
74 | client = diaspy.client.Client(__pod__, __username__, __passwd__) | |
75 | stream = client.get_stream() | |
7a31b4aa | 76 | if len(stream): self.assertEqual(diaspy.models.Post, type(stream[0])) |
264336e2 MM |
77 | |
78 | def testGettingNotifications(self): | |
79 | client = diaspy.client.Client(__pod__, __username__, __passwd__) | |
80 | notifications = client.get_notifications() | |
81 | self.assertEqual(list, type(notifications)) | |
82 | if notifications: self.assertEqual(dict, type(notifications[0])) | |
83 | ||
fab8b736 MM |
84 | def testGettingTag(self): |
85 | client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__) | |
86 | tag = client.get_tag('foo') | |
87 | self.assertEqual(list, type(tag)) | |
88 | if tag: self.assertEqual(diaspy.models.Post, type(tag[0])) | |
89 | ||
90 | def testGettingMailbox(self): | |
91 | client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__) | |
92 | mailbox = client.get_mailbox() | |
93 | self.assertEqual(list, type(mailbox)) | |
94 | self.assertEqual(diaspy.conversations.Conversation, type(mailbox[0])) | |
95 | ||
f2eaa3c7 | 96 | |
1232dac5 MM |
97 | if __name__ == '__main__': |
98 | unittest.main() | |
99 | c = diaspy.connection.Connection(__pod__, __username__, __passwd__) | |
100 | c.login() | |
101 | stream = diaspy.modules.Stream(c) | |
102 | for post in stream: | |
103 | if post['text'] == '#diaspy test': post.delete() |