Skip to content
Open
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
167 changes: 61 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Commands:
statuses Manage test statuses in TestRail
casefields List case fields in TestRail
resultfields List result fields in TestRail
priorities List test case priorities in TestRail
casetypes List test case types in TestRail
update Update TRCLI to the latest version from PyPI.
```

Expand Down Expand Up @@ -2394,157 +2396,110 @@ Case Status ID: 2
Case status listing completed successfully.
```

### Statuses Command

The TestRail CLI provides the `statuses` command for retrieving status information from TestRail. This includes both test result statuses (Passed, Failed, Blocked, etc.) and case statuses (Approved, Draft, etc.). These statuses are crucial for mapping test results correctly and managing test case workflows.

#### Statuses Command Overview

The `statuses` command supports two subcommands:
### Priorities Command

| Subcommand | Purpose | API Endpoint |
|------------|---------|--------------|
| `all` | List all test result statuses | Retrieve available test result statuses (Passed, Failed, Blocked, etc.) |
| `case` | List all case statuses (Enterprise 7.3+) | Retrieve test case statuses (Approved, Draft, etc.) for case workflows |
The TestRail CLI provides the `priorities` command for retrieving all available test case priorities from TestRail. This command helps you understand the priority levels configured in your TestRail instance, including their IDs, names, short names, display order, and which priority is set as the default.

#### Reference

```shell
$ trcli statuses --help
$ trcli priorities --help

Usage: trcli statuses [OPTIONS] COMMAND [ARGS]...
Manage test statuses in TestRail
Usage: trcli priorities [OPTIONS] COMMAND [ARGS]...
Manage test case priorities in TestRail

Options:
--help Show this message and exit.

Commands:
all List all test result statuses from TestRail
case List all case statuses from TestRail (Enterprise 7.3+)
list List all test case priorities from TestRail
```

##### Listing Test Result Statuses

List all test result statuses available for a project:
#### Listing Priorities

```shell
# List all test result statuses (using config file)
$ trcli -c config.yml statuses all
# List all priorities
$ trcli priorities list -h https://yourinstance.testrail.io -u user@example.com -p password

# List all statuses with all parameters
$ trcli statuses all \
--host https://yourinstance.testrail.io \
--username <your_username> \
--password <your_password> \
--project "Your Project"
# Show all fields including priority order
$ trcli priorities list -c config.yml --show-all-fields

# Show all fields including color values
$ trcli -c config.yml statuses all --show-all-fields

# JSON output for integration with other tools
$ trcli -c config.yml statuses all --json-output | jq '.[].name'
# JSON output
$ trcli priorities list -c config.yml --json-output
```

**Example Output:**
#### Example Output

```shell
$ trcli -c config.yml statuses all

Statuses List (Test Result Statuses) Execution Parameters
> TestRail instance: https://yourinstance.testrail.io (user: test@example.com)
> Project: Your Project

Retrieving test result statuses for project ID 1...
Found 5 test result status(es):

Status ID: 1
Name: passed
Label: Passed
System Status: Yes
Is Untested: No
Is Final: Yes
$ trcli priorities list -c config.yml

Status ID: 2
Name: blocked
Label: Blocked
System Status: Yes
Is Untested: No
Is Final: No

Status ID: 3
Name: untested
Label: Untested
System Status: Yes
Is Untested: Yes
Is Final: No
Priorities List Execution Parameters
> TestRail instance: https://yourinstance.testrail.io (user: your@email.com)
Retrieving priorities...
Found 4 priority level(s).

Status ID: 4
Name: retest
Label: Retest
System Status: Yes
Is Untested: No
Is Final: No
ID: 1 | Name: 1 - Don't Test | Short: 1 - Don't
ID: 2 | Name: 2 - Low | Short: 2 - Low
ID: 3 | Name: 3 - Medium | Short: 3 - Med
ID: 4 | Name: 4 - Must Test | Short: 4 - Must [DEFAULT]

Status ID: 5
Name: failed
Label: Failed
System Status: Yes
Is Untested: No
Is Final: Yes
Priority listing completed successfully.
```

