forked from twilio/twilio-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_core.py
91 lines (72 loc) · 2.53 KB
/
test_core.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
import six
if six.PY3:
import unittest
else:
import unittest2 as unittest
from datetime import datetime
from datetime import date
from twilio.rest.resources import parse_date
from twilio.rest.resources import transform_params
from twilio.rest.resources import convert_keys
from twilio.rest.resources import convert_case
from twilio.rest.resources import convert_boolean
from twilio.rest.resources import normalize_dates
class CoreTest(unittest.TestCase):
def test_date(self):
d = date(2009,10,10)
self.assertEquals(parse_date(d), "2009-10-10")
def test_datetime(self):
d = datetime(2009,10,10)
self.assertEquals(parse_date(d), "2009-10-10")
def test_string_date(self):
d = "2009-10-10"
self.assertEquals(parse_date(d), "2009-10-10")
def test_string_date(self):
d = None
self.assertEquals(parse_date(d), None)
def test_string_date(self):
d = False
self.assertEquals(parse_date(d), None)
def test_fparam(self):
d = {"HEY": None, "YOU": 3}
ed = {"YOU":3}
self.assertEquals(transform_params(d), ed)
def test_fparam_booleans(self):
d = {"HEY": None, "YOU": 3, "Activated": False}
ed = {"YOU":3, "Activated": "false"}
self.assertEquals(transform_params(d), ed)
def test_normalize_dates(self):
@normalize_dates
def foo(on=None, before=None, after=None):
return {
"on": on,
"before": before,
"after": after,
}
d = foo(on="2009-10-10", before=date(2009,10,10),
after=datetime(2009,10,10))
self.assertEquals(d["on"], "2009-10-10")
self.assertEquals(d["after"], "2009-10-10")
self.assertEquals(d["before"], "2009-10-10")
def test_convert_case(self):
self.assertEquals(convert_case("from_"), "From")
self.assertEquals(convert_case("to"), "To")
self.assertEquals(convert_case("friendly_name"), "FriendlyName")
def test_convert_bool(self):
self.assertEquals(convert_boolean(False), "false")
self.assertEquals(convert_boolean(True), "true")
self.assertEquals(convert_boolean(1), 1)
def test_convert_keys(self):
d = {
"from_": 0,
"to": 0,
"friendly_name": 0,
"ended": 0,
}
ed = {
"From": 0,
"To": 0,
"FriendlyName": 0,
"EndTime": 0,
}
self.assertEquals(ed, convert_keys(d))