Ejemplo n.º 1
0
 def test_datetime_with_strip_ms(self):
     """Testing DjbletsJSONENcoder.encode with datetimes when using
     strip_datetime_ms=False
     """
     encoder = DjbletsJSONEncoder(strip_datetime_ms=False)
     self.assertEqual(
         encoder.encode(datetime(2016, 8, 26, 3, 3, 26, 123456)),
         '"2016-08-26T03:03:26.123"')
Ejemplo n.º 2
0
 def test_datetime_with_strip_ms(self):
     """Testing DjbletsJSONENcoder.encode with datetimes when using
     strip_datetime_ms=False
     """
     encoder = DjbletsJSONEncoder(strip_datetime_ms=False)
     self.assertEqual(
         encoder.encode(datetime.datetime(2016, 8, 26, 3, 3, 26, 123456)),
         '"2016-08-26T03:03:26.123"')
Ejemplo n.º 3
0
    def test_model_to_json(self):
        """Testing DjbletsJSONEncoder.encode for a Model"""

        class TestModel(models.Model):
            foo = models.IntegerField()

            def to_json(self):
                return {"foo": self.foo}

        obj = TestModel(foo=1)
        encoder = DjbletsJSONEncoder()

        self.assertEqual(encoder.encode(obj), '{"foo": 1}')
Ejemplo n.º 4
0
    def test_object_to_json(self):
        """Testing DjbletsJSONEncoder.encode for an object with a to_json()
        method
        """
        class TestObject(object):
            def to_json(self):
                return {
                    'foo': 1,
                }

        obj = TestObject()
        encoder = DjbletsJSONEncoder()

        self.assertEqual(encoder.encode(obj), '{"foo": 1}')
Ejemplo n.º 5
0
    def test_object_to_json(self):
        """Testing DjbletsJSONEncoder.encode for an object with a to_json()
        method
        """
        class TestObject(object):
            def to_json(self):
                return {
                    'foo': 1,
                }

        obj = TestObject()
        encoder = DjbletsJSONEncoder()

        self.assertEqual(encoder.encode(obj), '{"foo": 1}')
Ejemplo n.º 6
0
 def test_datetime(self):
     """Testing DjbletsJSONENcoder.encode with datetimes"""
     encoder = DjbletsJSONEncoder()
     self.assertEqual(
         encoder.encode(datetime.datetime(2016, 8, 26, 3, 3, 26, 123456)),
         '"2016-08-26T03:03:26"')
Ejemplo n.º 7
0
 def test_datetime(self):
     """Testing DjbletsJSONENcoder.encode with datetimes"""
     encoder = DjbletsJSONEncoder()
     self.assertEqual(
         encoder.encode(datetime(2016, 8, 26, 3, 3, 26, 123456)),
         '"2016-08-26T03:03:26"')