5 # failure to import any of the modules below indicates failed tests
6 # =================================================================
7 # modules used by diaspy
16 #### test suite configuration variables: can be adjusted to your liking
18 __pod__
= testconf
.__pod
__
19 __username__
= testconf
.__username
__
20 __passwd__
= testconf
.__passwd
__
25 test_count_file
= open('TEST_COUNT', 'r')
26 test_count
= int(test_count_file
.read())
27 test_count_file
.close()
28 except (IOError, ValueError):
32 test_count_file
= open('TEST_COUNT', 'w')
33 test_count_file
.write(str(test_count
))
34 test_count_file
.close()
35 print('Running test no. {0}'.format(test_count
))
37 print('Running tests on connection to pod: "{0}"\t'.format(__pod__
), end
='')
38 test_connection
= diaspy
.connection
.Connection(pod
=__pod__
, username
=__username__
, password
=__passwd__
)
39 test_connection
.login()
40 print('[ CONNECTED ]\n')
42 post_text
= '#diaspy test no. {0}'.format(test_count
)
45 #######################################
46 #### TEST SUITE CODE ####
47 #######################################
48 class ConnectionTest(unittest
.TestCase
):
49 def testLoginWithoutUsername(self
):
50 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
51 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, password
='foo')
53 def testLoginWithoutPassword(self
):
54 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
55 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, username
='user')
57 def testGettingUserInfo(self
):
58 info
= test_connection
.getUserInfo()
59 self
.assertEqual(dict, type(info
))
62 class ClientTests(unittest
.TestCase
):
63 def testGettingStream(self
):
64 client
= diaspy
.client
.Client(test_connection
)
65 stream
= client
.get_stream()
66 if len(stream
): self
.assertEqual(diaspy
.models
.Post
, type(stream
[0]))
68 def testGettingNotifications(self
):
69 client
= diaspy
.client
.Client(test_connection
)
70 notifications
= client
.get_notifications()
71 self
.assertEqual(diaspy
.notifications
.Notifications
, type(notifications
))
72 if notifications
: self
.assertEqual(diaspy
.models
.Notification
, type(notifications
[0]))
74 def testGettingTag(self
):
75 client
= diaspy
.client
.Client(test_connection
)
76 tag
= client
.get_tag('foo')
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
.id, [p
.id for p
in stream
])
108 def testPostingText(self
):
109 stream
= diaspy
.streams
.Stream(test_connection
)
110 post
= stream
.post(post_text
)
111 self
.assertEqual(diaspy
.models
.Post
, type(post
))
113 @unittest.skip('returns internal server error -- not our fault that it is failing')
114 def testPostingImage(self
):
115 stream
= diaspy
.streams
.Stream(test_connection
)
116 stream
.post(text
=post_text
, photo
='test-image.png')
118 def testingAddingTag(self
):
119 ft
= diaspy
.streams
.FollowedTags(test_connection
)
122 def testAspectsAdd(self
):
123 aspects
= diaspy
.streams
.Aspects(test_connection
)
124 aspects
.add(testconf
.test_aspect_name_fake
)
125 testconf
.test_aspect_id
= aspects
.add(testconf
.test_aspect_name
).id
127 def testAspectsGettingID(self
):
128 aspects
= diaspy
.streams
.Aspects(test_connection
)
129 id = aspects
.getAspectID(testconf
.test_aspect_name
)
130 self
.assertEqual(testconf
.test_aspect_id
, id)
132 def testAspectsRemoveById(self
):
133 aspects
= diaspy
.streams
.Aspects(test_connection
)
134 aspects
.remove(testconf
.test_aspect_id
)
135 self
.assertEqual(-1, aspects
.getAspectID(testconf
.test_aspect_name
))
137 def testAspectsRemoveByName(self
):
138 aspects
= diaspy
.streams
.Aspects(test_connection
)
139 aspects
.remove(name
=testconf
.test_aspect_name_fake
)
140 self
.assertEqual(-1, aspects
.getAspectID(testconf
.test_aspect_name_fake
))
142 def testActivity(self
):
143 activity
= diaspy
.streams
.Activity(test_connection
)
145 def testMentionsStream(self
):
146 mentions
= diaspy
.streams
.Mentions(test_connection
)
149 class UserTests(unittest
.TestCase
):
150 def testHandleSeparatorRaisingExceptions(self
):
151 user
= diaspy
.people
.User(test_connection
)
152 handles
= ['user.pod.example.com',
153 'user@podexamplecom',
155 'use r@pod.example.com',
156 'user0@pod300 example.com',
159 self
.assertRaises(Exception, user
._sephandle
, h
)
161 def testGettingUserByHandle(self
):
162 user
= diaspy
.people
.User(test_connection
, handle
=testconf
.diaspora_id
)
164 self
.assertEqual(testconf
.guid
, user
['guid'])
165 self
.assertEqual(testconf
.diaspora_name
, user
['diaspora_name'])
166 self
.assertIn('id', user
.data
)
167 self
.assertIn('image_urls', user
.data
)
168 self
.assertEqual(type(user
.stream
), diaspy
.streams
.Outer
)
170 def testGettingUserByGUID(self
):
171 user
= diaspy
.people
.User(test_connection
, guid
=testconf
.guid
)
173 self
.assertEqual(testconf
.diaspora_id
, user
['diaspora_id'])
174 self
.assertEqual(testconf
.diaspora_name
, user
['diaspora_name'])
175 self
.assertIn('id', user
.data
)
176 self
.assertIn('image_urls', user
.data
)
177 self
.assertEqual(type(user
.stream
), diaspy
.streams
.Outer
)
180 class ContactsTest(unittest
.TestCase
):
181 def testGetOnlySharing(self
):
182 contacts
= diaspy
.people
.Contacts(test_connection
)
183 result
= contacts
.get(set='only_sharing')
185 self
.assertEqual(diaspy
.people
.User
, type(i
))
187 def testGetAll(self
):
188 contacts
= diaspy
.people
.Contacts(test_connection
)
189 result
= contacts
.get(set='all')
191 self
.assertEqual(diaspy
.people
.User
, type(i
))
194 contacts
= diaspy
.people
.Contacts(test_connection
)
195 result
= contacts
.get()
197 self
.assertEqual(diaspy
.people
.User
, type(i
))
200 class PostTests(unittest
.TestCase
):
201 def testStringConversion(self
):
202 s
= diaspy
.streams
.Stream(test_connection
)
205 s
= diaspy
.streams
.Stream(test_connection
)
208 class NotificationsTests(unittest
.TestCase
):
209 def testMarkgingRead(self
):
210 notifications
= diaspy
.notifications
.Notifications(test_connection
)
212 for n
in notifications
:
216 if notif
is not None:
219 warnings
.warn('test not sufficient: no unread notifications were found')
221 if __name__
== '__main__': unittest
.main()