test_client.py 1004 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import os
  2. import unittest
  3. from mock import call, MagicMock, patch
  4. from yarg import get, HTTPError
  5. class GoodResponse(object):
  6. status_code = 200
  7. package = os.path.join(os.path.dirname(__file__),
  8. 'package.json')
  9. content = open(package).read()
  10. class BadResponse(object):
  11. status_code = 300
  12. reason = "Mocked"
  13. class TestClient(unittest.TestCase):
  14. @patch('requests.get', return_value=BadResponse)
  15. def test_get(self, get_mock):
  16. # Python 2.6....
  17. try:
  18. get("test")
  19. except HTTPError as e:
  20. self.assertEqual(300, e.status_code)
  21. self.assertEqual(e.status_code, e.errno)
  22. self.assertEqual(e.reason, e.message)
  23. @patch('requests.get', return_value=GoodResponse)
  24. def test_end_slash(self, get_mock):
  25. get("test", pypi_server="https://mock.test.mock/test")
  26. self.assertEqual(call('https://mock.test.mock/test/test/json'),
  27. get_mock.call_args)