def test_render_GET_RTLlang(self): """Test rendering a request for plain bridges in Arabic.""" if 'ar' not in _langs.get_langs(): self.skipTest("'ar' language unsupported") self.useBenignBridges() request = DummyRequest([b"bridges?transport=obfs3"]) request.method = b'GET' request.getClientIP = lambda: '3.3.3.3' # For some strange reason, the 'Accept-Language' value *should not* be # a list, unlike all the other headers and args… request.headers.update({'accept-language': 'ar,en,en_US,'}) page = self.bridgesResource.render(request) self.assertSubstring(b"rtl.css", page) self.assertSubstring( # "I need an alternative way to get bridges!" "أحتاج إلى وسيلة بديلة للحصول على bridges".encode("utf-8"), page) for bridgeLine in self.parseBridgesFromHTMLPage(page): # Check that each bridge line had the expected number of fields: bridgeLine = bridgeLine.split(' ') self.assertEqual(len(bridgeLine), 2)
def getSupportedLangs(): """Return all supported languages. :rtype: set :returns: A set of language locales, e.g.: set(['el', 'eo', ..., ]). """ return _langs.get_langs()
def test_HowtoResource_render_GET_lang_ru(self): """renderGet() with ?lang=ru should return the howto page in Russian.""" if 'ru' not in _langs.get_langs(): self.skipTest("'ru' language unsupported") request = DummyRequest([self.pagename]) request.method = b'GET' request.addArg(b'lang', 'ru') page = self.howtoResource.render_GET(request) self.assertSubstring("Как использовать мосты".encode("utf-8"), page)
def test_IndexResource_render_GET_lang_ta(self): """renderGet() with ?lang=ta should return the index page in Tamil.""" if 'ta' not in _langs.get_langs(): self.skipTest("'ta' language unsupported") request = DummyRequest([self.pagename]) request.method = b'GET' request.addArg(b'lang', 'ta') page = self.indexResource.render_GET(request) self.assertSubstring("bridge-களை Tor Browser-உள்".encode("utf-8"), page)
def getFirstSupportedLang(langs): """Return the first language in **langs** that we support. :param list langs: All requested languages :rtype: str :returns: A country code for the client's preferred language. """ lang = 'en-US' supported = _langs.get_langs() for l in langs: if l in supported: lang = l break return lang
def getFirstSupportedLang(langs): """Return the first language in **langs** that we support. :param list langs: All requested languages :rtype: str :returns: A country code for the client's preferred language. """ lang = 'en-US' supported = _langs.get_langs() for l in langs: if l in supported: lang = l break return lang
def test_render_GET_RTLlang(self): """Test rendering a request for obfs3 bridges in Hebrew.""" if 'he' not in _langs.get_langs(): self.skipTest("'ar' language unsupported") request = DummyRequest(["bridges?transport=obfs3"]) request.method = b'GET' request.getClientIP = lambda: '3.3.3.3' request.headers.update({'accept-language': 'he'}) # We actually have to set the request args manually when using a # DummyRequest: request.args.update({'transport': ['obfs2']}) page = self.optionsResource.render(request) self.assertSubstring(b"rtl.css", page) self.assertSubstring("מהם גשרים?".encode("utf-8"), page)
def getFirstSupportedLang(langs): """Return the first language in **langs** that we support. :param list langs: All requested languages :rtype: str :returns: A country code for the client's preferred language. """ lang = 'en-US' supported = _langs.get_langs() for l in langs: if l in supported: lang = l break # crop locales (like 'en-US') to just the language return lang.split('-')[0]
def test_render_GET_RTLlang_obfs3(self): """Test rendering a request for obfs3 bridges in Farsi.""" if 'fa' not in _langs.get_langs(): self.skipTest("'ar' language unsupported") self.useBenignBridges() request = DummyRequest([b"bridges?transport=obfs3"]) request.method = b'GET' request.getClientIP = lambda: '3.3.3.3' request.headers.update({'accept-language': 'fa,en,en_US,'}) # We actually have to set the request args manually when using a # DummyRequest: request.args.update({'transport': ['obfs3']}) page = self.bridgesResource.render(request) self.assertSubstring(b"rtl.css", page) self.assertSubstring( # "How to use the above bridge lines" (since there should be # bridges in this response, we don't tell them about alternative # mechanisms for getting bridges) "چگونگی از پلهای خود استفاده کنید".encode("utf-8"), page) for bridgeLine in self.parseBridgesFromHTMLPage(page): # Check that each bridge line had the expected number of fields: bridgeLine = bridgeLine.split(' ') self.assertEqual(len(bridgeLine), 3) self.assertEqual(bridgeLine[0], 'obfs3') # Check that the IP and port seem okay: ip, port = bridgeLine[1].rsplit(':') self.assertIsInstance(ipaddress.ip_address(ip), ipaddress.IPv4Address) self.assertIsInstance(int(port), int) self.assertGreater(int(port), 0) self.assertLessEqual(int(port), 65535)
def test_usingRTLLang(self): self.assertFalse(translations.usingRTLLang(['foo_BAR'])) self.assertFalse(translations.usingRTLLang(['en'])) if 'fa' in _langs.get_langs(): self.assertTrue(translations.usingRTLLang(['fa']))