46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
|
|
import io
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
from PIL import Image
|
||
|
|
|
||
|
|
from soapbox import db
|
||
|
|
from soapbox.app import create_app
|
||
|
|
from soapbox.config import load_config
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def cfg(tmp_path):
|
||
|
|
return load_config(
|
||
|
|
{"SOAPBOX_DATA_DIR": str(tmp_path / "data"), "SOAPBOX_SITE_URL": "https://blog.example.no"}
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def app(cfg):
|
||
|
|
app = create_app(cfg)
|
||
|
|
app.config["TESTING"] = True
|
||
|
|
conn = db.connect(cfg.db_path)
|
||
|
|
db.create_user(conn, "eier", "hemmelig123", db.ROLE_OWNER, "Ole")
|
||
|
|
db.create_user(conn, "gjest1", "hemmelig123", db.ROLE_GUEST, "Gjest En")
|
||
|
|
conn.close()
|
||
|
|
return app
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def client(app):
|
||
|
|
return app.test_client()
|
||
|
|
|
||
|
|
|
||
|
|
def login(client, username="eier", password="hemmelig123", prefix=""):
|
||
|
|
return client.post(f"{prefix}/admin/login", data={"username": username, "password": password})
|
||
|
|
|
||
|
|
|
||
|
|
def csrf(client, prefix=""):
|
||
|
|
with client.session_transaction(path=f"{prefix}/admin/") as s:
|
||
|
|
return s["csrf"]
|
||
|
|
|
||
|
|
|
||
|
|
def png_bytes(size=(3000, 1500)):
|
||
|
|
buf = io.BytesIO()
|
||
|
|
Image.new("RGB", size, "green").save(buf, "PNG")
|
||
|
|
return buf.getvalue()
|