def test_request_with_hosts_file(mock_request): ignition.set_default_hosts_file('.my_hosts_file') ignition.request('//test') mock_request.assert_called_once() _, cert_store, _, _, _, = _destructure_request_args(mock_request) assert cert_store.get_hosts_file() == '.my_hosts_file' mock_request.return_value.send.assert_called_once()
def test_request_with_default_timeout(mock_request): ignition.set_default_timeout(9) ignition.request('//test') mock_request.assert_called_once() _, _, request_timeout, _, _, = _destructure_request_args(mock_request) assert request_timeout == 9 mock_request.return_value.send.assert_called_once()
def test_request_with_overloaded_timeout(mock_request): ignition.set_default_timeout(8) ignition.request('//test', timeout=12) mock_request.assert_called_once() _, _, request_timeout, _, _, = _destructure_request_args(mock_request) assert request_timeout == 12 mock_request.send_assert_called_once()
def test_request(mock_request): ignition.request('//test') mock_request.assert_called_once() request_url, cert_store, request_timeout, referer, ca_cert = _destructure_request_args( mock_request) assert request_url == '//test' assert cert_store.get_hosts_file() == ignition.DEFAULT_HOSTS_FILE assert request_timeout == ignition.DEFAULT_REQUEST_TIMEOUT assert referer is None assert ca_cert is None mock_request.return_value.send.assert_called_once()
def test_request_with_values(mock_request): ignition.request('path', referer='//test', timeout=10, ca_cert='string') mock_request.assert_called_once() request_url, cert_store, request_timeout, referer, ca_cert = _destructure_request_args( mock_request) assert request_url == 'path' assert cert_store.get_hosts_file() == ignition.DEFAULT_HOSTS_FILE assert request_timeout == 10 assert referer == '//test' assert ca_cert == 'string' mock_request.return_value.send.assert_called_once()
def geminiRequest(self, url: str): # Run in the thread executor try: response = ignition.request(url) data = response.data() return response, data except Exception as err: log.debug(f'Gemini request error for URL {url}: {err}') return None, None
def bench_route(route): bench_times = list() last_time = time.perf_counter_ns() for i in range(0, 100): response = ig.request(f'//localhost:1966/{route}') current_time = time.perf_counter_ns() bench_times.append(current_time - last_time) last_time = current_time return bench_times
def run_integration(): print('Running integration tests...') for route, func in tests.items(): response = ig.request(f'//localhost:1966/{route}') passed, msg = func(response) if not passed: print(f'[{func.__name__}] failed ({route}): {msg}') sys.exit(-1) else: print(f'{func.__name__} passed ({route})')
''' This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ''' import ignition response1 = ignition.request('//gemini.circumlunar.space') response2 = ignition.request('software', referer=response1.url) print(response2)
''' This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ''' import ignition url = '//gemini.circumlunar.space' response = ignition.request(url) if response.is_a(ignition.SuccessResponse): print('Success!') print(response.data()) elif response.is_a(ignition.InputResponse): print('Needs additional input: %s' % (response.data())) elif response.is_a(ignition.RedirectResponse): print('Received response, redirect to: %s' % (response.data())) elif response.is_a(ignition.TempFailureResponse): print('Error from server: %s' % (response.data())) elif response.is_a(ignition.PermFailureResponse): print('Error from server: %s' % (response.data())) elif response.is_a(ignition.ClientCertRequiredResponse): print('Client certificate required. %s' % (response.data()))
''' This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ''' import ignition # Fetch capsule content response = ignition.request('//gemini.circumlunar.space') # Get status from remote capsule print(response.status) # Get response information from remote capsule print(response.data())