MCPcopy
hub / github.com/lektor/lektor / prepare_stub_data

Function prepare_stub_data

tests/test_api.py:41–70  ·  view source on GitHub ↗

Creates folders, models, test object and its children records.

(scratch_project, children_records_data)

Source from the content-addressed store, hash-verified

39
40@pytest.fixture(scope="function", autouse=True)
41def prepare_stub_data(scratch_project, children_records_data):
42 """Creates folders, models, test object and its children records."""
43 tree = scratch_project.tree
44 with open(os.path.join(tree, "models", "mymodel.ini"), "w", encoding="utf-8") as f:
45 f.write("[children]\n" "order_by = -pub_date, title\n")
46 with open(
47 os.path.join(tree, "models", "mychildmodel.ini"), "w", encoding="utf-8"
48 ) as f:
49 f.write(
50 "[fields.title]\n" "type = string\n" "[fields.pub_date]\n" "type = date"
51 )
52 os.mkdir(os.path.join(tree, "content", "myobj"))
53 with open(
54 os.path.join(tree, "content", "myobj", "contents.lr"), "w", encoding="utf-8"
55 ) as f:
56 f.write("_model: mymodel\n" "---\n" "title: My Test Object\n")
57 for record in children_records_data:
58 os.mkdir(os.path.join(tree, "content", "myobj", record["id"]))
59 with open(
60 os.path.join(tree, "content", "myobj", record["id"], "contents.lr"),
61 "w",
62 encoding="utf-8",
63 ) as f:
64 f.write(
65 "_model: mychildmodel\n"
66 "---\n"
67 "title: %s\n"
68 "---\n"
69 "pub_date: %s" % (record["title"], record["pub_date"])
70 )
71
72
73def test_children_sorting_via_api(scratch_test_client, children_records_data):

Callers

nothing calls this directly

Calls 1

mkdirMethod · 0.80

Tested by

no test coverage detected