Two tests added
[diaspy.git] / tests.py
1 #!/usr/bin/env python3
2
3 import unittest
4 import getpass
5
6 # failure to import any of the modules below indicates failed tests
7 # modules used by diaspy
8 import requests, re
9 # actual diaspy code
10 import diaspy
11
12
13 #### test suite configuration variables: can be adjusted to your liking
14 import testconf
15 __pod__ = testconf.__pod__
16 __username__ = testconf.__username__
17 __passwd__ = testconf.__passwd__
18
19
20 class ClientTests(unittest.TestCase):
21 def testInitialization(self):
22 client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__)
23 self.assertEqual(__pod__, client.pod)
24 self.assertEqual(__username__, client._username)
25 self.assertEqual(__passwd__, client._password)
26 self.assertEqual({}, client._post_data)
27 self.assertEqual(client._token_regex, re.compile(r'content="(.*?)"\s+name="csrf-token'))
28 self.assertEqual(client._login_data['user[username]'], __username__)
29 self.assertEqual(client._login_data['user[password]'], __passwd__)
30 self.assertEqual(client._login_data['authenticity_token'], client.get_token())
31
32 def testGettingTag(self):
33 client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__)
34 tag = client.get_tag('foo')
35 self.assertEqual(list, type(tag))
36 if tag: self.assertEqual(diaspy.models.Post, type(tag[0]))
37
38 def testGettingMailbox(self):
39 client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__)
40 mailbox = client.get_mailbox()
41 self.assertEqual(list, type(mailbox))
42 self.assertEqual(diaspy.conversations.Conversation, type(mailbox[0]))
43
44 if __name__ == '__main__': unittest.main()