a37541374bf84a57a547e1c07841376a3e5d994c
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 ConnectionTest(unittest
.TestCase
):
43 def testLoginWithoutUsername(self
):
44 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
45 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, password
='foo')
47 def testLoginWithoutPassword(self
):
48 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
49 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, username
='user')
51 def testGettingUserInfo(self
):
52 info
= test_connection
.getUserInfo()
53 self
.assertEqual(dict, type(info
))
56 class ClientTests(unittest
.TestCase
):
57 def testGettingStream(self
):
58 client
= diaspy
.client
.Client(test_connection
)
59 stream
= client
.get_stream()
60 if len(stream
): self
.assertEqual(diaspy
.models
.Post
, type(stream
[0]))
62 def testGettingNotifications(self
):
63 client
= diaspy
.client
.Client(test_connection
)
64 notifications
= client
.get_notifications()
65 self
.assertEqual(list, type(notifications
))
66 if notifications
: self
.assertEqual(dict, type(notifications
[0]))
68 def testGettingTagAsList(self
):
69 client
= diaspy
.client
.Client(test_connection
)
70 tag
= client
.get_tag('foo')
71 self
.assertEqual(list, type(tag
))
72 if tag
: self
.assertEqual(diaspy
.models
.Post
, type(tag
[0]))
74 def testGettingTagAsStream(self
):
75 client
= diaspy
.client
.Client(test_connection
)
76 tag
= client
.get_tag('foo', stream
=True)
77 self
.assertEqual(diaspy
.streams
.Generic
, type(tag
))
78 if tag
: self
.assertEqual(diaspy
.models
.Post
, type(tag
[0]))
80 def testGettingMailbox(self
):
81 client
= diaspy
.client
.Client(test_connection
)
82 mailbox
= client
.get_mailbox()
83 self
.assertEqual(list, type(mailbox
))
84 self
.assertEqual(diaspy
.conversations
.Conversation
, type(mailbox
[0]))
87 class StreamTest(unittest
.TestCase
):
88 def testGetting(self
):
89 stream
= diaspy
.streams
.Generic(test_connection
)
91 def testGettingLength(self
):
92 stream
= diaspy
.streams
.Generic(test_connection
)
95 def testClearing(self
):
96 stream
= diaspy
.streams
.Stream(test_connection
)
98 self
.assertEqual(0, len(stream
))
100 def testPurging(self
):
101 stream
= diaspy
.streams
.Stream(test_connection
)
102 post
= stream
.post('#diaspy test')
106 self
.assertNotIn(post
.post_id
, [p
.post_id
for p
in stream
])
108 def testPostingText(self
):
109 stream
= diaspy
.streams
.Stream(test_connection
)
110 post
= stream
.post('#diaspy test no. {0}'.format(test_count
))
111 self
.assertEqual(diaspy
.models
.Post
, type(post
))
113 def testPostingImage(self
):
114 stream
= diaspy
.streams
.Stream(test_connection
)
115 stream
.post_picture('./test-image.png')
117 def testingAddingTag(self
):
118 ft
= diaspy
.streams
.FollowedTags(test_connection
)
122 class UserTests(unittest
.TestCase
):
123 def testHandleSeparatorRaisingExceptions(self
):
124 user
= diaspy
.people
.User(test_connection
)
125 handles
= ['user.pod.example.com',
126 'user@podexamplecom',
128 'use r@pod.example.com',
129 'user0@pod300 example.com',
132 self
.assertRaises(Exception, user
._sephandle
, h
)
134 def testGettingUserByHandle(self
):
135 user
= diaspy
.people
.User(test_connection
)
136 user
.fetchhandle(testconf
.diaspora_id
)
137 self
.assertEqual(testconf
.guid
, user
['guid'])
138 self
.assertEqual(testconf
.name
, user
['name'])
139 self
.assertIn('id', user
.data
)
140 self
.assertIn('avatar', user
.data
)
141 self
.assertEqual(type(user
.stream
), diaspy
.streams
.Outer
)
143 def testGettingUserByGUID(self
):
144 user
= diaspy
.people
.User(test_connection
)
145 user
.fetchguid(testconf
.guid
)
146 self
.assertEqual(testconf
.diaspora_id
, user
['diaspora_id'])
147 self
.assertEqual(testconf
.name
, user
['name'])
148 self
.assertIn('id', user
.data
)
149 self
.assertIn('avatar', user
.data
)
150 self
.assertEqual(type(user
.stream
), diaspy
.streams
.Outer
)
153 if __name__
== '__main__':
155 c
= diaspy
.connection
.Connection(__pod__
, __username__
, __passwd__
)
157 stream
= diaspy
.modules
.Stream(c
)
159 if post
['text'] == '#diaspy test': post
.delete()