|
7 | 7 |
|
8 | 8 | from kitsune.flagit.models import FlaggedObject |
9 | 9 | from kitsune.products.models import ProductSupportConfig |
10 | | -from kitsune.products.tests import ProductFactory, ProductSupportConfigFactory, TopicFactory |
| 10 | +from kitsune.products.tests import ( |
| 11 | + ProductFactory, |
| 12 | + ProductSupportConfigFactory, |
| 13 | + TopicFactory, |
| 14 | + ZendeskConfigFactory, |
| 15 | +) |
11 | 16 | from kitsune.questions.models import ( |
12 | 17 | AAQConfig, |
13 | 18 | Answer, |
@@ -43,7 +48,7 @@ def test_ratelimit(self): |
43 | 48 | product=p, |
44 | 49 | forum_config=aaq_config, |
45 | 50 | is_active=True, |
46 | | - default_support_type=ProductSupportConfig.SUPPORT_TYPE_FORUM |
| 51 | + default_support_type=ProductSupportConfig.SUPPORT_TYPE_FORUM, |
47 | 52 | ) |
48 | 53 | topic = TopicFactory(slug="troubleshooting", products=[p], in_aaq=True) |
49 | 54 | data = { |
@@ -99,7 +104,7 @@ def setUp(self): |
99 | 104 | product=product, |
100 | 105 | forum_config=aaq_config, |
101 | 106 | is_active=True, |
102 | | - default_support_type=ProductSupportConfig.SUPPORT_TYPE_FORUM |
| 107 | + default_support_type=ProductSupportConfig.SUPPORT_TYPE_FORUM, |
103 | 108 | ) |
104 | 109 |
|
105 | 110 | def test_non_authenticated_user(self): |
@@ -138,6 +143,68 @@ def test_authenticated_user(self): |
138 | 143 | assert template_used(response, "questions/new_question.html") |
139 | 144 |
|
140 | 145 |
|
| 146 | +class AAQZendeskRedirectLocaleTests(TestCase): |
| 147 | + """Tests that the Zendesk redirect preserves the original locale for the community switcher.""" |
| 148 | + |
| 149 | + def setUp(self): |
| 150 | + self.product = ProductFactory(title="Firefox", slug="firefox") |
| 151 | + en_locale, _ = QuestionLocale.objects.get_or_create(locale="en-US") |
| 152 | + fr_locale, _ = QuestionLocale.objects.get_or_create(locale="fr") |
| 153 | + aaq_config = AAQConfigFactory( |
| 154 | + product=self.product, |
| 155 | + enabled_locales=[en_locale, fr_locale], |
| 156 | + is_active=True, |
| 157 | + ) |
| 158 | + ProductSupportConfigFactory( |
| 159 | + product=self.product, |
| 160 | + forum_config=aaq_config, |
| 161 | + zendesk_config=ZendeskConfigFactory(), |
| 162 | + is_active=True, |
| 163 | + default_support_type=ProductSupportConfig.SUPPORT_TYPE_ZENDESK, |
| 164 | + ) |
| 165 | + self.user = UserFactory(is_superuser=False) |
| 166 | + self.client.login(username=self.user.username, password="testpass") |
| 167 | + |
| 168 | + def test_zendesk_redirect_includes_from_locale(self): |
| 169 | + """When a non-English user hits the Zendesk form, the redirect includes from_locale.""" |
| 170 | + url = reverse("questions.aaq_step3", locale="fr", args=["firefox"]) |
| 171 | + response = self.client.get(url) |
| 172 | + self.assertEqual(response.status_code, 302) |
| 173 | + self.assertIn("from_locale=fr", response["Location"]) |
| 174 | + |
| 175 | + def test_localized_forum_link_set_when_forum_enabled(self): |
| 176 | + """When from_locale differs from current locale and the forum supports it, |
| 177 | + a localized forum link appears in the switcher widget.""" |
| 178 | + url = reverse("questions.aaq_step3", locale="en-US", args=["firefox"]) |
| 179 | + response = self.client.get(url, {"from_locale": "fr"}) |
| 180 | + self.assertEqual(response.status_code, 200) |
| 181 | + doc = pq(response.content) |
| 182 | + # The widget is rendered twice (sidebar + inline), so expect 2 links. |
| 183 | + links = doc(".switcher-actions a:not(.sumo-button)") |
| 184 | + self.assertEqual(len(links), 2) |
| 185 | + for link in links.items(): |
| 186 | + self.assertIn("/fr/questions/new/firefox/form", link.attr("href")) |
| 187 | + self.assertIn(settings.LANGUAGES_DICT["fr"], link.text()) |
| 188 | + |
| 189 | + def test_no_localized_forum_link_without_from_locale(self): |
| 190 | + """When from_locale is absent, no localized forum link appears.""" |
| 191 | + url = reverse("questions.aaq_step3", locale="en-US", args=["firefox"]) |
| 192 | + response = self.client.get(url) |
| 193 | + self.assertEqual(response.status_code, 200) |
| 194 | + doc = pq(response.content) |
| 195 | + links = doc(".switcher-actions a:not(.sumo-button)") |
| 196 | + self.assertEqual(len(links), 0) |
| 197 | + |
| 198 | + def test_no_localized_forum_link_for_unsupported_locale(self): |
| 199 | + """When from_locale is a locale the forum doesn't support, no localized link appears.""" |
| 200 | + url = reverse("questions.aaq_step3", locale="en-US", args=["firefox"]) |
| 201 | + response = self.client.get(url, {"from_locale": "de"}) |
| 202 | + self.assertEqual(response.status_code, 200) |
| 203 | + doc = pq(response.content) |
| 204 | + links = doc(".switcher-actions a:not(.sumo-button)") |
| 205 | + self.assertEqual(len(links), 0) |
| 206 | + |
| 207 | + |
141 | 208 | class TestQuestionUpdates(TestCase): |
142 | 209 | """Tests that questions are only updated in the right cases.""" |
143 | 210 |
|
|
0 commit comments