def test_user_proxy(self): request(self.method, sentinel.url, sentinel.username, sentinel.password, kwarg=sentinel.kwvalue) self.method.assert_called_once_with(sentinel.url, auth=(sentinel.username, sentinel.password), kwarg=sentinel.kwvalue)
def test_insecure_platform_message_is_printed(self): _reset_platform_warning() self.method.side_effect = self._warn_and_respond(InsecurePlatformWarning) buff = six.StringIO() sys.stdout = buff try: request(self.method, sentinel.url) finally: sys.stdout = sys.__stdout__ self.assertIn('Got an InsecurePlatformWarning. Upgrade python to 2.7.9 or better to remove.', buff.getvalue())
def test_insecure_platform_is_supresed(self): _reset_platform_warning() self.method.side_effect = self._warn_and_respond(InsecurePlatformWarning) with warnings.catch_warnings(record=True) as warns: response = request(self.method, sentinel.url) eq_(warns, []) eq_(response, self.response)
def test_not_all_warnings_are__supresed(self): _reset_platform_warning() self.method.side_effect = self._warn_and_respond(Warning, 'warning_message') with warnings.catch_warnings(record=True) as warns: response = request(self.method, sentinel.url) eq_(len(warns), 1) self.assertIn('warning_message', str(warns[0])) eq_(response, self.response)
def test_exception_contains_response(self): self.response.status_code = 500 try: request(self.method, sentinel.url) except NotOkResponse as err: eq_(err.response, self.response)
def test_server_error_fails(self): self.response.status_code = 500 request(self.method, sentinel.url)
def test_not_found_fails(self): self.response.status_code = 404 request(self.method, sentinel.url)
def test_no_user_proxy(self): response = request(self.method, sentinel.url, kwarg=sentinel.kwvalue) self.method.assert_called_once_with(sentinel.url, kwarg=sentinel.kwvalue) eq_(response, self.response)