Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
e723052
TRCLI-78 Implement labels management command, added unit test and tes…
acuanico-tr-galt Aug 7, 2025
b05aa13
TRCLI-78 Added functional tests
acuanico-tr-galt Aug 7, 2025
0384af0
TRCLI-78 Added helper comments for functional tests
acuanico-tr-galt Aug 7, 2025
a2a0819
TRCLI-78 Added document and guide changes for Project level labels ma…
acuanico-tr-galt Aug 7, 2025
938ada1
TRCLI-78 Corrected parameter name for batch delete labels from label_…
acuanico-tr-galt Aug 7, 2025
1d27e5a
TRCLI-113 added implementation for labels management on test cases
acuanico-tr-galt Aug 14, 2025
cad3db5
TRCLI-113 added functional tests for labels management for test cases
acuanico-tr-galt Aug 14, 2025
cfe1973
TRCLI-113 updated tests report file for property and name to reflect …
acuanico-tr-galt Aug 14, 2025
9bbedbd
TRCLI-113 updated unit tests for label management for test cases
acuanico-tr-galt Aug 14, 2025
dd675b8
TRCLI-113 Updated readme guide to include labels management for test …
acuanico-tr-galt Aug 14, 2025
0033280
TRCLI-113 added implementation for getting test case labels using tes…
acuanico-tr-galt Aug 26, 2025
00672ec
TRCLI-113 added updates to labels cases list to make --id and --title…
acuanico-tr-galt Aug 26, 2025
f3fb429
TRCLI-113 TRCLI-139 Updated labels cases add to accept multiple label…
acuanico-tr-galt Aug 27, 2025
45512bd
TRCLI-113 Updated labels cases get to still show results even if a mi…
acuanico-tr-galt Aug 27, 2025
c27b7b7
TRCLI-113 Updated validations for mixed invalid and valid labels, imm…
acuanico-tr-galt Aug 28, 2025
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
463 changes: 460 additions & 3 deletions README.md

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions tests/test_api_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from unittest.mock import patch, MagicMock
from trcli.constants import FAULT_MAPPING
from trcli.cli import Environment
from trcli.api.api_client import APIClient
Expand Down Expand Up @@ -280,3 +281,150 @@ def test_timeout_is_parsed_and_validated(
else:
with pytest.raises(AssertionError):
environment.log.assert_has_calls([mocker.call(TIMEOUT_PARSE_ERROR)])

@pytest.mark.api_client
@patch('requests.post')
def test_send_post_with_json_default(self, mock_post, api_resources_maker):
"""Test that send_post uses JSON by default"""
# Mock response
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {"id": 1, "title": "Test"}
mock_response.content = b'{"id": 1, "title": "Test"}'
mock_post.return_value = mock_response

# Create API client
api_client = api_resources_maker()

# Call send_post without as_form_data parameter (should default to JSON)
result = api_client.send_post("test_endpoint", {":title": "Test Label"})

# Verify the result
assert result.status_code == 200
assert result.response_text == {"id": 1, "title": "Test"}

# Verify JSON was used
mock_post.assert_called_once()
call_args = mock_post.call_args

# Should use json parameter, not data
assert 'json' in call_args[1]
assert 'data' not in call_args[1]
assert call_args[1]['json'] == {":title": "Test Label"}

# Should have JSON content type header
headers = call_args[1]['headers']
assert headers.get('Content-Type') == 'application/json'

@pytest.mark.api_client
@patch('requests.post')
def test_send_post_with_form_data_true(self, mock_post, api_resources_maker):
"""Test that send_post uses form-data when as_form_data=True"""
# Mock response
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {"id": 1, "title": "Test"}
mock_response.content = b'{"id": 1, "title": "Test"}'
mock_post.return_value = mock_response

# Create API client
api_client = api_resources_maker()

# Call send_post with as_form_data=True
result = api_client.send_post("test_endpoint", {":title": "Test Label"}, as_form_data=True)

# Verify the result
assert result.status_code == 200
assert result.response_text == {"id": 1, "title": "Test"}

# Verify form-data was used
mock_post.assert_called_once()
call_args = mock_post.call_args

# Should use data parameter, not json
assert 'data' in call_args[1]
assert 'json' not in call_args[1]
assert call_args[1]['data'] == {":title": "Test Label"}

# Should NOT have files parameter (uses application/x-www-form-urlencoded)
assert 'files' not in call_args[1] or call_args[1]['files'] is None

# Should NOT have JSON content type header when using form-data
headers = call_args[1]['headers']
assert headers.get('Content-Type') != 'application/json'

@pytest.mark.api_client
@patch('requests.post')
def test_send_post_with_form_data_false(self, mock_post, api_resources_maker):
"""Test that send_post uses JSON when as_form_data=False explicitly"""
# Mock response
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {"id": 1, "title": "Test"}
mock_response.content = b'{"id": 1, "title": "Test"}'
mock_post.return_value = mock_response

# Create API client
api_client = api_resources_maker()

# Call send_post with as_form_data=False
result = api_client.send_post("test_endpoint", {":title": "Test Label"}, as_form_data=False)

# Verify the result
assert result.status_code == 200
assert result.response_text == {"id": 1, "title": "Test"}

# Verify JSON was used
mock_post.assert_called_once()
call_args = mock_post.call_args

# Should use json parameter, not data
assert 'json' in call_args[1]
assert 'data' not in call_args[1]
assert call_args[1]['json'] == {":title": "Test Label"}

# Should have JSON content type header
headers = call_args[1]['headers']
assert headers.get('Content-Type') == 'application/json'

@pytest.mark.api_client
@patch('requests.post')
def test_send_post_with_files_and_form_data(self, mock_post, api_resources_maker):
"""Test that send_post handles files parameter with form-data"""
# Mock response
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {"id": 1, "title": "Test"}
mock_response.content = b'{"id": 1, "title": "Test"}'
mock_post.return_value = mock_response

# Create API client
api_client = api_resources_maker()

# Call send_post with files and form-data
files = {"file1": "/path/to/file"}
result = api_client.send_post(
"test_endpoint",
{":title": "Test Label"},
files=files,
as_form_data=True
)

# Verify the result
assert result.status_code == 200
assert result.response_text == {"id": 1, "title": "Test"}

# Verify form-data was used
mock_post.assert_called_once()
call_args = mock_post.call_args

# Should use data parameter, not json
assert 'data' in call_args[1]
assert 'json' not in call_args[1]
assert call_args[1]['data'] == {":title": "Test Label"}
# Files should be passed through as provided (not replaced with empty dict)
assert call_args[1]['files'] == files

# Should NOT have JSON content type header when using files
headers = call_args[1]['headers']
assert headers.get('Content-Type') != 'application/json'
Loading