def test_web_connectivity_client_is_not_reachable(self): wcc = WebConnectivityClient( 'https://web-connectivity.th.ooni.io') wcc.queryBackend = MagicMock() wcc.queryBackend.return_value = defer.fail(Exception()) result = yield wcc.isReachable() self.assertEqual(result, False)
def test_web_connectivity_client_is_reachable(self): wcc = WebConnectivityClient( 'https://web-connectivity.th.ooni.io') wcc.queryBackend = MagicMock() wcc.queryBackend.return_value = defer.succeed({"status": "ok"}) result = yield wcc.isReachable() self.assertEqual(result, True)
def getReachableTestHelper(self, test_helper_name, test_helper_address, test_helper_alternate): # For the moment we look for alternate addresses only of # web_connectivity test helpers. if test_helper_name == 'web-connectivity': for web_connectivity_settings in self.sortAddressesByPriority( test_helper_address, test_helper_alternate): web_connectivity_test_helper = WebConnectivityClient( settings=web_connectivity_settings) if not web_connectivity_test_helper.isSupported(): log.err("Unsupported %s web_connectivity test_helper " "%s" % ( web_connectivity_settings['type'], web_connectivity_settings['address'] )) continue reachable = yield web_connectivity_test_helper.isReachable() if not reachable: log.err("Unreachable %s web_connectivity test helper %s" % ( web_connectivity_settings['type'], web_connectivity_settings['address'] )) continue defer.returnValue(web_connectivity_settings) raise e.NoReachableTestHelpers else: defer.returnValue(test_helper_address.encode('ascii'))
def getReachableTestHelper(self, test_helper_name, test_helper_address, test_helper_alternate): # For the moment we look for alternate addresses only of # web_connectivity test helpers. if test_helper_name == 'web-connectivity': for web_connectivity_settings in self.sortAddressesByPriority( test_helper_address, test_helper_alternate): web_connectivity_test_helper = WebConnectivityClient( settings=web_connectivity_settings) if not web_connectivity_test_helper.isSupported(): log.err("Unsupported %s web_connectivity test_helper " "%s" % (web_connectivity_settings['type'], web_connectivity_settings['address'])) continue reachable = yield web_connectivity_test_helper.isReachable() if not reachable: log.err("Unreachable %s web_connectivity test helper %s" % (web_connectivity_settings['type'], web_connectivity_settings['address'])) continue defer.returnValue(web_connectivity_settings) raise e.NoReachableTestHelpers else: defer.returnValue(test_helper_address.encode('ascii'))
def test_web_connectivity_client_is_not_reachable(self): wcc = WebConnectivityClient('https://web-connectivity.th.ooni.io') wcc.queryBackend = MagicMock() wcc.queryBackend.return_value = defer.fail(Exception()) result = yield wcc.isReachable() self.assertEqual(result, False)
def test_web_connectivity_client_is_reachable(self): wcc = WebConnectivityClient('https://web-connectivity.th.ooni.io') wcc.queryBackend = MagicMock() wcc.queryBackend.return_value = defer.succeed({"status": "ok"}) result = yield wcc.isReachable() self.assertEqual(result, True)