Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions ansible_ai_connect/main/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
10 changes: 8 additions & 2 deletions ansible_ai_connect/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down