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}"\n'.format(__pod__
))
36 test_connection
= diaspy
.connection
.Connection(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
37 test_connection
.login()
41 class StreamTest(unittest
.TestCase
):
42 def testGetting(self
):
43 c
= diaspy
.connection
.Connection(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
45 stream
= diaspy
.streams
.Generic(c
)
47 def testGettingLength(self
):
48 c
= diaspy
.connection
.Connection(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
50 stream
= diaspy
.streams
.Generic(c
)
53 def testClearing(self
):
54 stream
= diaspy
.streams
.Stream(test_connection
)
56 self
.assertEqual(0, len(stream
))
58 def testPurging(self
):
59 stream
= diaspy
.streams
.Stream(test_connection
)
60 post
= stream
.post('#diaspy test')
64 self
.assertNotIn(post
.post_id
, [p
.post_id
for p
in stream
])
66 def testPostingText(self
):
67 c
= diaspy
.connection
.Connection(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
69 stream
= diaspy
.streams
.Stream(c
)
70 post
= stream
.post('#diaspy test no. {0}'.format(test_count
))
71 self
.assertEqual(diaspy
.models
.Post
, type(post
))
73 def testPostingImage(self
):
74 c
= diaspy
.connection
.Connection(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
76 stream
= diaspy
.streams
.Stream(c
)
77 stream
.post_picture('./test-image.png')
80 class ConnectionTest(unittest
.TestCase
):
81 def testLoginWithoutUsername(self
):
82 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
83 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, password
='foo')
85 def testLoginWithoutPassword(self
):
86 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
87 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, username
='user')
89 def testGettingUserInfo(self
):
90 connection
= diaspy
.connection
.Connection(__pod__
, __username__
, __passwd__
)
92 info
= connection
.getUserInfo()
93 self
.assertEqual(dict, type(info
))
96 class ClientTests(unittest
.TestCase
):
97 def testGettingStream(self
):
98 client
= diaspy
.client
.Client(__pod__
, __username__
, __passwd__
)
99 stream
= client
.get_stream()
100 if len(stream
): self
.assertEqual(diaspy
.models
.Post
, type(stream
[0]))
102 def testGettingNotifications(self
):
103 client
= diaspy
.client
.Client(__pod__
, __username__
, __passwd__
)
104 notifications
= client
.get_notifications()
105 self
.assertEqual(list, type(notifications
))
106 if notifications
: self
.assertEqual(dict, type(notifications
[0]))
108 def testGettingTagAsList(self
):
109 client
= diaspy
.client
.Client(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
110 tag
= client
.get_tag('foo')
111 self
.assertEqual(list, type(tag
))
112 if tag
: self
.assertEqual(diaspy
.models
.Post
, type(tag
[0]))
114 def testGettingTagAsStream(self
):
115 client
= diaspy
.client
.Client(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
116 tag
= client
.get_tag('foo', stream
=True)
117 self
.assertEqual(diaspy
.streams
.Generic
, type(tag
))
118 if tag
: self
.assertEqual(diaspy
.models
.Post
, type(tag
[0]))
120 def testGettingMailbox(self
):
121 client
= diaspy
.client
.Client(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
122 mailbox
= client
.get_mailbox()
123 self
.assertEqual(list, type(mailbox
))
124 self
.assertEqual(diaspy
.conversations
.Conversation
, type(mailbox
[0]))
127 if __name__
== '__main__':
129 c
= diaspy
.connection
.Connection(__pod__
, __username__
, __passwd__
)
131 stream
= diaspy
.modules
.Stream(c
)
133 if post
['text'] == '#diaspy test': post
.delete()