test_models.py 933 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. import json
  3. import logging
  4. import unittest
  5. from webserver import models
  6. class TestUser(unittest.TestCase):
  7. def test_shrink_extra_size(self):
  8. n = 1024
  9. a = models.Reader()
  10. a.extra = {}
  11. a.extra["download_history"] = [{"id": 123, "title": "name", "timestamp": 1643347670}] * n
  12. a.shrink_column_extra()
  13. self.assertLess(len(json.dumps(a.extra)), 32 * 1024)
  14. def test_shrink_extra_size2(self):
  15. n = 200
  16. a = models.Reader()
  17. a.extra = {}
  18. a.extra["download_history"] = [{"id": 123, "title": "name", "timestamp": 1643347670}] * n
  19. a.shrink_column_extra()
  20. # should not shrink
  21. self.assertEqual(len(a.extra["download_history"]), n)
  22. if __name__ == "__main__":
  23. logging.basicConfig(
  24. level=logging.DEBUG,
  25. format="%(levelname)5s %(pathname)s:%(lineno)d %(message)s",
  26. )
  27. unittest.main()