Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Added Custom YAMLs #14

Merged
merged 7 commits into from
Nov 7, 2023
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
2 changes: 1 addition & 1 deletion test_collections/sdk_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from .support.yaml_tests import sdk_collection
from .support.yaml_tests import sdk_collection, custom_collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- This is a placeholder file for the custom YAML folder
- Use this directory to include all customized YAML files
- The tests will be presented in a new test collection on the TH UI
4 changes: 3 additions & 1 deletion test_collections/sdk_tests/support/yaml_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#
from app.test_engine.models.test_declarations import TestCollectionDeclaration

from .sdk_yaml_tests import sdk_yaml_test_collection
from .sdk_yaml_tests import sdk_yaml_test_collection, custom_yaml_test_collection

# Test engine will auto load TestCollectionDeclarations declared inside the package
# initializer
sdk_collection: TestCollectionDeclaration = sdk_yaml_test_collection()

custom_collection: TestCollectionDeclaration = custom_yaml_test_collection()
31 changes: 29 additions & 2 deletions test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
SDK_YAML_PATH = Path("/app/backend/test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/sdk")
SDK_YAML_TEST_FOLDER = YamlTestFolder(path=SDK_YAML_PATH, filename_pattern="Test_TC*")

CUSTOM_YAML_PATH = Path("/app/backend/test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/custom")
CUSTOM_YAML_TEST_FOLDER = YamlTestFolder(path=CUSTOM_YAML_PATH, filename_pattern="Test_TC*")


def _init_test_suites(yaml_version: str) -> dict[SuiteType, YamlSuiteDeclaration]:
return {
SuiteType.MANUAL: YamlSuiteDeclaration(
Expand Down Expand Up @@ -68,7 +72,7 @@ def _parse_yaml_to_test_case_declaration(
return YamlCaseDeclaration(test=yaml_test, yaml_version=yaml_version)


def _parse_all_sdk_yaml(
def _parse_all_yaml(
yaml_files: list[Path], yaml_version: str
) -> list[YamlSuiteDeclaration]:
"""Parse all yaml files and organize them in the 3 test suites:
Expand Down Expand Up @@ -108,10 +112,33 @@ def sdk_yaml_test_collection(

files = yaml_test_folder.yaml_file_paths()
version = yaml_test_folder.version
suites = _parse_all_sdk_yaml(yaml_files=files, yaml_version=version)
suites = _parse_all_yaml(yaml_files=files, yaml_version=version)

for suite in suites:
suite.sort_test_cases()
collection.add_test_suite(suite)

return collection


def custom_yaml_test_collection(
yaml_test_folder: YamlTestFolder = CUSTOM_YAML_TEST_FOLDER,
) -> YamlCollectionDeclaration:
"""Declare a new collection of test suites."""
collection = YamlCollectionDeclaration(
name="Custom YAML Tests", folder=yaml_test_folder
)

files = yaml_test_folder.yaml_file_paths()
suites = _parse_all_yaml(yaml_files=files, yaml_version=None)

for suite in suites:
if not suite.test_cases:
continue
suite.sort_test_cases()
collection.add_test_suite(suite)

if not collection.test_suites:
return None

return collection