007-category.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import sys
  2. import pathlib
  3. test_file = pathlib.Path(__file__)
  4. project = test_file.parent.parent
  5. sys.path.append(str(project))
  6. import server_source as source
  7. from test import test
  8. import asyncio
  9. import tortoise
  10. async def main():
  11. modules = {
  12. source.model.Meta.app: [ "server_source" ]
  13. }
  14. await tortoise.Tortoise.init(
  15. db_url = "sqlite://:memory:",
  16. modules = modules
  17. )
  18. await tortoise.Tortoise.generate_schemas()
  19. books = source.category.get_proxy().create("books").result()
  20. await books.save()
  21. test(str(books), "books")
  22. test(len(await source.category_manager.all()), 1)
  23. loaded_books = await source.category_manager.add("books")
  24. test(len(await source.category_manager.all()), 1)
  25. games = await source.category_manager.add("games")
  26. test(len(await source.category_manager.all()), 2)
  27. await source.category_manager.clean("books")
  28. test(len(await source.category_manager.all()), 1)
  29. await tortoise.Tortoise.close_connections()
  30. asyncio.run(main())