**Note:** The `[DEFAULT]` marker indicates which priority is set as the default for new test cases in TestRail. Priorities are global settings and apply across all projects in your TestRail instance.

Status listing completed successfully.
```
### Case Types Command

##### Listing Case Statuses
The TestRail CLI provides the `casetypes` command for retrieving all available test case types from TestRail. This command helps you understand the different case type classifications configured in your TestRail instance, such as Automated, Functionality, Performance, and others, including which type is set as the default.

List all case statuses (requires TestRail Enterprise 7.3+):
#### Reference

```shell
# List all case statuses (using config file)
$ trcli -c config.yml statuses case
$ trcli casetypes --help

# List case statuses with all parameters
$ trcli statuses case \
--host https://yourinstance.testrail.io \
--username <your_username> \
--password <your_password> \
--project "Your Project"
Usage: trcli casetypes [OPTIONS] COMMAND [ARGS]...
Manage test case types in TestRail

# Show all fields including abbreviations
$ trcli -c config.yml statuses case --show-all-fields
Options:
--help Show this message and exit.

# JSON output for integration
$ trcli -c config.yml statuses case --json-output | jq '.[].name'
Commands:
list List all test case types from TestRail
```

**Example Output:**
#### Listing Case Types

```shell
$ trcli -c config.yml statuses case
# List all case types
$ trcli -h https://yourinstance.testrail.io -u user@example.com -p password casetypes list

Statuses List (Case Statuses) Execution Parameters
> TestRail instance: https://yourinstance.testrail.io (user: test@example.com)
> Project: Your Project
# With config file
$ trcli casetypes list -c config.yml

Retrieving case statuses...
Note: This command requires TestRail Enterprise 7.3 or later.
Found 2 case status(es):
# JSON output
$ trcli casetypes list -c config.yml --json-output
```

Case Status ID: 1
Name: Approved
Is Default: No
Is Approved: Yes
#### Example Output

Case Status ID: 2
Name: Draft
Is Default: Yes
Is Approved: No
```shell
$ trcli casetypes list -c config.yml

Case Types List Execution Parameters
> TestRail instance: https://yourinstance.testrail.io (user: your@email.com)
Retrieving case types...
Found 4 case type(s).

Case status listing completed successfully.
ID: 1 | Name: Automated
ID: 2 | Name: Functionality
ID: 3 | Name: Performance
ID: 6 | Name: Other [DEFAULT]

