Creates folders, models, test object and its children records.
(scratch_project, children_records_data)
| 39 | |
| 40 | @pytest.fixture(scope="function", autouse=True) |
| 41 | def 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 | |
| 73 | def test_children_sorting_via_api(scratch_test_client, children_records_data): |