Esempio n. 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())
Esempio n. 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()))
Esempio n. 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()))
Esempio n. 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())