Merge pull request #8 from marekjm/devel
[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 # pod used by tests (has to be valid)
15 __pod__ = 'http://pod.orkz.net'
16 __username__ = 'testuser'
17 __passwd__ = 'testpassword'
18
19
20 class ClientTests(unittest.TestCase):
21 def testInitialization(self):
22 """This test checks initialization of Client() instance.
23 """
24 client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__)
25 self.assertEqual(__pod__, client.pod)
26 self.assertEqual(__username__, client._username)
27 self.assertEqual(__passwd__, client._password)
28 self.assertEqual(None, client._post_data)
29 self.assertEqual(client._token_regex, re.compile(r'content="(.*?)"\s+name="csrf-token'))
30 self.assertEqual(client._login_data['user[username]'], 'testuser')
31 self.assertEqual(client._login_data['user[password]'], 'testpassword')
32 self.assertEqual(client._login_data['authenticity_token'], client.get_token())
33
34 def testPreparationOfPostData(self):
35 """This test checks correctness of data set for posting.
36 """
37
38
39
40 if __name__ == '__main__':
41 __passwd__ = getpass.getpass(prompt='Password used for testing: ')
42 if __passwd__ == '': __passwd__ = 'testpassword'
43 unittest.main()