Пример #1
0
 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)
Пример #2
0
    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)")
Пример #3
0
 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
         )
Пример #4
0
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))
Пример #6
0
    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)
Пример #7
0
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
        )
Пример #8
0
    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=")
Пример #9
0
    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)
Пример #10
0
    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=")
Пример #11
0
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')
Пример #12
0
 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))
Пример #13
0
 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))
Пример #14
0
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'
        )
Пример #15
0
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)
Пример #16
0
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)