def test_with_weirder_prefix(self): activate('en-us') self.assertEqual(url_for_language('/en-us/about/', 'es'), '/es/about/') activate('es') self.assertEqual(url_for_language('/es/about/', 'es-mx'), '/es-mx/about/')
def test_translated_unnamed_urls(self): activate('en') url = reverse('tests.urls.unnamed_view', kwargs={'k1': 'foo'}) self.assertEqual(url, '/en/the-unnamed-url/foo/') self.assertEqual(url_for_language(url, 'es'), '/es/el-url-sin-nombre/foo/')
def test_translated_urls(self): activate('en') url = reverse('translated_url', kwargs={'k1': 'foo'}) self.assertEqual(url, '/en/the-url/foo/') self.assertEqual(url_for_language(url, 'es'), '/es/el-url/foo/')
def test_possible_false_positive(self): activate('en') self.assertEqual(url_for_language('/enable/', 'en'), '/en/enable/') self.assertEqual(url_for_language('/enable/', 'es'), '/es/enable/')
def test_with_host(self): activate('en') url = 'http://example.com/en/about/' self.assertEqual(url_for_language(url, 'es'), 'http://example.com/es/about/')
def test_with_language(self): activate('en') self.assertEqual(url_for_language('/en/about/', 'en'), '/en/about/') self.assertEqual(url_for_language('/en/about/', 'es'), '/es/about/')
def get_redirect_url(self, **kwargs): new_language = self.request.POST.get('language', None) url = self.get_next_url() return url_for_language(url, new_language)