From 1e6e10a94c08b80b90ce150e27a2908a27b2897f Mon Sep 17 00:00:00 2001 From: Lucas Gomide Date: Fri, 6 Jun 2025 11:27:49 -0300 Subject: [PATCH] refactor: rename org column name to ID instead of Handle --- src/crewai/cli/cli.py | 6 +++--- src/crewai/cli/organization/main.py | 10 +++++----- tests/cli/organization/test_main.py | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/crewai/cli/cli.py b/src/crewai/cli/cli.py index 1d9dc9f80..ab53c8bb3 100644 --- a/src/crewai/cli/cli.py +++ b/src/crewai/cli/cli.py @@ -368,11 +368,11 @@ def list(): @org.command() -@click.argument("handle") -def switch(handle): +@click.argument("id") +def switch(id): """Switch to a specific organization.""" org_command = OrganizationCommand() - org_command.switch(handle) + org_command.switch(id) @org.command() diff --git a/src/crewai/cli/organization/main.py b/src/crewai/cli/organization/main.py index ec4146089..233f85714 100644 --- a/src/crewai/cli/organization/main.py +++ b/src/crewai/cli/organization/main.py @@ -23,7 +23,7 @@ class OrganizationCommand(BaseCommand, PlusAPIMixin): table = Table(title="Your Organizations") table.add_column("Name", style="cyan") - table.add_column("Handle", style="green") + table.add_column("ID", style="green") for org in orgs: table.add_row(org["name"], org["uuid"]) @@ -32,15 +32,15 @@ class OrganizationCommand(BaseCommand, PlusAPIMixin): console.print(f"Failed to retrieve organization list: {str(e)}", style="bold red") raise SystemExit(1) - def switch(self, org_handle): + def switch(self, org_id): try: response = self.plus_api_client.get_organizations() response.raise_for_status() orgs = response.json() - org = next((o for o in orgs if o["uuid"] == org_handle), None) + org = next((o for o in orgs if o["uuid"] == org_id), None) if not org: - console.print(f"Organization with handle '{org_handle}' not found.", style="bold red") + console.print(f"Organization with id '{org_id}' not found.", style="bold red") return settings = Settings() @@ -60,4 +60,4 @@ class OrganizationCommand(BaseCommand, PlusAPIMixin): else: console.print("You're not currently logged in to any organization.", style="yellow") console.print("Use 'crewai org list' to see available organizations.", style="yellow") - console.print("Use 'crewai org switch ' to switch to an organization.", style="yellow") + console.print("Use 'crewai org switch ' to switch to an organization.", style="yellow") diff --git a/tests/cli/organization/test_main.py b/tests/cli/organization/test_main.py index ac82f9f8c..5f92284ae 100644 --- a/tests/cli/organization/test_main.py +++ b/tests/cli/organization/test_main.py @@ -46,11 +46,11 @@ def test_org_switch_command(mock_org_command_class, runner): mock_org_instance = MagicMock() mock_org_command_class.return_value = mock_org_instance - result = runner.invoke(switch, ['test-handle']) + result = runner.invoke(switch, ['test-id']) assert result.exit_code == 0 mock_org_command_class.assert_called_once() - mock_org_instance.switch.assert_called_once_with('test-handle') + mock_org_instance.switch.assert_called_once_with('test-id') @patch('crewai.cli.cli.OrganizationCommand') @@ -91,7 +91,7 @@ class TestOrganizationCommand(unittest.TestCase): mock_table.assert_called_once_with(title="Your Organizations") mock_table.return_value.add_column.assert_has_calls([ call("Name", style="cyan"), - call("Handle", style="green") + call("ID", style="green") ]) mock_table.return_value.add_row.assert_has_calls([ call("Org 1", "org-123"), @@ -122,6 +122,7 @@ class TestOrganizationCommand(unittest.TestCase): with pytest.raises(SystemExit): self.org_command.list() + self.org_command.plus_api_client.get_organizations.assert_called_once() mock_console.print.assert_called_once_with( "Failed to retrieve organization list: API Error", @@ -135,7 +136,7 @@ class TestOrganizationCommand(unittest.TestCase): mock_response.raise_for_status = MagicMock() mock_response.json.return_value = [ {"name": "Org 1", "uuid": "org-123"}, - {"name": "Test Org", "uuid": "test-handle"} + {"name": "Test Org", "uuid": "test-id"} ] self.org_command.plus_api_client = MagicMock() self.org_command.plus_api_client.get_organizations.return_value = mock_response @@ -143,14 +144,14 @@ class TestOrganizationCommand(unittest.TestCase): mock_settings_instance = MagicMock() mock_settings_class.return_value = mock_settings_instance - self.org_command.switch("test-handle") + self.org_command.switch("test-id") self.org_command.plus_api_client.get_organizations.assert_called_once() mock_settings_instance.dump.assert_called_once() assert mock_settings_instance.org_name == "Test Org" - assert mock_settings_instance.org_uuid == "test-handle" + assert mock_settings_instance.org_uuid == "test-id" mock_console.print.assert_called_once_with( - "Successfully switched to Test Org (test-handle)", + "Successfully switched to Test Org (test-id)", style="bold green" ) @@ -165,11 +166,11 @@ class TestOrganizationCommand(unittest.TestCase): self.org_command.plus_api_client = MagicMock() self.org_command.plus_api_client.get_organizations.return_value = mock_response - self.org_command.switch("non-existent-handle") + self.org_command.switch("non-existent-id") self.org_command.plus_api_client.get_organizations.assert_called_once() mock_console.print.assert_called_once_with( - "Organization with handle 'non-existent-handle' not found.", + "Organization with id 'non-existent-id' not found.", style="bold red" ) @@ -178,14 +179,14 @@ class TestOrganizationCommand(unittest.TestCase): def test_current_organization_with_org(self, mock_settings_class, mock_console): mock_settings_instance = MagicMock() mock_settings_instance.org_name = "Test Org" - mock_settings_instance.org_uuid = "test-handle" + mock_settings_instance.org_uuid = "test-id" mock_settings_class.return_value = mock_settings_instance self.org_command.current() self.org_command.plus_api_client.get_organizations.assert_not_called() mock_console.print.assert_called_once_with( - "Currently logged in to organization Test Org (test-handle)", + "Currently logged in to organization Test Org (test-id)", style="bold green" )