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
32 changes: 21 additions & 11 deletions smart_tests/commands/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,12 @@ def verify(app_instance: Application):
client = SmartTestsClient(tracking_client=tracking_client, app=app_instance)
java = get_java_command()

# Print the system information first so that we can get them even if there's
# an issue.

click.echo("Organization: " + repr(org))
click.echo("Workspace: " + repr(workspace))
click.echo("Proxy: " + repr(os.getenv("HTTPS_PROXY")))
click.echo("Platform: " + repr(platform.platform()))
click.echo("Python version: " + repr(platform.python_version()))
click.echo("Java command: " + repr(java))
click.echo("smart-tests version: " + repr(version))

# raise an error here after we print out the basic diagnostics if LAUNCHABLE_TOKEN is not set.
ensure_org_workspace()

# Fetch display names from the verification endpoint
org_display = org
workspace_display = workspace
try:
res = client.request("get", "verification")
if res.status_code == 401:
Expand All @@ -111,6 +103,15 @@ def verify(app_instance: Application):
)
raise typer.Exit(2)
res.raise_for_status()

# Parse display names from response, with fallback to original values
try:
data = res.json()
org_display = data.get("organizationDisplayName", org)
workspace_display = data.get("workspaceDisplayName", workspace)
except Exception:
# If JSON parsing fails, continue with original values
pass
except Exception as e:
tracking_client.send_error_event(
event_name=Tracking.ErrorEvent.INTERNAL_CLI_ERROR,
Expand All @@ -119,6 +120,15 @@ def verify(app_instance: Application):
)
client.print_exception_and_recover(e)

# Print the system information after fetching display names
click.echo("Organization: " + repr(org_display))
click.echo("Workspace: " + repr(workspace_display))
click.echo("Proxy: " + repr(os.getenv("HTTPS_PROXY")))
click.echo("Platform: " + repr(platform.platform()))
click.echo("Python version: " + repr(platform.python_version()))
click.echo("Java command: " + repr(java))
click.echo("smart-tests version: " + repr(version))

if java is None:
msg = "Java is not installed. Install Java version 8 or newer to use the Smart Tests CLI."
tracking_client.send_error_event(
Expand Down
56 changes: 56 additions & 0 deletions tests/commands/test_verify.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os
from subprocess import CalledProcessError
from unittest import TestCase
from unittest.mock import patch

import responses # type: ignore

from smart_tests.commands.verify import check_java_version, compare_java_version, compare_version, parse_version
from smart_tests.utils.http_client import get_base_url
from tests.cli_test_case import CliTestCase


class VersionTest(TestCase):
Expand Down Expand Up @@ -51,3 +56,54 @@ def test_check_java_version(self, mock_run):
mock_run.side_effect = CalledProcessError(1, 'java -version')
result = check_java_version('java')
self.assertEqual(result, -1)


class VerifyCommandTest(CliTestCase):
"""Test the verify command with display names"""

@responses.activate
@patch.dict(os.environ, {"SMART_TESTS_TOKEN": CliTestCase.smart_tests_token})
def test_verify_shows_display_name(self):
"""Test that verify displays organizationDisplayName and workspaceDisplayName from API response"""
verification_url = f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/verification"

# Mock server response with displayName fields
responses.add(
responses.GET,
verification_url,
json={
"organization": self.organization,
"organizationDisplayName": "My Company",
"workspace": self.workspace,
"workspaceDisplayName": "Production"
},
status=200
)

result = self.cli("verify")
self.assert_success(result)

# Verify displayName appears in output
self.assertIn("'My Company'", result.output)
self.assertIn("'Production'", result.output)

@responses.activate
@patch.dict(os.environ, {"SMART_TESTS_TOKEN": CliTestCase.smart_tests_token})
def test_verify_fallback_when_no_display_name(self):
"""Test that verify falls back to org/workspace when displayName not in response"""
verification_url = f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/verification"

# Mock server response without displayName fields
responses.add(
responses.GET,
verification_url,
json={},
status=200
)

result = self.cli("verify")
self.assert_success(result)

# Should show original org/workspace names
self.assertIn(f"'{self.organization}'", result.output)
self.assertIn(f"'{self.workspace}'", result.output)
Loading