def test_update_event_files(self): serialize = SerializeModel() a1 = ModelFile("a", False) a1.local_size = 100 a2 = ModelFile("a", False) a2.local_size = 200 out = parse_stream( serialize.update_event( SerializeModel.UpdateEvent( SerializeModel.UpdateEvent.Change.UPDATED, a1, a2))) data = json.loads(out["data"]) self.assertEqual("a", data["old_file"]["name"]) self.assertEqual(100, data["old_file"]["local_size"]) self.assertEqual("a", data["new_file"]["name"]) self.assertEqual(200, data["new_file"]["local_size"]) out = parse_stream( serialize.update_event( SerializeModel.UpdateEvent( SerializeModel.UpdateEvent.Change.ADDED, None, a1))) data = json.loads(out["data"]) self.assertEqual(None, data["old_file"]) self.assertEqual("a", data["new_file"]["name"]) self.assertEqual(100, data["new_file"]["local_size"]) out = parse_stream( serialize.update_event( SerializeModel.UpdateEvent( SerializeModel.UpdateEvent.Change.ADDED, a2, None))) data = json.loads(out["data"]) self.assertEqual("a", data["old_file"]["name"]) self.assertEqual(200, data["old_file"]["local_size"]) self.assertEqual(None, data["new_file"])
def test_update_event_is_a_dict(self): serialize = SerializeModel() out = parse_stream( serialize.update_event( SerializeModel.UpdateEvent( SerializeModel.UpdateEvent.Change.UPDATED, None, None))) data = json.loads(out["data"]) self.assertEqual(dict, type(data)) self.assertEqual(None, data["old_file"]) self.assertEqual(None, data["new_file"])
def test_event_names(self): serialize = SerializeModel() out = parse_stream(serialize.model([])) self.assertEqual("model-init", out["event"]) out = parse_stream( serialize.update_event( SerializeModel.UpdateEvent( SerializeModel.UpdateEvent.Change.ADDED, None, None))) self.assertEqual("model-added", out["event"]) out = parse_stream( serialize.update_event( SerializeModel.UpdateEvent( SerializeModel.UpdateEvent.Change.UPDATED, None, None))) self.assertEqual("model-updated", out["event"]) out = parse_stream( serialize.update_event( SerializeModel.UpdateEvent( SerializeModel.UpdateEvent.Change.REMOVED, None, None))) self.assertEqual("model-removed", out["event"])