aboutsummaryrefslogtreecommitdiffstats
path: root/tests/middleware/test_open_store.py
blob: 3e844a922522c1fce97f0440a47342ae4b0f15f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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