Case type listing completed successfully.
```

**Note:** The `[DEFAULT]` marker indicates which case type is set as the default for new test cases in TestRail. Case types are global settings and apply across all projects in your TestRail instance.

### Case Fields Command

The TestRail CLI provides the `casefields` command for retrieving all available test case custom fields from TestRail. This command helps you understand what custom fields are available for test cases, their types, configurations, and which projects they apply to.
Expand Down
119 changes: 119 additions & 0 deletions tests/test_cmd_casetypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import pytest
from unittest import mock
from unittest.mock import MagicMock, patch
from click.testing import CliRunner

from trcli.cli import Environment
from trcli.commands import cmd_casetypes


class TestCmdCaseTypes:
"""Test class for casetypes command functionality"""

def setup_method(self):
"""Set up test environment"""
self.runner = CliRunner()
self.environment = Environment(cmd="casetypes")
self.environment.host = "https://test.testrail.com"
self.environment.username = "test@example.com"
self.environment.password = "password"
self.environment.api_key = None

def _setup_project_client_mock(self, mock_project_client):
"""Helper to setup ProjectBasedClient mock"""
mock_client_instance = MagicMock()
mock_project_client.return_value = mock_client_instance
return mock_client_instance

@mock.patch("trcli.commands.cmd_casetypes.ProjectBasedClient")
def test_list_case_types_success(self, mock_project_client):
"""Test successful case types listing"""
mock_client = self._setup_project_client_mock(mock_project_client)
mock_client.api_request_handler.case_type_handler.get_case_types.return_value = (
[
{"id": 1, "is_default": False, "name": "Automated"},
{"id": 2, "is_default": False, "name": "Functionality"},
{"id": 3, "is_default": False, "name": "Performance"},
{"id": 6, "is_default": True, "name": "Other"},
],
"",
)

with patch.object(self.environment, "log") as mock_log, patch.object(
self.environment, "set_parameters"
), patch.object(self.environment, "check_for_required_parameters"):
result = self.runner.invoke(cmd_casetypes.list, [], obj=self.environment)

assert result.exit_code == 0
mock_client.api_request_handler.case_type_handler.get_case_types.assert_called_once()
assert mock_log.called

@mock.patch("trcli.commands.cmd_casetypes.ProjectBasedClient")
def test_list_case_types_json_output(self, mock_project_client):
"""Test case types listing with JSON output"""
mock_client = self._setup_project_client_mock(mock_project_client)
case_types_data = [
{"id": 1, "is_default": False, "name": "Automated"},
{"id": 6, "is_default": True, "name": "Other"},
]
mock_client.api_request_handler.case_type_handler.get_case_types.return_value = (case_types_data, "")

with patch.object(self.environment, "set_parameters"), patch.object(
self.environment, "check_for_required_parameters"
):
result = self.runner.invoke(cmd_casetypes.list, ["--json-output"], obj=self.environment)

assert result.exit_code == 0
# Check for prettified JSON
assert '"name": "Automated"' in result.output
assert "\n" in result.output

@mock.patch("trcli.commands.cmd_casetypes.ProjectBasedClient")
def test_list_case_types_empty_result(self, mock_project_client):
"""Test case types listing with no case types (edge case)"""
mock_client = self._setup_project_client_mock(mock_project_client)
mock_client.api_request_handler.case_type_handler.get_case_types.return_value = ([], "")

with patch.object(self.environment, "log") as mock_log, patch.object(
self.environment, "set_parameters"
), patch.object(self.environment, "check_for_required_parameters"):
result = self.runner.invoke(cmd_casetypes.list, [], obj=self.environment)

assert result.exit_code == 0
assert mock_log.called

@mock.patch("trcli.commands.cmd_casetypes.ProjectBasedClient")
def test_list_case_types_api_error(self, mock_project_client):
"""Test case types listing with API error"""
mock_client = self._setup_project_client_mock(mock_project_client)
mock_client.api_request_handler.case_type_handler.get_case_types.return_value = ([], "Connection timeout")

with patch.object(self.environment, "elog") as mock_elog, patch.object(
self.environment, "set_parameters"
), patch.object(self.environment, "check_for_required_parameters"):
result = self.runner.invoke(cmd_casetypes.list, [], obj=self.environment)

assert result.exit_code == 1
mock_elog.assert_called_with("Error: Failed to retrieve case types: Connection timeout")

@mock.patch("trcli.commands.cmd_casetypes.ProjectBasedClient")
def test_list_case_types_default_marked(self, mock_project_client):
"""Test that default case type is properly marked"""
mock_client = self._setup_project_client_mock(mock_project_client)
mock_client.api_request_handler.case_type_handler.get_case_types.return_value = (
[
{"id": 1, "is_default": False, "name": "Automated"},
{"id": 6, "is_default": True, "name": "Other"},
],
"",
)

with patch.object(self.environment, "log") as mock_log, patch.object(
self.environment, "set_parameters"
), patch.object(self.environment, "check_for_required_parameters"):
result = self.runner.invoke(cmd_casetypes.list, [], obj=self.environment)

assert result.exit_code == 0
# Verify DEFAULT marker appears for the default case type
log_calls = [str(call) for call in mock_log.call_args_list]
assert any("[DEFAULT]" in str(call) for call in log_calls)
Loading
Loading