from contextlib import contextmanager from wsgiref.validate import validator from paste import open_database from ..common_wsgi import call_app def test_open_database(monkeypatch): db_path = "test_db_path" conn = object() @contextmanager def connect(uri): assert uri == db_path yield conn @validator @open_database @validator def app(environ, start_response): assert "paste.db_conn" in environ assert environ["paste.db_conn"] == conn start_response("200 OK", [("Content-Type", "text/plain")]) return [b"Hello, World!"] monkeypatch.setattr("paste.db.connect", connect) response = call_app(app, environ={"PASTE_DB": db_path}) assert response.status == "200 OK" assert response.data == b"Hello, World!" assert ("Content-Type", "text/plain") in response.headers