debut changement vers google drive
CI - Security, Lint & Tests / validate (push) Failing after 1m14s
CI - Security, Lint & Tests / validate (push) Failing after 1m14s
This commit is contained in:
@@ -80,6 +80,7 @@ def documents_in_a_throwaway_directory(tmp_path, monkeypatch):
|
||||
cannot leave a PDF in someone's working tree.
|
||||
"""
|
||||
monkeypatch.setenv('DOCUMENTS_ROOT', str(tmp_path / 'documents'))
|
||||
monkeypatch.setenv('DOCUMENT_STORAGE_BACKEND', 'local')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
+14
-17
@@ -1,17 +1,17 @@
|
||||
"""Which PostgreSQL driver the application actually asks for — QUA-001.
|
||||
|
||||
`postgresql://…` is not "whichever driver is installed". SQLAlchemy reads it
|
||||
as psycopg2 and imports that module when the engine is created.
|
||||
requirements.txt pins psycopg 3 and no psycopg2, so a clean install against
|
||||
the URL Render hands out — the same form docs/database-restore.md documents
|
||||
— fails before the first request:
|
||||
as psycopg2 unless the URL names a driver. requirements.txt declares psycopg
|
||||
3, so create_app() must explicitly select it.
|
||||
|
||||
ModuleNotFoundError: No module named 'psycopg2'
|
||||
|
||||
create_app() now names the driver. These tests pin that down, and the last
|
||||
one proves the failure is real rather than theoretical.
|
||||
The test suite must not assume that psycopg2 is absent: a developer's virtual
|
||||
environment can contain optional packages in addition to the declared
|
||||
dependencies. These tests instead pin the application's selected driver and
|
||||
the dependency contract that production installs use.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
@@ -80,16 +80,13 @@ class TestTheFactory:
|
||||
assert app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite:///')
|
||||
|
||||
|
||||
class TestTheFailureIsReal:
|
||||
"""Not a hypothetical: this is what the deployed configuration did."""
|
||||
class TestDriverContract:
|
||||
def test_production_dependencies_select_psycopg_3(self):
|
||||
requirements = Path(__file__).resolve().parents[1] / 'requirements.txt'
|
||||
declared = requirements.read_text(encoding='utf-8')
|
||||
|
||||
def test_psycopg2_is_not_installed(self):
|
||||
with pytest.raises(ImportError):
|
||||
import psycopg2 # noqa: F401
|
||||
|
||||
def test_a_driverless_url_cannot_build_an_engine(self):
|
||||
with pytest.raises(ModuleNotFoundError):
|
||||
create_engine('postgresql://u:p@host/db')
|
||||
assert 'psycopg[binary]==' in declared
|
||||
assert 'psycopg2' not in declared
|
||||
|
||||
def test_the_normalised_url_can(self):
|
||||
engine = create_engine(normalise_database_url('postgresql://u:p@host/db'))
|
||||
|
||||
+23
-1
@@ -19,7 +19,13 @@ import os
|
||||
import pytest
|
||||
|
||||
from app.extensions import db
|
||||
from app.storage import CONTRACTS_DIR, document_path, documents_root
|
||||
from app.storage import (
|
||||
CONTRACTS_DIR,
|
||||
GOOGLE_DRIVE_PATH_PREFIX,
|
||||
document_path,
|
||||
documents_root,
|
||||
store_uploaded_document,
|
||||
)
|
||||
|
||||
|
||||
class TestDocumentsRoot:
|
||||
@@ -87,6 +93,22 @@ class TestDocumentPath:
|
||||
assert first_old == second_old, 'and must not move the ones already filed'
|
||||
|
||||
|
||||
class TestGoogleDriveStorage:
|
||||
def test_new_uploads_store_an_opaque_drive_reference(self, monkeypatch):
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
monkeypatch.setenv('DOCUMENT_STORAGE_BACKEND', 'google_drive')
|
||||
monkeypatch.setattr(
|
||||
'app.storage.upload_google_drive_file',
|
||||
lambda **_kwargs: 'drive-file-123',
|
||||
)
|
||||
upload = FileStorage(stream=_pdf(), filename='contract.pdf', content_type='application/pdf')
|
||||
|
||||
stored_path = store_uploaded_document(upload, os.path.join(CONTRACTS_DIR, 'new.pdf'))
|
||||
|
||||
assert stored_path == f'{GOOGLE_DRIVE_PATH_PREFIX}drive-file-123'
|
||||
|
||||
|
||||
class TestThroughTheUploadRoute:
|
||||
@pytest.fixture
|
||||
def uploaded(self, app, client, as_role, make_user):
|
||||
|
||||
Reference in New Issue
Block a user