Ferran Pegueroles avatar Ferran Pegueroles committed c7e7d99

Full test coverage of library

Comments (0)

Files changed (3)

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
         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)
 

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()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.