diff --git a/ansible_ai_connect/main/tests/test_views.py b/ansible_ai_connect/main/tests/test_views.py index b51bc49d7..6837cb65e 100644 --- a/ansible_ai_connect/main/tests/test_views.py +++ b/ansible_ai_connect/main/tests/test_views.py @@ -151,6 +151,55 @@ class MockUser: self.assertEqual(response.url, "/") +class LoginViewProjectNameTest(TestCase): + @override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible Lightspeed with IBM watsonx Code Assistant") + def test_project_name_unchanged_without_next(self): + request = RequestFactory().get("/login") + request.user = AnonymousUser() + response = LoginView.as_view()(request) + response.render() + contents = response.content.decode() + self.assertIn("Log in to Ansible Lightspeed with IBM watsonx Code Assistant", contents) + + @override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible Lightspeed with IBM watsonx Code Assistant") + def test_project_name_unchanged_with_different_next(self): + request = RequestFactory().get("/login?next=/home") + request.user = AnonymousUser() + response = LoginView.as_view()(request) + response.render() + contents = response.content.decode() + self.assertIn("Log in to Ansible Lightspeed with IBM watsonx Code Assistant", contents) + + @override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible Lightspeed with IBM watsonx Code Assistant") + def test_project_name_modified_with_chatbot_next(self): + request = RequestFactory().get("/login?next=/chatbot") + request.user = AnonymousUser() + response = LoginView.as_view()(request) + response.render() + contents = response.content.decode() + self.assertIn("Log in to Ansible Lightspeed", contents) + self.assertNotIn("Log in to Ansible Lightspeed with IBM watsonx Code Assistant", contents) + + @override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible Lightspeed with IBM watsonx Code Assistant") + def test_project_name_modified_with_chatbot_slash_next(self): + request = RequestFactory().get("/login?next=/chatbot/") + request.user = AnonymousUser() + response = LoginView.as_view()(request) + response.render() + contents = response.content.decode() + self.assertIn("Log in to Ansible Lightspeed", contents) + self.assertNotIn("Log in to Ansible Lightspeed with IBM watsonx Code Assistant", contents) + + @override_settings(ANSIBLE_AI_PROJECT_NAME="Ansible AI Connect") + def test_project_name_no_change_if_no_watsonx_text(self): + request = RequestFactory().get("/login?next=/chatbot") + request.user = AnonymousUser() + response = LoginView.as_view()(request) + response.render() + contents = response.content.decode() + self.assertIn("Log in to Ansible AI Connect", contents) + + @override_settings(ALLOW_METRICS_FOR_ANONYMOUS_USERS=False) class TestMetricsView(APITransactionTestCase): diff --git a/ansible_ai_connect/main/views.py b/ansible_ai_connect/main/views.py index 301140aad..d7950b458 100644 --- a/ansible_ai_connect/main/views.py +++ b/ansible_ai_connect/main/views.py @@ -51,9 +51,15 @@ class LoginView(auth_views.LoginView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context["next"] = self.request.GET.get("next") or "/" + next_url = self.request.GET.get("next") or "/" + context["next"] = next_url context["deployment_mode"] = settings.DEPLOYMENT_MODE - context["project_name"] = settings.ANSIBLE_AI_PROJECT_NAME + + project_name = settings.ANSIBLE_AI_PROJECT_NAME + if next_url and next_url.startswith("/chatbot"): + project_name = project_name.replace(" with IBM watsonx Code Assistant", "") + + context["project_name"] = project_name context["aap_api_provider_name"] = settings.AAP_API_PROVIDER_NAME context["documentation_url"] = settings.COMMERCIAL_DOCUMENTATION_URL return context