Пример #1
0
    def test_encoder_missing(self):
        """If no encoder is found, raise ValueError"""
        from datetime import datetime

        dynamizer = Dynamizer()
        with self.assertRaises(ValueError):
            dynamizer.encode(datetime.utcnow())
Пример #2
0
 def test_register_encoder(self):
     """ Can register a custom encoder """
     from datetime import datetime
     dynamizer = Dynamizer()
     dynamizer.register_encoder(datetime, lambda d, v:
                                (STRING, v.isoformat()))
     now = datetime.utcnow()
     self.assertEqual(dynamizer.raw_encode(now), (STRING, now.isoformat()))
Пример #3
0
 def test_register_encoder(self):
     """ Can register a custom encoder """
     from datetime import datetime
     dynamizer = Dynamizer()
     dynamizer.register_encoder(datetime, lambda d, v:
                                (STRING, v.isoformat()))
     now = datetime.utcnow()
     self.assertEqual(dynamizer.raw_encode(now), (STRING, now.isoformat()))
Пример #4
0
 def test_encoder_missing(self):
     """ If no encoder is found, raise ValueError """
     from datetime import datetime
     dynamizer = Dynamizer()
     with self.assertRaises(ValueError):
         dynamizer.encode(datetime.utcnow())