changeset 6704b2faa950 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=6704b2faa950
description:
Add protocols test for timedelta and factorize them
issue10733
review371841002
diffstat:
trytond/tests/test_protocols.py | 101 +++++++++++++++++----------------------
1 files changed, 45 insertions(+), 56 deletions(-)
diffs (126 lines):
diff -r d3b83d15ef73 -r 6704b2faa950 trytond/tests/test_protocols.py
--- a/trytond/tests/test_protocols.py Thu Sep 23 10:15:16 2021 +0200
+++ b/trytond/tests/test_protocols.py Thu Sep 23 10:19:03 2021 +0200
@@ -11,7 +11,50 @@
from trytond.protocols.xmlrpc import client, XMLRequest
-class JSONTestCase(unittest.TestCase):
+class DumpsLoadsMixin:
+
+ def dumps_loads(self, value):
+ raise NotImplementedError
+
+ def test_datetime(self):
+ 'Test datetime'
+ self.dumps_loads(datetime.datetime.now())
+
+ def test_date(self):
+ 'Test date'
+ self.dumps_loads(datetime.date.today())
+
+ def test_time(self):
+ 'Test time'
+ self.dumps_loads(datetime.datetime.now().time())
+
+ def test_timedelta(self):
+ "Test timedelta"
+ self.dumps_loads(datetime.timedelta(days=1, seconds=10))
+
+ def test_bytes(self):
+ 'Test bytes'
+ self.dumps_loads(bytes(b'foo'))
+ self.dumps_loads(bytearray(b'foo'))
+
+ def test_decimal(self):
+ 'Test Decimal'
+ self.dumps_loads(Decimal('3.141592653589793'))
+
+ def test_biginteger(self):
+ "Test BigInteger"
+ self.dumps_loads(client.MAXINT + 1)
+
+ def test_immutable_dict(self):
+ "Test ImmutableDict"
+ self.dumps_loads(ImmutableDict(foo='bar'))
+
+ def test_none(self):
+ 'Test None'
+ self.dumps_loads(None)
+
+
+class JSONTestCase(DumpsLoadsMixin, unittest.TestCase):
'Test JSON'
def test_json_request(self):
@@ -29,33 +72,8 @@
json.dumps(value, cls=JSONEncoder),
object_hook=JSONDecoder()), value)
- def test_datetime(self):
- 'Test datetime'
- self.dumps_loads(datetime.datetime.now())
- def test_date(self):
- 'Test date'
- self.dumps_loads(datetime.date.today())
-
- def test_time(self):
- 'Test time'
- self.dumps_loads(datetime.datetime.now().time())
-
- def test_bytes(self):
- 'Test bytes'
- self.dumps_loads(bytes(b'foo'))
- self.dumps_loads(bytearray(b'foo'))
-
- def test_decimal(self):
- 'Test Decimal'
- self.dumps_loads(Decimal('3.141592653589793'))
-
- def test_immutable_dict(self):
- "Test ImmutableDict"
- self.dumps_loads(ImmutableDict(foo='bar'))
-
-
-class XMLTestCase(unittest.TestCase):
+class XMLTestCase(DumpsLoadsMixin, unittest.TestCase):
'Test XML'
def test_xml_request(self):
@@ -83,35 +101,6 @@
result, = result
self.assertEqual(value, result)
- def test_decimal(self):
- 'Test Decimal'
- self.dumps_loads(Decimal('3.141592653589793'))
-
- def test_bytes(self):
- 'Test bytes'
- self.dumps_loads(bytes(b'foo'))
- self.dumps_loads(bytearray(b'foo'))
-
- def test_date(self):
- 'Test date'
- self.dumps_loads(datetime.date.today())
-
- def test_time(self):
- 'Test time'
- self.dumps_loads(datetime.datetime.now().time())
-
- def test_biginteger(self):
- "Test BigInteger"
- self.dumps_loads(client.MAXINT + 1)
-
- def test_immutable_dict(self):
- "Test ImmutableDict"
- self.dumps_loads(ImmutableDict(foo='bar'))
-
- def test_none(self):
- 'Test None'
- self.dumps_loads(None)
-
def suite():
suite_ = unittest.TestSuite()