Removed unnecessary data obtaining from `get_*` methods
[diaspy.git] / tests.py
CommitLineData
94c2d637
MM
1#!/usr/bin/env python3
2
3import unittest
313c9233 4import getpass
94c2d637 5
313c9233 6# failure to import any of the modules below indicates failed tests
94c2d637
MM
7# modules used by diaspy
8import requests, re
9# actual diaspy code
10import diaspy
11
12
13#### test suite configuration variables: can be adjusted to your liking
fab8b736
MM
14import testconf
15__pod__ = testconf.__pod__
16__username__ = testconf.__username__
17__passwd__ = testconf.__passwd__
94c2d637
MM
18
19
20class ClientTests(unittest.TestCase):
313c9233 21 def testInitialization(self):
313c9233 22 client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__)
94c2d637 23 self.assertEqual(__pod__, client.pod)
313c9233
MM
24 self.assertEqual(__username__, client._username)
25 self.assertEqual(__passwd__, client._password)
fab8b736 26 self.assertEqual({}, client._post_data)
94c2d637 27 self.assertEqual(client._token_regex, re.compile(r'content="(.*?)"\s+name="csrf-token'))
fab8b736
MM
28 self.assertEqual(client._login_data['user[username]'], __username__)
29 self.assertEqual(client._login_data['user[password]'], __passwd__)
94c2d637
MM
30 self.assertEqual(client._login_data['authenticity_token'], client.get_token())
31
264336e2
MM
32 def testGettingUserInfo(self):
33 client = diaspy.client.Client(__pod__, __username__, __passwd__)
34 info = client.get_user_info()
35 self.assertEqual(dict, type(info))
36
37 def testGettingStream(self):
38 client = diaspy.client.Client(__pod__, __username__, __passwd__)
39 stream = client.get_stream()
40 self.assertEqual(list, type(stream))
41 if stream: self.assertEqual(diaspy.models.Post, type(stream[0]))
42
43 def testGettingNotifications(self):
44 client = diaspy.client.Client(__pod__, __username__, __passwd__)
45 notifications = client.get_notifications()
46 self.assertEqual(list, type(notifications))
47 if notifications: self.assertEqual(dict, type(notifications[0]))
48
fab8b736
MM
49 def testGettingTag(self):
50 client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__)
51 tag = client.get_tag('foo')
52 self.assertEqual(list, type(tag))
53 if tag: self.assertEqual(diaspy.models.Post, type(tag[0]))
54
55 def testGettingMailbox(self):
56 client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__)
57 mailbox = client.get_mailbox()
58 self.assertEqual(list, type(mailbox))
59 self.assertEqual(diaspy.conversations.Conversation, type(mailbox[0]))
60
61if __name__ == '__main__': unittest.main()