import sys import pathlib test_file = pathlib.Path(__file__) project = test_file.parent.parent sys.path.append(str(project)) import server_source as source from test import test import asyncio import tortoise async def main(): modules = { source.model.Meta.app: [ "server_source" ] } await tortoise.Tortoise.init( db_url = "sqlite://:memory:", modules = modules ) await tortoise.Tortoise.generate_schemas() sample_author = source.author_proxy \ .create("Sample", "Example") \ .set_description("That is sample author.") \ .result() await sample_author.save() sample_cover = source.attachment_proxy \ .create("cover.jpg") \ .set_name("Cover title") \ .set_description("Cover description.") \ .result() await sample_cover.save() sample_attachment = source.attachment_proxy \ .create("instruction.pdf") \ .set_name("User instruction") \ .set_description("That is simple user instruction.") \ .result() await sample_attachment.save() sample_item = source.item_proxy \ .create("Sample item", "123456789012") \ .set_description("That is sample object.") \ .set_on_stock(10) \ .set_product_type(await source.product_type_manager.add("book")) \ .set_category(await source.category_manager.add("adrenalin")) \ .set_author(sample_author) \ .set_cover(sample_cover) \ .result() await sample_item.save() new_proxy = await source.item_proxy(sample_item) \ .add_attachment(sample_attachment) await new_proxy.result().save() print(repr(new_proxy.result())) await tortoise.Tortoise.close_connections() asyncio.run(main())