test_api.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. from proxypool.api import app
  8. class ApiTestCase(unittest.TestCase):
  9. def setUp(self):
  10. self._app = app.test_client()
  11. self._conn = RedisClient()
  12. def tearDown(self):
  13. self._conn.flush()
  14. def test_get(self):
  15. self._conn.put('aaa')
  16. self._conn.put('bbb')
  17. r = self._app.get('/get')
  18. assert 'aaa' in str(r.data)
  19. r = self._app.get('/get')
  20. assert 'bbb' in str(r.data)
  21. def test_count(self):
  22. self._conn.put('aaa')
  23. self._conn.put('bbb')
  24. r = self._app.get('/count')
  25. assert '2' in str(r.data)
  26. self._conn.put('ccc')
  27. self._conn.put('ddd')
  28. r = self._app.get('/count')
  29. assert '4' in str(r.data)
  30. proxy = self._conn.pop()
  31. r = self._app.get('/count')
  32. assert '3' in str(r.data)
  33. if __name__ == '__main__':
  34. unittest.main()