File: test_deserialize.py

package info (click to toggle)
python-twilio 9.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,756 kB
  • sloc: python: 8,281; makefile: 65
file content (79 lines) | stat: -rw-r--r-- 2,425 bytes parent folder | download
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
import datetime
import unittest
from decimal import Decimal

from twilio.base import deserialize


class Iso8601DateTestCase(unittest.TestCase):
    def test_parsable(self):
        actual = deserialize.iso8601_date("2015-01-02")
        expected = datetime.date(2015, 1, 2)
        self.assertEqual(expected, actual)

    def test_not_parsable(self):
        actual = deserialize.iso8601_date("not-a-date")
        self.assertEqual("not-a-date", actual)


class Iso8601DateTimeTestCase(unittest.TestCase):
    def test_parsable(self):
        actual = deserialize.iso8601_datetime("2015-01-02T03:04:05Z")
        expected = datetime.datetime(2015, 1, 2, 3, 4, 5, 0, datetime.timezone.utc)
        self.assertEqual(expected, actual)

    def test_not_parsable(self):
        actual = deserialize.iso8601_datetime("not-a-datetime")
        self.assertEqual("not-a-datetime", actual)


class DecimalTestCase(unittest.TestCase):
    def test_none(self):
        self.assertEqual(None, deserialize.decimal(None))

    def test_empty_string(self):
        self.assertEqual("", deserialize.decimal(""))

    def test_zero_string(self):
        self.assertEqual(Decimal("0.0000"), deserialize.decimal("0.0000"))

    def test_negative_string(self):
        self.assertEqual(Decimal("-0.0123"), deserialize.decimal("-0.0123"))

    def test_positive_string(self):
        self.assertEqual(Decimal("0.0123"), deserialize.decimal("0.0123"))

    def test_zero(self):
        self.assertEqual(0, deserialize.decimal(0))

    def test_negative(self):
        self.assertEqual(-0.0123, deserialize.decimal(-0.0123))

    def test_positive(self):
        self.assertEqual(0.0123, deserialize.decimal(0.0123))


class IntegerTestCase(unittest.TestCase):
    def test_none(self):
        self.assertEqual(None, deserialize.integer(None))

    def test_empty_string(self):
        self.assertEqual("", deserialize.integer(""))

    def test_zero_string(self):
        self.assertEqual(0, deserialize.integer("0"))

    def test_negative_string(self):
        self.assertEqual(-1, deserialize.integer("-1"))

    def test_positive_string(self):
        self.assertEqual(1, deserialize.integer("1"))

    def test_zero(self):
        self.assertEqual(0, deserialize.integer(0))

    def test_negative(self):
        self.assertEqual(-1, deserialize.integer(-1))

    def test_positive(self):
        self.assertEqual(1, deserialize.integer(1))