mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Re-arranged config tests to work around weird error
This commit is contained in:
parent
002c9c464a
commit
fd6164b03e
2 changed files with 17 additions and 16 deletions
|
|
@ -15,6 +15,10 @@ import time
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
|
|
||||||
|
# This temp file is used by one of the plugin config tests
|
||||||
|
TEMP_PLUGIN_SECRET_FILE = os.path.join(tempfile.gettempdir(), "plugin-secret")
|
||||||
|
|
||||||
|
|
||||||
class TestResponse:
|
class TestResponse:
|
||||||
def __init__(self, status, headers, body):
|
def __init__(self, status, headers, body):
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|
@ -97,7 +101,6 @@ def make_app_client(
|
||||||
memory=False,
|
memory=False,
|
||||||
config=None,
|
config=None,
|
||||||
filename="fixtures.db",
|
filename="fixtures.db",
|
||||||
metadata=None,
|
|
||||||
is_immutable=False,
|
is_immutable=False,
|
||||||
extra_databases=None,
|
extra_databases=None,
|
||||||
inspect_data=None,
|
inspect_data=None,
|
||||||
|
|
@ -140,7 +143,7 @@ def make_app_client(
|
||||||
immutables=immutables,
|
immutables=immutables,
|
||||||
memory=memory,
|
memory=memory,
|
||||||
cors=cors,
|
cors=cors,
|
||||||
metadata=metadata or METADATA,
|
metadata=METADATA,
|
||||||
plugins_dir=plugins_dir,
|
plugins_dir=plugins_dir,
|
||||||
config=config,
|
config=config,
|
||||||
inspect_data=inspect_data,
|
inspect_data=inspect_data,
|
||||||
|
|
@ -247,7 +250,11 @@ METADATA = {
|
||||||
"source_url": "https://github.com/simonw/datasette/blob/master/tests/fixtures.py",
|
"source_url": "https://github.com/simonw/datasette/blob/master/tests/fixtures.py",
|
||||||
"about": "About Datasette",
|
"about": "About Datasette",
|
||||||
"about_url": "https://github.com/simonw/datasette",
|
"about_url": "https://github.com/simonw/datasette",
|
||||||
"plugins": {"name-of-plugin": {"depth": "root"}},
|
"plugins": {
|
||||||
|
"name-of-plugin": {"depth": "root"},
|
||||||
|
"env-plugin": {"foo": {"$env": "FOO_ENV"}},
|
||||||
|
"file-plugin": {"foo": {"$file": TEMP_PLUGIN_SECRET_FILE}},
|
||||||
|
},
|
||||||
"databases": {
|
"databases": {
|
||||||
"fixtures": {
|
"fixtures": {
|
||||||
"description": "Test tables description",
|
"description": "Test tables description",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from bs4 import BeautifulSoup as Soup
|
from bs4 import BeautifulSoup as Soup
|
||||||
from .fixtures import app_client, make_app_client # noqa
|
from .fixtures import app_client, make_app_client, TEMP_PLUGIN_SECRET_FILE # noqa
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
@ -126,22 +126,16 @@ def test_plugin_config(app_client):
|
||||||
assert None is app_client.ds.plugin_config("unknown-plugin")
|
assert None is app_client.ds.plugin_config("unknown-plugin")
|
||||||
|
|
||||||
|
|
||||||
def test_plugin_config_env():
|
def test_plugin_config_env(app_client):
|
||||||
os.environ["FOO_ENV"] = "FROM_ENVIRONMENT"
|
os.environ["FOO_ENV"] = "FROM_ENVIRONMENT"
|
||||||
for client in make_app_client(
|
assert {"foo": "FROM_ENVIRONMENT"} == app_client.ds.plugin_config("env-plugin")
|
||||||
metadata={"plugins": {"env-plugin": {"foo": {"$env": "FOO_ENV"}}}}
|
|
||||||
):
|
|
||||||
assert {"foo": "FROM_ENVIRONMENT"} == client.ds.plugin_config("env-plugin")
|
|
||||||
del os.environ["FOO_ENV"]
|
del os.environ["FOO_ENV"]
|
||||||
|
|
||||||
|
|
||||||
def test_plugin_config_file(tmpdir):
|
def test_plugin_config_file(app_client):
|
||||||
filepath = str(tmpdir / "secret-file")
|
open(TEMP_PLUGIN_SECRET_FILE, "w").write("FROM_FILE")
|
||||||
open(filepath, "w").write("FROM_FILE")
|
assert {"foo": "FROM_FILE"} == app_client.ds.plugin_config("file-plugin")
|
||||||
for client in make_app_client(
|
os.remove(TEMP_PLUGIN_SECRET_FILE)
|
||||||
metadata={"plugins": {"file-plugin": {"foo": {"$file": filepath}}}}
|
|
||||||
):
|
|
||||||
assert {"foo": "FROM_FILE"} == client.ds.plugin_config("file-plugin")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue