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())
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())
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')
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')
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")