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')
72 def testCreatingTag(self
):
73 ft
= diaspy
.streams
.FollowedTags(test_connection
)
77 class ConnectionTest(unittest
.TestCase
):
78 def testLoginWithoutUsername(self
):
79 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
80 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, password
='foo')
82 def testLoginWithoutPassword(self
):
83 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
84 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, username
='user')
86 def testGettingUserInfo(self
):
87 info
= test_connection
.getUserInfo()
88 self
.assertEqual(dict, type(info
))
91 class ClientTests(unittest
.TestCase
):
92 def testGettingStream(self
):
93 client
= diaspy
.client
.Client(test_connection
)
94 stream
= client
.get_stream()
95 if len(stream
): self
.assertEqual(diaspy
.models
.Post
, type(stream
[0]))
97 def testGettingNotifications(self
):
98 client
= diaspy
.client
.Client(test_connection
)
99 notifications
= client
.get_notifications()
100 self
.assertEqual(list, type(notifications
))
101 if notifications
: self
.assertEqual(dict, type(notifications
[0]))
103 def testGettingTagAsList(self
):
104 client
= diaspy
.client
.Client(test_connection
)
105 tag
= client
.get_tag('foo')
106 self
.assertEqual(list, type(tag
))
107 if tag
: self
.assertEqual(diaspy
.models
.Post
, type(tag
[0]))
109 def testGettingTagAsStream(self
):
110 client
= diaspy
.client
.Client(test_connection
)
111 tag
= client
.get_tag('foo', stream
=True)
112 self
.assertEqual(diaspy
.streams
.Generic
, type(tag
))
113 if tag
: self
.assertEqual(diaspy
.models
.Post
, type(tag
[0]))
115 def testGettingMailbox(self
):
116 client
= diaspy
.client
.Client(test_connection
)
117 mailbox
= client
.get_mailbox()
118 self
.assertEqual(list, type(mailbox
))
119 self
.assertEqual(diaspy
.conversations
.Conversation
, type(mailbox
[0]))
122 if __name__
== '__main__':
124 c
= diaspy
.connection
.Connection(__pod__
, __username__
, __passwd__
)
126 stream
= diaspy
.modules
.Stream(c
)
128 if post
['text'] == '#diaspy test': post
.delete()