Ferran Pegueroles avatar Ferran Pegueroles committed 48ee8bb Draft

Use autospec for test mocking

Comments (0)

Files changed (3)

 cover-html=1
 cover-erase=1
 cover-tests=1
-cover-package=peerreach
-cover-package=peerreach.tests
+cover-package=peerreach,tests
 cover-inclusive=1
 cover-branches=1

tests/test_peerreach.py

 
         self.assertEqual(data, json.loads(raw))
 
-    @mock.patch("requests.get")
+    @mock.patch("requests.get", autospec=True)
     def test_get_data(self, get):
 
         class Response:
         self.assertEqual(data, json.loads(Response().text))
         get.assert_called_once_with(test_url)
 
-    @mock.patch("requests.get")
+    @mock.patch("requests.get", autospec=True)
     def test_get_data_error(self, get):
 
         class Response:

tests/test_runner.py

 
 class TestRunner(TestCase):
 
-    @mock.patch("peerreach.runner.Api")
+    @mock.patch("peerreach.runner.Api", autospec=True)
     def test_main_screen_name(self, Api):
 
         Api().user_lookup.return_value = {"a": "b"}
 
         Api().user_lookup.assert_called_once_with(screen_name="test_user")
 
-    @mock.patch("peerreach.runner.Api")
+    @mock.patch("peerreach.runner.Api", autospec=True)
     def test_main_user_id(self, Api):
 
         Api().user_lookup.return_value = {"a": "b"}
 
         Api().user_lookup.assert_called_once_with(user_id='11111')
 
-    @mock.patch("peerreach.runner.Api")
+    @mock.patch("peerreach.runner.Api", autospec=True)
     def test_main_screen_names(self, Api):
 
         Api().multi_user_lookup.return_value = {"a": "b"}
         Api().multi_user_lookup.assert_called_once_with(
                             screen_names=["test_user1", "test_user2"])
 
-    @mock.patch("peerreach.runner.Api")
+    @mock.patch("peerreach.runner.Api", autospec=True)
     def test_main_user_ids(self, Api):
 
         Api().multi_user_lookup.return_value = {"a": "b"}
         Api().multi_user_lookup.assert_called_once_with(
                             user_ids=["11111", "22222"])
 
-    @mock.patch("peerreach.runner.Api")
+    @mock.patch("peerreach.runner.Api", autospec=True)
     def test_main_not_raw(self, Api):
 
         Api.return_value.user_lookup.return_value = {"a": "b"}
         args, kwargs = Api.call_args
         self.assertTrue(isinstance(kwargs['parser'], JSONParser))
 
-    @mock.patch("peerreach.runner.Api")
+    @mock.patch("peerreach.runner.Api", autospec=True)
     def test_main_raw(self, Api):
 
         Api.return_value.user_lookup.return_value = '{"a": "b"}'
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.