51 lines
1.1 KiB
Python
51 lines
1.1 KiB
Python
"""Scratch Zotero DB for the fetch tests (no live DB, no network)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sqlite3
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from tests.zot.test_db import ZOTERO_SCHEMA, _seed_schema_maps
|
|
from zot.db import TYPE_MAP, Db
|
|
|
|
EXTRA_SCHEMA = """
|
|
CREATE TABLE IF NOT EXISTS deletedItems (
|
|
itemID INTEGER PRIMARY KEY,
|
|
dateDeleted TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
);
|
|
"""
|
|
|
|
|
|
@pytest.fixture()
|
|
def zdb(tmp_path: Path) -> Db:
|
|
path = str(tmp_path / "zotero.sqlite")
|
|
con = sqlite3.connect(path)
|
|
con.executescript(ZOTERO_SCHEMA)
|
|
con.executescript(EXTRA_SCHEMA)
|
|
_seed_schema_maps(con)
|
|
con.commit()
|
|
con.close()
|
|
d = Db(path)
|
|
yield d
|
|
d.close()
|
|
|
|
|
|
def mk_item(
|
|
db: Db,
|
|
*,
|
|
type_name: str = "journalArticle",
|
|
title: str = "",
|
|
doi: str = "",
|
|
isbn: str = "",
|
|
date: str = "",
|
|
extra: str = "",
|
|
) -> int:
|
|
item_id = db.create_item(TYPE_MAP[type_name])
|
|
db.set_fields(
|
|
item_id,
|
|
{"title": title, "DOI": doi, "ISBN": isbn, "date": date, "extra": extra},
|
|
)
|
|
return item_id
|