def editjson(id: int): """Lets the user edit the raw json of the character.""" c = get_character(id, check_author=True) form = ImportForm(obj=c) if form.validate_on_submit(): c.title = form.title.data c.body = form.body.data if form.migration.data: logger.debug("Trying to migrate data") data = form.body.data c.body = migrate(data, latest, migrations=migrations) elif form.conversion.data: logger.debug("Conversion is checked") data = form.body.data c.body = coc7e.convert_from_dholes(data) logentry = LogEntry(c, "JSON edited", user_id=current_user.id) session.add(logentry) session.commit() return redirect(url_for('character.view', id=c.id)) form.submit.label.text = 'Save' validation_errors = c.validate() return render_template('character/import.html.jinja', title="Edit JSON", validation_errors=validation_errors, form=form, type=None)
def test_migrate_down(): data = {"meta": { "Version": "1.0.1" }} migrated = migrate(data, "1.0.0", migrations=migrations) assert migrated['meta']['Version'] == "1.0.0"
def test_migrate_same(): data = {"meta": { "Version": "1.0.0" }} migrated = migrate(data, "1.0.0") assert migrated == data
def test_validate_migration_up_and_down(test_sheet: dict): migrated = migrate(test_sheet.copy(), "0.0.4", migrations=migrations) back_down = migrate(migrated, "0.0.1", migrations=migrations) assert test_sheet == back_down
def test_validate_migration_latest(test_sheet: dict): errors = validate(migrate(test_sheet, latest, migrations=migrations), CHARACTER_SCHEMA) assert len(errors) == 0, errors
def test_migrate_unavailable(): data = {"version": "1.0.2"} with pytest.raises(Exception): migrate(data, "2.0.0", migrations=migrations)