def test_post_and_confirm_status_empty_data(self, _post): mock_response = mock.Mock() _post.return_value = mock_response req = Requester('foo', 'bar') with self.assertRaises(AssertionError) as ae: req.post_and_confirm_status(url='http://dummy', params={'param': 'value'}, data=None)
def test_post_and_confirm_status_empty_data(self, _post): _post.return_value = 'SUCCESS' req = Requester('foo', 'bar') with self.assertRaises(AssertionError) as ae: req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data=None) self.assertTrue(ae.exception.message=="Unexpected type of parameter 'data': <type 'NoneType'>. Expected (str, dict)")
def test_post_and_confirm_status_empty_data(self, _post): mock_response = mock.Mock() _post.return_value = mock_response req = Requester('foo', 'bar') with self.assertRaises(AssertionError) as ae: req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data=None )
def test_post_and_confirm_status_empty_data(monkeypatch): def fake_post(*args, **kwargs): # pylint: disable=unused-argument return 'SUCCESS' monkeypatch.setattr(requests, 'post', fake_post) req = Requester('foo', 'bar') with pytest.raises(AssertionError): req.post_and_confirm_status(url='http://dummy', params={'param': 'value'}, data=None)
def test_post_and_confirm_status_empty_data(self, _post): _post.return_value = 'SUCCESS' req = Requester('foo', 'bar') with self.assertRaises(AssertionError) as ae: req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data=None ) self.assertTrue(str(ae.exception) == "Unexpected type of parameter 'data': %s. Expected (str, dict)" % type(None))
def test_post_and_confirm_status_bad_result(self, _post): response = requests.Response() response.status_code = 500 _post.return_value = response req = Requester('foo', 'bar') with self.assertRaises(JenkinsAPIException) as ae: req.post_and_confirm_status(url='http://dummy', params={'param': 'value'}, data='some data') self.assertIsInstance(ae.exception, JenkinsAPIException)
def test_post_and_confirm_status_empty_data(monkeypatch): def fake_post(*args, **kwargs): # pylint: disable=unused-argument return 'SUCCESS' monkeypatch.setattr(requests, 'post', fake_post) req = Requester('foo', 'bar') with pytest.raises(AssertionError): req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data=None )
def test_post_and_confirm_status_bad_result(self, _post): response = requests.Response() response.status_code = 500 _post.return_value = response req = Requester('foo', 'bar') with self.assertRaises(JenkinsAPIException) as ae: req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data='some data') print ae.exception.message self.assertTrue(ae.exception.message=="Operation failed. url=None, data=some data, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=500, text=")
def test_post_and_confirm_status_bad_result(self, _post): response = requests.Response() response.status_code = 500 _post.return_value = response req = Requester('foo', 'bar') with self.assertRaises(JenkinsAPIException) as ae: req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data='some data' ) self.assertIsInstance(ae.exception, JenkinsAPIException)
def test_post_and_confirm_status_bad_result(self, _post): response = requests.Response() response.status_code = 500 _post.return_value = response req = Requester('foo', 'bar') with self.assertRaises(JenkinsAPIException) as ae: req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data='some data' ) print ae.exception.message self.assertTrue(ae.exception.message == "Operation failed. url=None, data=some data, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=500, text=")
def test_post_and_confirm_status_bad_result(monkeypatch): class FakeResponse(object): def __init__(self, *args, **kwargs): # pylint: disable=unused-argument self.status_code = 500 self.url = 'http://dummy' self.text = 'something' def fake_post(*args, **kwargs): # pylint: disable=unused-argument return FakeResponse() monkeypatch.setattr(requests, 'post', fake_post) req = Requester('foo', 'bar') with pytest.raises(JenkinsAPIException): req.post_and_confirm_status(url='http://dummy', params={'param': 'value'}, data='some data')
def test_post_and_confirm_status_some_data(self, _post): response = requests.Response() response.status_code = 200 _post.return_value = response req = Requester('foo', 'bar') ret = req.post_and_confirm_status(url='http://dummy', params={'param': 'value'}, data='some data') self.assertTrue(isinstance(ret, requests.Response))
def test_post_and_confirm_status_some_data(self, _post): response = requests.Response() response.status_code = 200 _post.return_value = response req = Requester('foo', 'bar') ret = req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data='some data') self.assertTrue(isinstance(ret, requests.Response))
def test_post_and_confirm_status_bad_result(monkeypatch): class FakeResponse(object): def __init__(self, *args, **kwargs): # pylint: disable=unused-argument self.status_code = 500 self.url = 'http://dummy' self.text = 'something' def fake_post(*args, **kwargs): # pylint: disable=unused-argument return FakeResponse() monkeypatch.setattr(requests, 'post', fake_post) req = Requester('foo', 'bar') with pytest.raises(JenkinsAPIException): req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data='some data' )
def test_post_and_confirm_status_some_data(monkeypatch): class FakeResponse(requests.Response): def __init__(self, *args, **kwargs): # pylint: disable=unused-argument self.status_code = 200 def fake_post(*args, **kwargs): # pylint: disable=unused-argument return FakeResponse() monkeypatch.setattr(requests, 'post', fake_post) req = Requester('foo', 'bar') ret = req.post_and_confirm_status(url='http://dummy', params={'param': 'value'}, data='some data') assert isinstance(ret, requests.Response)
def test_post_and_confirm_status_some_data(monkeypatch): class FakeResponse(requests.Response): def __init__(self, *args, **kwargs): # pylint: disable=unused-argument self.status_code = 200 def fake_post(*args, **kwargs): # pylint: disable=unused-argument return FakeResponse() monkeypatch.setattr(requests, 'post', fake_post) req = Requester('foo', 'bar') ret = req.post_and_confirm_status( url='http://dummy', params={'param': 'value'}, data='some data' ) assert isinstance(ret, requests.Response)