-
Notifications
You must be signed in to change notification settings - Fork 50
/
conftest.py
46 lines (33 loc) · 1.16 KB
/
conftest.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import tempfile
from pathlib import Path
import pytest
from fastapi.testclient import TestClient
from tinydb import TinyDB
from tinydb.storages import MemoryStorage
import docat.app as docat
from docat.utils import create_symlink
@pytest.fixture
def client():
temp_dir = tempfile.TemporaryDirectory()
docat.DOCAT_UPLOAD_FOLDER = Path(temp_dir.name)
docat.db = TinyDB(storage=MemoryStorage)
yield TestClient(docat.app)
docat.app.db = None
temp_dir.cleanup()
@pytest.fixture
def client_with_claimed_project(client):
table = docat.db.table("claims")
token_hash_1234 = b"\xe0\x8cS\xa3)\xb4\xb5\xa5\xda\xc3K\x96\xf6).\xdd-\xacR\x8e3Q\x17\x87\xfb\x94\x0c-\xc2h\x1c\xf3"
table.insert({"name": "some-project", "token": token_hash_1234.hex(), "salt": ""})
yield client
@pytest.fixture
def temp_project_version(tmp_path):
docs = tmp_path / "doc"
docs.mkdir()
def __create(project, version):
version_docs = docs / project / version
version_docs.mkdir(parents=True)
(version_docs / "index.html").touch()
create_symlink(version_docs, docs / project / "latest")
return docs
yield __create