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')
40 post_text
= '#diaspy test no. {0}'.format(test_count
)
43 #######################################
44 #### TEST SUITE CODE ####
45 #######################################
46 class ConnectionTest(unittest
.TestCase
):
47 def testLoginWithoutUsername(self
):
48 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
49 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, password
='foo')
51 def testLoginWithoutPassword(self
):
52 connection
= diaspy
.connection
.Connection(pod
=__pod__
)
53 self
.assertRaises(diaspy
.connection
.LoginError
, connection
.login
, username
='user')
55 def testGettingUserInfo(self
):
56 info
= test_connection
.getUserInfo()
57 self
.assertEqual(dict, type(info
))
60 class ClientTests(unittest
.TestCase
):
61 def testGettingStream(self
):
62 client
= diaspy
.client
.Client(test_connection
)
63 stream
= client
.get_stream()
64 if len(stream
): self
.assertEqual(diaspy
.models
.Post
, type(stream
[0]))
66 def testGettingNotifications(self
):
67 client
= diaspy
.client
.Client(test_connection
)
68 notifications
= client
.get_notifications()
69 self
.assertEqual(list, type(notifications
))
70 if notifications
: self
.assertEqual(dict, type(notifications
[0]))
72 def testGettingTag(self
):
73 client
= diaspy
.client
.Client(test_connection
)
74 tag
= client
.get_tag('foo')
75 self
.assertEqual(diaspy
.streams
.Generic
, type(tag
))
76 if tag
: self
.assertEqual(diaspy
.models
.Post
, type(tag
[0]))
78 def testGettingMailbox(self
):
79 client
= diaspy
.client
.Client(test_connection
)
80 mailbox
= client
.get_mailbox()
81 self
.assertEqual(list, type(mailbox
))
82 self
.assertEqual(diaspy
.conversations
.Conversation
, type(mailbox
[0]))
85 class StreamTest(unittest
.TestCase
):
86 def testGetting(self
):
87 stream
= diaspy
.streams
.Generic(test_connection
)
89 def testGettingLength(self
):
90 stream
= diaspy
.streams
.Generic(test_connection
)
93 def testClearing(self
):
94 stream
= diaspy
.streams
.Stream(test_connection
)
96 self
.assertEqual(0, len(stream
))
98 def testPurging(self
):
99 stream
= diaspy
.streams
.Stream(test_connection
)
100 post
= stream
.post('#diaspy test')
104 self
.assertNotIn(post
.post_id
, [p
.post_id
for p
in stream
])
106 def testPostingText(self
):
107 stream
= diaspy
.streams
.Stream(test_connection
)
108 post
= stream
.post(post_text
)
109 self
.assertEqual(diaspy
.models
.Post
, type(post
))
111 @unittest.skip('returns internal server error -- not our fault that it is failing')
112 def testPostingImage(self
):
113 stream
= diaspy
.streams
.Stream(test_connection
)
114 stream
.post(text
=post_text
, photo
='test-image.png')
116 def testingAddingTag(self
):
117 ft
= diaspy
.streams
.FollowedTags(test_connection
)
120 def testAspectsAdd(self
):
121 aspects
= diaspy
.streams
.Aspects(test_connection
)
122 aspects
.add(testconf
.test_aspect_name_fake
)
123 testconf
.test_aspect_id
= aspects
.add(testconf
.test_aspect_name
)
125 def testAspectsGettingID(self
):
126 aspects
= diaspy
.streams
.Aspects(test_connection
)
127 id = aspects
.getAspectID(testconf
.test_aspect_name
)
128 self
.assertEqual(testconf
.test_aspect_id
, id)
130 def testAspectsRemoveById(self
):
131 aspects
= diaspy
.streams
.Aspects(test_connection
)
132 aspects
.remove(testconf
.test_aspect_id
)
133 self
.assertEqual(-1, aspects
.getAspectID(testconf
.test_aspect_name
))
135 def testAspectsRemoveByName(self
):
136 aspects
= diaspy
.streams
.Aspects(test_connection
)
137 aspects
.remove(name
=testconf
.test_aspect_name_fake
)
138 self
.assertEqual(-1, aspects
.getAspectID(testconf
.test_aspect_name_fake
))
140 def testActivity(self
):
141 activity
= diaspy
.streams
.Activity(test_connection
)
143 def testMentionsStream(self
):
144 mentions
= diaspy
.streams
.Mentions(test_connection
)
147 class UserTests(unittest
.TestCase
):
148 def testHandleSeparatorRaisingExceptions(self
):
149 user
= diaspy
.people
.User(test_connection
)
150 handles
= ['user.pod.example.com',
151 'user@podexamplecom',
153 'use r@pod.example.com',
154 'user0@pod300 example.com',
157 self
.assertRaises(Exception, user
._sephandle
, h
)
159 def testGettingUserByHandle(self
):
160 user
= diaspy
.people
.User(test_connection
)
161 user
.fetchhandle(testconf
.diaspora_id
)
162 self
.assertEqual(testconf
.guid
, user
['guid'])
163 self
.assertEqual(testconf
.diaspora_name
, user
['diaspora_name'])
164 self
.assertIn('id', user
.data
)
165 self
.assertIn('image_urls', user
.data
)
166 self
.assertEqual(type(user
.stream
), diaspy
.streams
.Outer
)
168 def testGettingUserByGUID(self
):
169 user
= diaspy
.people
.User(test_connection
)
170 user
.fetchguid(testconf
.guid
)
171 self
.assertEqual(testconf
.diaspora_id
, user
['diaspora_id'])
172 self
.assertEqual(testconf
.diaspora_name
, user
['diaspora_name'])
173 self
.assertIn('id', user
.data
)
174 self
.assertIn('image_urls', user
.data
)
175 self
.assertEqual(type(user
.stream
), diaspy
.streams
.Outer
)
178 class ContactsTest(unittest
.TestCase
):
179 def testGetOnlySharing(self
):
180 contacts
= diaspy
.people
.Contacts(test_connection
)
181 result
= contacts
.get(set='only_sharing')
183 self
.assertEqual(diaspy
.people
.User
, type(i
))
185 def testGetAll(self
):
186 contacts
= diaspy
.people
.Contacts(test_connection
)
187 result
= contacts
.get(set='all')
189 self
.assertEqual(diaspy
.people
.User
, type(i
))
192 contacts
= diaspy
.people
.Contacts(test_connection
)
193 result
= contacts
.get()
195 self
.assertEqual(diaspy
.people
.User
, type(i
))
198 class PostTests(unittest
.TestCase
):
199 def testStringConversion(self
):
200 s
= diaspy
.streams
.Stream(test_connection
)
203 s
= diaspy
.streams
.Stream(test_connection
)
206 if __name__
== '__main__': unittest
.main()