class DispatcherTests(TestCase): url = "http://test.com" login = "******" password = "******" def setUp(self): self.dispatcher = ApiDispatcher(self.url) @parameterized.expand([("GET",), ("POST",), ("DELETE",), ("PATCH",), ("PUT",)]) @mock.patch("api.core.requests") def test_requests(self, method, requests_mock): mock_method = getattr(requests_mock, method.lower()) mock_method.return_value = MockResponse({}, 200) self.dispatcher.make_request(method, "/test", model=mock.MagicMock(ModelBase)) self.assertTrue(mock_method.called) self.assertIn(self.url + "/test", mock_method.call_args[0]) @mock.patch("api.core.requests") def test_with_arguments(self, requests_mock): requests_mock.get.return_value = MockResponse({}, 200) args = {"arg1": "1", "arg2": "2"} self.dispatcher.add_additional_params(**args) self.dispatcher.make_request("GET", "/test", model=mock.MagicMock(ModelBase)) for name, val in args.iteritems(): self.assertIn(name, requests_mock.get.call_args[1]) self.assertEqual(val, requests_mock.get.call_args[1][name])
def setUp(self): self.dispatcher = ApiDispatcher(self.url)