-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_mask_columns.py
31 lines (29 loc) · 1.12 KB
/
test_mask_columns.py
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 datasette.app import Datasette
import sqlite_utils
import pytest
import httpx
@pytest.mark.asyncio
async def test_datasette_mask_columns(tmpdir):
path = str(tmpdir / "foo.db")
db = sqlite_utils.Database(path)
db["users"].insert({"id": 1, "password": "secret"})
datasette = Datasette([path], memory=True)
# Without the plugin:
async with httpx.AsyncClient(app=datasette.app()) as client:
response = await client.get("http://localhost/foo/users.json?_shape=array")
assert 200 == response.status_code
assert [{"rowid": 1, "id": 1, "password": "secret"}] == response.json()
# With the plugin:
datasette2 = Datasette(
[path],
memory=True,
metadata={
"databases": {
"foo": {"plugins": {"datasette-mask-columns": {"users": ["password"]}}}
}
},
)
async with httpx.AsyncClient(app=datasette2.app()) as client:
response = await client.get("http://localhost/foo/users.json?_shape=array")
assert 200 == response.status_code
assert [{"rowid": 1, "id": 1, "password": None}] == response.json()