diff --git a/controlpanel/api/models/app.py b/controlpanel/api/models/app.py index 93140edef..b5365c80e 100644 --- a/controlpanel/api/models/app.py +++ b/controlpanel/api/models/app.py @@ -254,12 +254,13 @@ def auth0_client_name(self, env_name=None): def app_url_name(self, env_name): format_pattern = settings.APP_URL_NAME_PATTERN.get(env_name.upper()) + namespace = self.namespace.removeprefix("data-platform-app-") if not format_pattern: format_pattern = settings.APP_URL_NAME_PATTERN.get(self.DEFAULT_SETTING_KEY_WORD) if format_pattern: - return format_pattern.format(app_name=self.namespace, env=env_name) + return format_pattern.format(app_name=namespace, env=env_name) else: - return self.namespace + return namespace def get_auth_client(self, env_name): env_name = env_name or self.DEFAULT_AUTH_CATEGORY diff --git a/tests/api/models/test_app.py b/tests/api/models/test_app.py index 39277aea6..58d5e8d8c 100644 --- a/tests/api/models/test_app.py +++ b/tests/api/models/test_app.py @@ -209,3 +209,16 @@ def test_app_allowed_ip_ranges(): def test_iam_role_arn(): app = App(slug="example-app") assert app.iam_role_arn == f"arn:aws:iam::{settings.AWS_DATA_ACCOUNT_ID}:role/test_app_example-app" + + +@pytest.mark.parametrize("namespace, env, expected", [ + ("data-platform-app-example", "dev", "example-dev"), + ("example", "dev", "example-dev"), + ("data-platform-example", "dev", "data-platform-example-dev"), + ("data-platform-app-example", "prod", "example"), + ("example", "prod", "example"), + ("data-platform-example", "prod", "data-platform-example"), +]) +def test_app_url_name(namespace, env, expected): + app = App(namespace=namespace) + assert app.app_url_name(env_name=env) == expected