Skip to content

Commit c473f09

Browse files
committed
Adjust project name in login view for chatbot route
The login view now removes 'with IBM watsonx Code Assistant' from the project name when the 'next' parameter is '/chatbot' or '/chatbot/'. Tests were added to verify this behavior and ensure the project name remains unchanged in other cases.
1 parent ec005be commit c473f09

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

ansible_ai_connect/main/tests/test_views.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,55 @@ class MockUser:
151151
self.assertEqual(response.url, "/")
152152

153153

154+
class LoginViewProjectNameTest(TestCase):
155+
@override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible Lightspeed with IBM watsonx Code Assistant")
156+
def test_project_name_unchanged_without_next(self):
157+
request = RequestFactory().get("/login")
158+
request.user = AnonymousUser()
159+
response = LoginView.as_view()(request)
160+
response.render()
161+
contents = response.content.decode()
162+
self.assertIn("Log in to Ansible Lightspeed with IBM watsonx Code Assistant", contents)
163+
164+
@override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible Lightspeed with IBM watsonx Code Assistant")
165+
def test_project_name_unchanged_with_different_next(self):
166+
request = RequestFactory().get("/login?next=/home")
167+
request.user = AnonymousUser()
168+
response = LoginView.as_view()(request)
169+
response.render()
170+
contents = response.content.decode()
171+
self.assertIn("Log in to Ansible Lightspeed with IBM watsonx Code Assistant", contents)
172+
173+
@override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible Lightspeed with IBM watsonx Code Assistant")
174+
def test_project_name_modified_with_chatbot_next(self):
175+
request = RequestFactory().get("/login?next=/chatbot")
176+
request.user = AnonymousUser()
177+
response = LoginView.as_view()(request)
178+
response.render()
179+
contents = response.content.decode()
180+
self.assertIn("Log in to Ansible Lightspeed", contents)
181+
self.assertNotIn("Log in to Ansible Lightspeed with IBM watsonx Code Assistant", contents)
182+
183+
@override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible Lightspeed with IBM watsonx Code Assistant")
184+
def test_project_name_modified_with_chatbot_slash_next(self):
185+
request = RequestFactory().get("/login?next=/chatbot/")
186+
request.user = AnonymousUser()
187+
response = LoginView.as_view()(request)
188+
response.render()
189+
contents = response.content.decode()
190+
self.assertIn("Log in to Ansible Lightspeed", contents)
191+
self.assertNotIn("Log in to Ansible Lightspeed with IBM watsonx Code Assistant", contents)
192+
193+
@override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible AI Connect")
194+
def test_project_name_no_change_if_no_watsonx_text(self):
195+
request = RequestFactory().get("/login?next=/chatbot")
196+
request.user = AnonymousUser()
197+
response = LoginView.as_view()(request)
198+
response.render()
199+
contents = response.content.decode()
200+
self.assertIn("Log in to Ansible AI Connect", contents)
201+
202+
154203
@override_settings(ALLOW_METRICS_FOR_ANONYMOUS_USERS=False)
155204
class TestMetricsView(APITransactionTestCase):
156205

ansible_ai_connect/main/views.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@
5151
class LoginView(auth_views.LoginView):
5252
def get_context_data(self, **kwargs):
5353
context = super().get_context_data(**kwargs)
54-
context["next"] = self.request.GET.get("next") or "/"
54+
next_url = self.request.GET.get("next") or "/"
55+
context["next"] = next_url
5556
context["deployment_mode"] = settings.DEPLOYMENT_MODE
56-
context["project_name"] = settings.ANSIBLE_AI_PROJECT_NAME
57+
58+
project_name = settings.ANSIBLE_AI_PROJECT_NAME
59+
if next_url and next_url.startswith("/chatbot"):
60+
project_name = project_name.replace(" with IBM watsonx Code Assistant", "")
61+
62+
context["project_name"] = project_name
5763
context["aap_api_provider_name"] = settings.AAP_API_PROVIDER_NAME
5864
context["documentation_url"] = settings.COMMERCIAL_DOCUMENTATION_URL
5965
return context

0 commit comments

Comments
 (0)