-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_tuenti.py
60 lines (51 loc) · 2.12 KB
/
test_tuenti.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
import os
import sys
import string
import unittest
import random
from tuenti import TuentiSocialMessenger
class TestTuentiSocialMessenger(unittest.TestCase):
def setUp(self):
unittest.TestCase.setUp(self)
self.user = os.environ.get('TUENTIUSER') or sys.argv[0]
password = os.environ.get('TUENTIPASSWORD') or sys.argv[1]
self.t = TuentiSocialMessenger.from_credentials(self.user, password)
def tearDown(self):
unittest.TestCase.tearDown(self)
self.tuenti_logout(self.t)
def tuenti_logout(self, tuenti_inst):
tuenti_inst.request('Auth_closeSession',
{'installationId': tuenti_inst.installation_id})
def test_token_auth(self):
auth_token, installation_id = self.t.get_auth_data()
tuenti_token = TuentiSocialMessenger.from_auth_token(
self.user, auth_token, installation_id)
session_data = tuenti_token.request(
'Auth_getSessionInfo', {'installationId': self.t.installation_id})
self.assertTrue('userId' in session_data)
self.tuenti_logout(tuenti_token)
def test_create_account(self):
t_empty = TuentiSocialMessenger()
generate_random = lambda: ''.join(
random.sample(string.ascii_lowercase, 8))
params = {
'email': '%[email protected]' % generate_random(),
'name': generate_random(),
'last': generate_random(),
'password': generate_random(),
'installationId': t_empty.installation_id,
'deviceFamily': 'MDI3MDFmZjU4MGExNWM0YmEyYjA5MzRkODlmMjg0MTU6'
'MC4yMjk5ODcwMCAxMzI0NDg5NjY0'
}
data = t_empty.request(
'Registration_createNewAccountWithPassword', params)
self.assertEqual(data['session']['newUser'], True)
self.tuenti_logout(t_empty)
def test_simple_request(self):
data = self.t.request('User_getRelationshipData')
self.assertEqual(
data.keys(),
[u'timestamp', u'contacts', u'weak', u'friends', u'blocked'])
if __name__ == '__main__':
unittest.main()