def test_050(self): """HTTP GET against http://some.bogus.address/ raises ConnectionError""" s = session.Session('http://some.bogus.address') logger = logging.getLogger() with d1_common.logging_context.LoggingContext(logger): logger.setLevel(logging.ERROR) self.assertRaises(requests.exceptions.ConnectionError, s.GET, '/')
def _post(self, query_dict, header_dict, body): mock_post.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL) s = session.Session( d1_test.d1_test_case.MOCK_MN_BASE_URL, query={ 'default_query': 'test', } ) return s.POST(['post'], query=query_dict, headers=header_dict, data=body)
def _post(self, query_dict, header_dict, body): s = session.Session(shared_settings.MN_RESPONSES_URL, query={ 'default_query': 'test', }) return s.POST(['post'], query=query_dict, headers=header_dict, data=body)
def test_1070(self): """cURL command line retains query parameters and headers""" query_dict = {'abcd': '1234', 'efgh': '5678'} header_dict = {'ijkl': '9876', 'mnop': '5432'} s = session.Session(d1_test.d1_test_case.MOCK_MN_BASE_URL) curl_str = s.get_curl_command_line( 'POST', 'http://some.bogus.address', query=query_dict, headers=header_dict, ) d1_test.sample.assert_equals(curl_str, 'curl_command_line')
def test_1070(self): """cURL command line retains query parameters and headers""" query_dict = {'abcd': '1234', 'efgh': '5678'} header_dict = {'ijkl': '9876', 'mnop': '5432'} s = session.Session(d1_test.d1_test_case.MOCK_BASE_URL) curl_str = s.get_curl_command_line( 'POST', 'http://some.bogus.address', query=query_dict, headers=header_dict, ) assert curl_str == \ 'curl -X POST -H "ijkl: 9876" -H "mnop: 5432" http://some.bogus.address?abcd=1234&efgh=5678'
def test_200(self): """cURL command line retains query parameters and headers""" query_dict = {'abcd': '1234', 'efgh': '5678'} header_dict = {'ijkl': '9876', 'mnop': '5432'} s = session.Session(shared_settings.MN_RESPONSES_URL) curl_str = s.get_curl_command_line( 'POST', 'http://some.bogus.address', query=query_dict, headers=header_dict, ) self.assertEqual( curl_str, 'curl -X POST -H "ijkl: 9876" -H "mnop: 5432" http://some.bogus.address?abcd=1234&efgh=5678', )
def _post_fields(self, fields_dict): mock_post.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL) s = session.Session(d1_test.d1_test_case.MOCK_MN_BASE_URL) return s.POST(['post'], fields=fields_dict)
def _get_response(self, pid, header_dict=None): mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL) s = session.Session(d1_test.d1_test_case.MOCK_MN_BASE_URL) return s.GET(['object', pid], headers=header_dict or {})
def _get_hash(self, pid): mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL) s = session.Session(d1_test.d1_test_case.MOCK_MN_BASE_URL) response = s.GET(['object', pid]) return hashlib.sha1(response.content).hexdigest()
def _post_fields(self, fields_dict): s = session.Session(shared_settings.MN_RESPONSES_URL) return s.POST(['post'], fields=fields_dict)
def _get_response(self, pid): s = session.Session(shared_settings.MN_RESPONSES_URL) return s.GET(['object', pid])
def _get_hash(self, pid): s = session.Session(shared_settings.MN_RESPONSES_URL) response = s.GET(['object', pid]) return hashlib.sha1(response.content).hexdigest()