Exemple #1
0
    def setUp(self):
        class Person(micromodels.Model):
            name = micromodels.CharField()
            age = micromodels.IntegerField(default=0)

        self.Person = Person
        self.data = {'name': 'Eric', 'age': 18}
        self.json_data = json.encode(self.data)
Exemple #2
0
    def test_model_type_change_serialization(self):
        class Event(micromodels.Model):
            time = micromodels.DateField(format="%Y-%m-%d")

        data = {'time': '2000-10-31'}
        json_data = json.encode(data)

        instance = Event.from_dict(json_data, is_json=True)
        output = instance.to_dict(serial=True)
        self.assertEqual(output['time'], instance.time.isoformat())
        self.assertEqual(json.decode(instance.to_json())['time'],
                         instance.time.isoformat())