548592550b8a911eda2a303ad9b9fd7c90c283d5
5 # failure to import any of the modules below indicates failed tests
6 # modules used by diaspy
14 #### test suite configuration variables: can be adjusted to your liking
16 __pod__
= testconf
.__pod
__
17 __username__
= testconf
.__username
__
18 __passwd__
= testconf
.__passwd
__
23 test_count_file
= open('TEST_COUNT', 'r')
24 test_count
= int(test_count_file
.read())
25 test_count_file
.close()
26 except (IOError, ValueError):
30 test_count_file
= open('TEST_COUNT', 'w')
31 test_count_file
.write(str(test_count
))
32 test_count_file
.close()
33 print('Running test no. {0}'.format(test_count
))
35 print('Running tests on connection to pod: "{0}"\t'.format(__pod__
), end
='')
36 test_connection
= diaspy
.connection
.Connection(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
37 test_connection
.login()
38 print('[ CONNECTED ]\n')
42 class StreamTest(unittest
.TestCase
):
43 def testGetting(self
):
44 stream
= diaspy
.streams
.Generic(test_connection
)
46 def testGettingLength(self
):
47 stream
= diaspy
.streams
.Generic(test_connection
)
50 def testClearing(self
):
51 stream
= diaspy
.streams
.Stream(test_connection
)
53 self
.assertEqual(0, len(stream
))
55 def testPurging(self
):
56 stream
= diaspy
.streams
.Stream(test_connection
)
57 post
= stream
.post('#diaspy test')
61 self
.assertNotIn(post
.post_id
, [p
.post_id
for p
in stream
])
63 def testPostingText(self
):
64 stream
= diaspy
.streams
.Stream(test_connection
)
65 post
= stream
.post('#diaspy test no. {0}'.format(test_count
))
66 self
.assertEqual(diaspy
.models
.Post
, type(post
))
68 def testPostingImage(self
):
69 stream
= diaspy
.streams
.Stream(test_connection
)
70 stream
.post_picture('./test-image.png')
73 class ConnectionTest(unittest
.TestCase
):
74 def testLoginWithoutUsername(self
):
75 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
76 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, password
='foo')
78 def testLoginWithoutPassword(self
):
79 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
80 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, username
='user')
82 def testGettingUserInfo(self
):
83 info
= test_connection
.getUserInfo()
84 self
.assertEqual(dict, type(info
))
87 class ClientTests(unittest
.TestCase
):
88 def testGettingStream(self
):
89 client
= diaspy
.client
.Client(test_connection
)
90 stream
= client
.get_stream()
91 if len(stream
): self
.assertEqual(diaspy
.models
.Post
, type(stream
[0]))
93 def testGettingNotifications(self
):
94 client
= diaspy
.client
.Client(test_connection
)
95 notifications
= client
.get_notifications()
96 self
.assertEqual(list, type(notifications
))
97 if notifications
: self
.assertEqual(dict, type(notifications
[0]))
99 def testGettingTagAsList(self
):
100 client
= diaspy
.client
.Client(test_connection
)
101 tag
= client
.get_tag('foo')
102 self
.assertEqual(list, type(tag
))
103 if tag
: self
.assertEqual(diaspy
.models
.Post
, type(tag
[0]))
105 def testGettingTagAsStream(self
):
106 client
= diaspy
.client
.Client(test_connection
)
107 tag
= client
.get_tag('foo', stream
=True)
108 self
.assertEqual(diaspy
.streams
.Generic
, type(tag
))
109 if tag
: self
.assertEqual(diaspy
.models
.Post
, type(tag
[0]))
111 def testGettingMailbox(self
):
112 client
= diaspy
.client
.Client(test_connection
)
113 mailbox
= client
.get_mailbox()
114 self
.assertEqual(list, type(mailbox
))
115 self
.assertEqual(diaspy
.conversations
.Conversation
, type(mailbox
[0]))
118 if __name__
== '__main__':
120 c
= diaspy
.connection
.Connection(__pod__
, __username__
, __passwd__
)
122 stream
= diaspy
.modules
.Stream(c
)
124 if post
['text'] == '#diaspy test': post
.delete()