def test_deserialization(): note = Notification(actor, verb_inf, note_object, source, level=level_id, target=target, external_key=external_key, context=context, users=users) serial = note.serialize() note2 = Notification.deserialize(serial) assert note2.id == note.id assert note2.actor == note.actor assert note2.verb.id == note.verb.id assert note2.object == note.object assert note2.source == note.source assert note2.level.id == note.level.id assert note2.target == note.target assert note2.external_key == note.external_key assert note2.context == note.context assert note2.users == note.users
def test_deserialize_bad(): with pytest.raises(InvalidNotificationError) as e: Notification.deserialize(None) assert "Can't deserialize an input of 'None'" in str(e.value) with pytest.raises(InvalidNotificationError) as e: Notification.deserialize(json.dumps({'a': actor.to_dict()})) assert "Missing keys" in str(e.value) with pytest.raises(InvalidNotificationError) as e: Notification.deserialize("foo") assert "Can only deserialize a JSON string" in str(e.value)