Esempio n. 1
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.dumps(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.loads(instance.to_json())["time"], instance.time.isoformat())
Esempio n. 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.dumps(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.loads(instance.to_json())['time'],
                         instance.time.isoformat())
Esempio n. 3
0
 def test_model_reserialization(self):
     instance = self.Person(self.json_data, is_json=True)
     self.assertEqual(instance.to_json(), self.json_data)
     instance.name = 'John'
     self.assertEqual(json.loads(instance.to_json())['name'],
                      'John')
Esempio n. 4
0
 def test_model_reserialization(self):
     instance = self.Person.from_dict(self.json_data, is_json=True)
     self.assertEqual(instance.to_json(), self.json_data)
     instance.name = 'John'
     self.assertEqual(json.loads(instance.to_json())['name'],
                      'John')
Esempio n. 5
0
 def test_model_reserialization(self):
     instance = self.Person.from_dict(self.json_data, is_json=True)
     self.assertEqual(instance.to_json(), self.json_data)
     instance.name = "John"
     self.assertEqual(json.loads(instance.to_json())["name"], "John")