-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
113 lines (89 loc) · 3.63 KB
/
tests.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#coding=utf-8
import textveloper as tv
import unittest
import simplejson
from mock import patch
class AccountManagerTest(unittest.TestCase):
def setUp(self):
self.account_manager = tv.AccountManager('mytokentest')
@patch('textveloper.requests')
def test_consultar_puntos(self, mock_requests):
mocked_response = {
"transaccion":"exitosa",
"puntos_enviados":"100",
"total_puntos":"1000",
"puntos_disponibles":"900"
}
mock_requests.post.return_value.content = simplejson.dumps(mocked_response)
response = self.account_manager.consultar_puntos()
self.assertEquals(response, mocked_response)
def test_api_subcuenta(self):
response = self.account_manager.api_subcuenta('sub_token')
self.assertEquals(str(type(response)), '<class \'textveloper.API\'>')
class APITest(unittest.TestCase):
def setUp(self):
am = tv.AccountManager('token')
self.api = am.api_subcuenta('sub_token')
@patch('textveloper.requests')
def test_enviar_mensaje(self, mock_requests):
mocked_response = {'mensaje_transaccion': 'MENSAJE_ENVIADO', 'transaccion': 'exitosa'}
mock_requests.post.return_value.content = simplejson.dumps(mocked_response)
response = self.api.enviar_mensaje("04125559988", "Foo bar baz")
self.assertEquals(mocked_response, response)
@patch('textveloper.requests')
def test_consultar_puntos_app(self, mock_requests):
mocked_response = {
"transaccion":"exitosa",
"puntos_enviados":"100",
"total_puntos":"1000",
"puntos_disponibles":"900"
}
mock_requests.post.return_value.content = simplejson.dumps(mocked_response)
response = self.api.consultar_puntos()
self.assertEquals(mocked_response, response)
@patch('textveloper.requests')
def test_historial_transferencias(self, mock_requests):
mocked_response = {
'historico': [
{
'cantidad': '20',
'codigo_transaccion': '10',
'fecha': '2013-08-24 19:10:08'
},
{
'cantidad': '1',
'codigo_transaccion': '11',
'fecha': '2013-08-28 23:17:07'
}
],
'transaccion': 'exitosa'
}
mock_requests.post.return_value.content = simplejson.dumps(mocked_response)
response = self.api.historial_transferencias()
self.assertEquals(mocked_response, response)
@patch('textveloper.requests')
def test_historial_mensajes(self, mock_requests):
mocked_response = {
'historico': [
{
'codigo_log': '67',
'estatus': 'Enviado',
'fecha': '2013-08-24 19:16:51',
'mensaje': 'ola ke ase?',
'telefono': '04241017107'
},
{
'codigo_log': '68',
'estatus': 'Enviado',
'fecha': '2013-08-24 19:25:36',
'mensaje': 'Hola gente, es Israel',
'telefono': '04142454597'
}
],
'transaccion': 'exitosa'
}
mock_requests.post.return_value.content = simplejson.dumps(mocked_response)
response = self.api.historial_mensajes()
self.assertEquals(mocked_response, response)
if __name__ == '__main__':
unittest.main()