def setUp(self): self.host = "abc.com" self.port = 80 self.api_path = "/v1/" self.path_list = ['test', 'more', 'test'] self.complete_path = "/v1/test/more/test" self.ws = MagicMock(auto_spec=WebService) self.api = APIHelper(self.host, self.port, self.api_path, self.ws)
class APITest(PicardTestCase): def setUp(self): super().setUp() self.host = "abc.com" self.port = 80 self.api_path = "/v1/" self.path_list = ['test', 'more', 'test'] self.complete_path = "/v1/test/more/test" self.ws = MagicMock(auto_spec=WebService) self.api = APIHelper(self.host, self.port, self.api_path, self.ws) def _test_ws_function_args(self, ws_function): self.assertGreater(ws_function.call_count, 0) self.assertEqual(ws_function.call_args[0][0], self.host) self.assertEqual(ws_function.call_args[0][1], self.port) self.assertEqual(ws_function.call_args[0][2], self.complete_path) def test_get(self): self.api.get(self.path_list, None) self._test_ws_function_args(self.ws.get) def test_post(self): self.api.post(self.path_list, None, None) self._test_ws_function_args(self.ws.post) def test_put(self): self.api.put(self.path_list, None, None) self._test_ws_function_args(self.ws.put) def test_delete(self): self.api.delete(self.path_list, None) self._test_ws_function_args(self.ws.delete)
class APITest(unittest.TestCase): def setUp(self): self.host = "abc.com" self.port = 80 self.api_path = "/v1/" self.path_list = ['test', 'more', 'test'] self.complete_path = "/v1/test/more/test" self.ws = MagicMock(auto_spec=WebService) self.api = APIHelper(self.host, self.port, self.api_path, self.ws) def _test_ws_function_args(self, ws_function): self.assertGreater(ws_function.call_count, 0) self.assertEqual(ws_function.call_args[0][0], self.host) self.assertEqual(ws_function.call_args[0][1], self.port) self.assertEqual(ws_function.call_args[0][2], self.complete_path) def test_get(self): self.api.get(self.path_list, None) self._test_ws_function_args(self.ws.get) def test_post(self): self.api.post(self.path_list, None, None) self._test_ws_function_args(self.ws.post) def test_put(self): self.api.put(self.path_list, None, None) self._test_ws_function_args(self.ws.put) def test_delete(self): self.api.delete(self.path_list, None) self._test_ws_function_args(self.ws.delete)