Commits

Ferran Pegueroles  committed c7e7d99

Full test coverage of library

  • Participants
  • Parent commits 347e591

Comments (0)

Files changed (3)

File peerreach/__init__.py

 
 __version__ = "0.1"
 
-from .api import Api, TooMuchArgsException,  NoArgsException
+from .api import Api
+from .api import TooMuchArgsException,  NoArgsException, HttpError
 from .parsers import RawParser, JSONParser, ObjectParser

File peerreach/api.py

         response = requests.get(url, **options)
 
         if str(response.status_code)[0] != '2':
-            raise HttpError(response.status)
+            raise HttpError(response.status_code)
 
         return self.parse(response.text)
 

File tests/test_peerreach.py

 
 from peerreach import Api
 from peerreach import JSONParser, RawParser, ObjectParser
-from peerreach import TooMuchArgsException, NoArgsException
+from peerreach import TooMuchArgsException, NoArgsException, HttpError
 
 
 class TestParser(TestCase):
         self.assertEqual(data, json.loads(Response().text))
         get.assert_called_once_with(test_url)
 
+    @mock.patch("requests.get")
+    def test_get_data_error(self, get):
+
+        class Response:
+            status_code = 500
+            text = '{"data": "test response"}'
+
+        get.return_value = Response()
+
+        api = Api()
+
+        test_url = "http://test"
+
+        self.assertRaises(HttpError, api.get_data, test_url)
+
     def test_user_lookup_user_id(self):
         api = DummyApi()