"""Add Drive signed upload test.""" import pathlib p = pathlib.Path('tests/test_contract_uploads.py') t = p.read_bytes() drive_test = ( b"\n def test_signed_upload_with_google_drive(\n" b" self, app, client, as_role, make_user, contract_for, monkeypatch\n" b" ):\n" b' """Signing with Drive backend stores gdrive:// in signed_file_path."""\n' b" monkeypatch.setenv('DOCUMENT_STORAGE_BACKEND', 'google_drive')\n" b" monkeypatch.setattr(\n" b" 'app.storage.upload_google_drive_file',\n" b" lambda **_kwargs: 'drive-signed-456',\n" b" )\n" b" player_id = as_role('player')\n" b" admin_id = make_user('admin')\n" b" contract_id, directory = contract_for(player_id, admin_id)\n\n" b" client.post(\n" b" f'/users/contracts/{contract_id}/upload_signed',\n" b" data={'signed_file': (io.BytesIO(_PDF_BYTES), 'signed.pdf')},\n" b" content_type='multipart/form-data',\n" b" follow_redirects=True,\n" b" )\n\n" b" with app.app_context():\n" b" contract = db.session.get(Contract, contract_id)\n" b" assert contract.status == 'signed'\n" b" assert contract.signed_file_path == 'gdrive://drive-signed-456'\n\n" ) # Add before 'class TestTheHelper:' marker = b'\nclass TestTheHelper:' pos = t.find(marker) if pos >= 0: t = t[:pos] + drive_test + t[pos:] p.write_bytes(t) print('Added Drive signed upload test') else: print('Could not find marker')