Skip to content

Commit

Permalink
Merge pull request #209 from gurock/restrict_testcase_title_length
Browse files Browse the repository at this point in the history
limit test case title. fixes #207
  • Loading branch information
bitcoder authored Feb 29, 2024
2 parents f8cb600 + cfdab7b commit 2f3e69d
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "${{ matrix.python_version }}"
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"tqdm==4.65.*",
"humanfriendly==10.0.*",
"openapi-spec-validator==0.5.*",
"beartype==0.7.*",
"prance" # Does not use semantic versioning
],
entry_points="""
Expand Down
7 changes: 4 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest
pytest==8.0.*
pytest-md-report
coverage
allure-pytest
Expand All @@ -8,8 +8,9 @@ requests-mock
click==8.0.3
pyyaml
junitparser
pyserde
pyserde==0.12.*
requests
tqdm
humanfriendly
deepdiff
deepdiff
beartype
5 changes: 4 additions & 1 deletion tests/test_data/XML/root.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<property name="testrail_result_step" value="passed:Go to homepage"/>
<property name="testrail_result_step" value="failed:Verify content"/>
</properties>
<skipped type="pytest.skip" message="Please skip">skipped by user</skipped></testcase>
<skipped type="pytest.skip" message="Please skip">skipped by user</skipped>
</testcase>
<testcase classname="The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs. Waltz, bad nymph, for quick jigs vex! Fox nymph" name="Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec." time="160">
</testcase>
</testsuite>
</testsuites>
71 changes: 71 additions & 0 deletions tests/test_data/json/api_request_handler_long_testcase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"description": null,
"name": "Suite1",
"suite_id": 4,
"testsections": [
{
"name": "Skipped test",
"suite_id": 4,
"section_id": 1234,
"testcases": [
{
"section_id": 1234,
"title": "testCase1",
"custom_automation_id": "Skipped test.testCase1",
"case_id": 1,
"result": {
"comment": "Type: pytest.skip\\nMessage: Please skip\\nText: skipped by user",
"status_id": 4,
"case_id": 1,
"attachments": [
"./path1",
"./path2"
]
}
},
{
"section_id": 1234,
"title": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.",
"custom_automation_id": "Skipped test.testCase2",
"estimate": "30s",
"case_id": null,
"result": {
"comment": "Comment testCase2",
"status_id": 1,
"case_id": null
}
}
],
"properties": [
{
"description": "logging: True",
"name": "logging",
"value": "True"
},
{
"description": "debug: False",
"name": "debug",
"value": "False"
}
]
},
{
"name": "Passed test",
"suite_id": 4,
"section_id": null,
"testcases": [
{
"section_id": 2,
"title": "testCase3",
"custom_automation_id": "Passed test.testCase3",
"case_id": null,
"result": {
"comment": "Comment testCase3",
"status_id": 1,
"case_id": null
}
}
]
}
]
}
26 changes: 26 additions & 0 deletions tests/test_data/json/root.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@
"custom_case_field": "custom_case_val"
},
"type_id": null
},
{
"case_id": null,
"custom_automation_id": "The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs. Waltz, bad nymph, for quick jigs vex! Fox nymph.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec.",
"estimate": null,
"milestone_id": null,
"refs": null,
"case_fields": {
},
"result": {
"assignedto_id": null,
"defects": null,
"elapsed": "160s",
"junit_result_unparsed": [],
"status_id": 1,
"case_id": null,
"version": null,
"custom_step_results": [],
"result_fields": {},
"attachments": [],
"comment": ""
},
"section_id": null,
"template_id": null,
"title": "quam felis, ultricies nec, pellentesque eu, pretium quis, sem Nulla consequat massa quis enim Donec",
"type_id": null
}
]
}
Expand Down
1 change: 1 addition & 0 deletions tests_e2e/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest
pytest-md-report
coverage
beartype
2 changes: 1 addition & 1 deletion trcli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.9.0"
__version__ = "1.9.1"
2 changes: 1 addition & 1 deletion trcli/api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path

import requests
from typing import Union, Callable, Dict, List
from beartype.typing import Union, Callable, Dict, List
from time import sleep

import urllib3
Expand Down
2 changes: 1 addition & 1 deletion trcli/api/api_request_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import html
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import List, Union, Tuple, Dict
from beartype.typing import List, Union, Tuple, Dict

from trcli.api.api_client import APIClient, APIClientResult
from trcli.api.api_response_verify import ApiResponseVerify
Expand Down
2 changes: 1 addition & 1 deletion trcli/api/api_response_verify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from serde.json import to_dict
from typing import List, Union, Any, Callable
from beartype.typing import List, Union, Any, Callable
from humanfriendly import parse_timespan


Expand Down
2 changes: 1 addition & 1 deletion trcli/api/results_uploader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from typing import Tuple, Callable, List
from beartype.typing import Tuple, Callable, List

from trcli.api.api_client import APIClient
from trcli.api.api_request_handler import ApiRequestHandler
Expand Down
2 changes: 1 addition & 1 deletion trcli/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from typing import List, Union
from beartype.typing import List, Union

import click
import yaml
Expand Down
36 changes: 35 additions & 1 deletion trcli/data_classes/data_parsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Union, List, Dict
from beartype.typing import Union, List, Dict


class MatchersParser:
Expand Down Expand Up @@ -69,3 +69,37 @@ def resolve_fields(fields: Union[List[str], Dict]) -> (Dict, str):
return fields_dictionary, error
except Exception as ex:
return fields_dictionary, f"Error parsing fields: {ex}"

class TestRailCaseFieldsOptimizer:

MAX_TESTCASE_TITLE_LENGTH = 100

@staticmethod
def extract_last_words(input_string, max_characters=100):
if input_string is None:
return None

# Define delimiters for splitting words
delimiters = [' ', '\t', ';', ':', '>', '/', '.']

# Replace multiple consecutive delimiters with a single space
regex_pattern = '|'.join(map(re.escape, delimiters))
cleaned_string = re.sub(f'[{regex_pattern}]+', ' ', input_string.strip())

# Split the cleaned string into words
words = cleaned_string.split()

# Extract the last words up to the maximum character limit
extracted_words = []
current_length = 0
for word in reversed(words):
if current_length + len(word) <= max_characters:
extracted_words.append(word)
current_length += len(word) + 1 # Add 1 for the space between words
else:
break

# Reverse the extracted words to maintain the original order
result = ' '.join(reversed(extracted_words))

return result
2 changes: 1 addition & 1 deletion trcli/data_classes/dataclass_testrail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from time import gmtime, strftime
from typing import List, Optional
from beartype.typing import List, Optional

from serde import field, serialize, deserialize, to_dict

Expand Down
2 changes: 1 addition & 1 deletion trcli/data_providers/api_data_provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Dict
from beartype.typing import List, Dict

from serde.json import to_dict

Expand Down
2 changes: 1 addition & 1 deletion trcli/readers/file_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from abc import abstractmethod
from typing import Union, List
from beartype.typing import Union, List

from trcli.cli import Environment
from trcli.data_classes.dataclass_testrail import TestRailSuite
Expand Down
6 changes: 3 additions & 3 deletions trcli/readers/junit_xml.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import glob
from pathlib import Path
from typing import Union, List
from beartype.typing import Union, List
from unittest import TestCase, TestSuite
from xml.etree import ElementTree as etree

from junitparser import JUnitXml, JUnitXmlError, Element, Attr

from trcli.cli import Environment
from trcli.data_classes.data_parsers import MatchersParser, FieldsParser
from trcli.data_classes.data_parsers import MatchersParser, FieldsParser, TestRailCaseFieldsOptimizer
from trcli.data_classes.dataclass_testrail import (
TestRailCase,
TestRailSuite,
Expand Down Expand Up @@ -163,7 +163,7 @@ def parse_file(self) -> List[TestRailSuite]:
result.prepend_comment(f"SauceLabs session: {sauce_session}")
test_cases.append(
TestRailCase(
title=case_name,
title=TestRailCaseFieldsOptimizer.extract_last_words(case_name, TestRailCaseFieldsOptimizer.MAX_TESTCASE_TITLE_LENGTH),
case_id=case_id,
result=result,
custom_automation_id=automation_id,
Expand Down
5 changes: 3 additions & 2 deletions trcli/readers/openapi_yml.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
from pathlib import Path
from typing import List
from beartype.typing import List

import yaml
from trcli.data_classes.data_parsers import TestRailCaseFieldsOptimizer

from trcli.data_classes.dataclass_testrail import (
TestRailCase,
Expand Down Expand Up @@ -167,7 +168,7 @@ def parse_file(self) -> List[TestRailSuite]:
section: TestRailSection = sections[tag]
section.testcases.append(
TestRailCase(
openapi_test.name,
TestRailCaseFieldsOptimizer.extract_last_words(openapi_test.name, TestRailCaseFieldsOptimizer.MAX_TESTCASE_TITLE_LENGTH),
custom_automation_id=f"{openapi_test.unique_id}",
result=TestRailResult(),
case_fields={
Expand Down
6 changes: 3 additions & 3 deletions trcli/readers/robot_xml.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from datetime import datetime, timedelta
from typing import List
from beartype.typing import List
from xml.etree import ElementTree

from trcli.backports import removeprefix
from trcli.cli import Environment
from trcli.data_classes.data_parsers import MatchersParser, FieldsParser
from trcli.data_classes.data_parsers import MatchersParser, FieldsParser, TestRailCaseFieldsOptimizer
from trcli.data_classes.dataclass_testrail import (
TestRailCase,
TestRailSuite,
Expand Down Expand Up @@ -115,7 +115,7 @@ def _find_suites(self, suite_element, sections_list: List, namespace=""):
for comment in reversed(comments):
result.prepend_comment(comment)
tr_test = TestRailCase(
title=case_name,
title=TestRailCaseFieldsOptimizer.extract_last_words(case_name, TestRailCaseFieldsOptimizer.MAX_TESTCASE_TITLE_LENGTH),
case_id=case_id,
result=result,
custom_automation_id=f"{namespace}.{case_name}",
Expand Down

0 comments on commit 2f3e69d

Please sign in to comment.