test_db.py 894 B

123456789101112131415161718192021222324252627282930313233343536
  1. import unittest
  2. import os
  3. import sys
  4. parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  5. sys.path.insert(0, parentdir)
  6. from proxypool.db import RedisClient
  7. class RedisClientTestCase(unittest.TestCase):
  8. def setUp(self):
  9. self._conn = RedisClient()
  10. def tearDown(self):
  11. self._conn.flush()
  12. def test_put_and_pop(self):
  13. self._conn.put("label")
  14. assert self._conn.pop() == "label"
  15. def test_put_many(self):
  16. self._conn.put_many(['a', 'b'])
  17. assert self._conn.pop() == "a"
  18. assert self._conn.pop() == "b"
  19. def test_len(self):
  20. self._conn.put_many(['a', 'b', 'c'])
  21. assert self._conn.queue_len == 3
  22. def test_get(self):
  23. self._conn.put_many(['a', 'b', 'c', 'd'])
  24. _ = self._conn.get(2)
  25. assert self._conn.queue_len == 2
  26. if __name__ == '__main__':
  27. unittest.main()