Esempio n. 1
0
    def test__serial_error(self):
        """If obj is not serializable, raise an exception."""

        obj = MagicMock()

        # Actual call
        with self.assertRaises(TypeError) as ex:
            JSONSerializer._serial(obj)

        # Asserts
        exception = ex.exception
        self.assertEqual('MagicMock is not JSON serializable', str(exception))
Esempio n. 2
0
    def test__serial_objectid(self):
        """If obj is an ObjectId, print it as a string."""

        obj = ObjectId('57bee205ab17852928644d3e')

        # Actual call
        serialized = JSONSerializer._serial(obj)

        # Asserts
        self.assertEqual('57bee205ab17852928644d3e', serialized)
Esempio n. 3
0
    def test__serial_datetime(self):
        """If obj is a datetime, isoformat it."""

        obj = datetime.datetime(2000, 1, 1)

        # Actual call
        serialized = JSONSerializer._serial(obj)

        # Asserts
        self.assertEqual('2000-01-01T00:00:00', serialized)