def __serialize__(self): return { "text": self.text, "version": self.version, "created": functions.date_serialize(self.created), "last_modified": functions.date_serialize(self.last_modified), }
def test_deserialize(self): ser=self._data(add=["visible","created_by","last_modified_by"]) created=self.random_datetime_utc() last_modified=created+self.random_timedelta() unser={ "publishing_date": ser["publishing_date"], "created_by": ser["created_by"], "last_modified_by":ser["last_modified_by"], "created": created } ser["created"]=functions.date_serialize(created) ser["last_modified"]=functions.date_serialize(last_modified) ser["publishing_date"]=functions.date_serialize(ser["publishing_date"]) ser["created_by"]=ser["created_by"].__serialize__() ser["last_modified_by"]=ser["last_modified_by"].__serialize__() obj=self.model.objects.deserialize(ser) for k in self.fields: self.assertTrue(hasattr(obj,k)) if k=="last_modified": continue if k in unser: self.assertEqual(unser[k],getattr(obj,k)) continue self.assertEqual(ser[k],getattr(obj,k)) obj2=self.model.objects.deserialize(ser) self.assertEqual(obj.id,obj2.id)
def test_deserialize(self): ser = self._data( add=["last_name", "first_name", "last_login", "groups"]) date_joined = self.random_datetime_utc() last_login = ser["last_login"] groups = ser["groups"] ser["groups"] = [g.name for g in groups] ser["date_joined"] = functions.date_serialize(date_joined) ser["last_login"] = functions.date_serialize(last_login) del (ser["password"]) obj = self.model.objects.deserialize(ser) for k in self.fields: self.assertTrue(hasattr(obj, k)) if k == "password": continue if k == "email": self.assertEqual(ser[k].lower(), obj.email) continue if k == "date_joined": self.assertEqual(date_joined, getattr(obj, k)) continue if k == "last_login": self.assertEqual(last_login, getattr(obj, k)) continue if k != "groups": self.assertEqual(ser[k], getattr(obj, k)) continue for grp in groups: self.assertIn(grp, obj.groups.all()) obj2 = self.model.objects.deserialize(ser) self.assertEqual(obj.id, obj2.id)
def __serialize__(self): return { "title": self.title, "content": self.content, "publishing_date": functions.date_serialize(self.publishing_date), "visible": self.visible, "created": functions.date_serialize(self.created), "last_modified": functions.date_serialize(self.last_modified), "created_by": self.created_by.__serialize__(), "last_modified_by": self.last_modified_by.__serialize__(), }
def __serialize__(self): ret = { "username": self.username, "last_name": self.last_name, "first_name": self.first_name, "email": self.email, "is_active": self.is_active, "date_joined": functions.date_serialize(self.date_joined), } if self.last_login: ret["last_login"] = functions.date_serialize(self.last_login) return ret
def __serialize__(self): return { "session_key": self.session_key, "created": functions.date_serialize(self.created), "code_name": self.code_name, "name": self.name, "version": self.version, "language": self.language, "platform": self.platform, "user_agent": self.user_agent, "cookies_enabled": self.cookies_enabled, "timezone": self.timezone, "iso_timestamps": self.iso_timestamps, "screen_width": self.screen_width, "screen_height": self.screen_height, "screen_color_depth": self.screen_color_depth, "screen_pixel_depth": self.screen_pixel_depth, "screen_available_height": self.screen_available_height, "screen_available_width": self.screen_available_width, "viewport_height": self.viewport_height, "viewport_width": self.viewport_width, "luxon_intl": self.luxon_intl, "luxon_intl_tokens": self.luxon_intl_tokens, "luxon_zones": self.luxon_zones, "luxon_relative": self.luxon_relative, }
def test_deserialize(self): ser = self._data() created = self.random_datetime_utc() last_modified = created + self.random_timedelta() ser["created"] = functions.date_serialize(created) ser["last_modified"] = functions.date_serialize(last_modified) obj = self.model.objects.deserialize(ser) for k in self.fields: with self.subTest(field=k): self.assertTrue(hasattr(obj, k)) if k == "last_modified": continue if k not in ["created", "last_modified"]: self.assertEqual(ser[k], getattr(obj, k)) continue self.assertEqual(created, getattr(obj, k)) obj2 = self.model.objects.deserialize(ser) self.assertEqual(obj.id, obj2.id)
def test_deserialize(self): ser = self._data(add=[ "code_name", "name", "version", "language", "platform", "user_agent", "cookies_enabled", "screen_width", "screen_height", "screen_available_width", "screen_available_height", "screen_color_depth", "screen_pixel_depth", "viewport_height", "viewport_width", "luxon_intl", "luxon_intl_tokens", "luxon_zones", "luxon_relative", "timezone", "iso_timestamps" ]) created = self.random_datetime_utc() ser["created"] = functions.date_serialize(created) obj = self.model.objects.deserialize(ser) for k in self.fields: with self.subTest(field=k): self.assertTrue(hasattr(obj, k)) if k == "created": self.assertEqual(created, getattr(obj, k)) continue self.assertEqual(ser[k], getattr(obj, k)) obj2 = self.model.objects.deserialize(ser) self.assertEqual(obj.id, obj2.id)