| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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
- def prepare_dir() -> pathlib.Path:
- test = pathlib.Path(__file__).parent
- resources = test / pathlib.Path("test_resources")
- if not resources.exists() or not resources.is_dir():
- resources.mkdir()
-
- for count in resources.iterdir():
- if count.is_file():
- count.unlink()
- return resources
- 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()
- content = "IyBVd1UKICogRmlyc3QgcG9pbnQKICogU2Vjb25kIHBvaW50Cg=="
- manager = source.attachments_manager(prepare_dir())
- proxy = await manager.upload(content, "md")
- attachment = proxy \
- .set_name("sample_file") \
- .set_description("This describe it.") \
- .result()
- print("Attachment before insert to DB:")
- print(repr(attachment))
- print()
- await attachment.save()
-
- print("Attachment after inserting to DB:")
- print(repr(attachment))
- print()
- readed = await manager.restore(attachment).load()
- print("Data loaded from Base64:")
- print("\"\"\"")
- print(readed.decode("UTF-8"))
- print("\"\"\"")
- print()
- await tortoise.Tortoise.close_connections()
- asyncio.run(main())
|