From 1bd0ae3e33095fd219a0d2a6c1c26e671e18c439 Mon Sep 17 00:00:00 2001 From: Hilton Lima Date: Wed, 1 Nov 2023 19:47:36 +0000 Subject: [PATCH 1/4] Added custom yamls tests --- test_collections/sdk_tests/__init__.py | 2 +- .../sdk_tests/support/yaml_tests/__init__.py | 4 ++- .../support/yaml_tests/sdk_yaml_tests.py | 32 +++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/test_collections/sdk_tests/__init__.py b/test_collections/sdk_tests/__init__.py index ec9f4b95..6df5f6d8 100644 --- a/test_collections/sdk_tests/__init__.py +++ b/test_collections/sdk_tests/__init__.py @@ -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 diff --git a/test_collections/sdk_tests/support/yaml_tests/__init__.py b/test_collections/sdk_tests/support/yaml_tests/__init__.py index bf55d4b4..c98d927c 100644 --- a/test_collections/sdk_tests/support/yaml_tests/__init__.py +++ b/test_collections/sdk_tests/support/yaml_tests/__init__.py @@ -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() \ No newline at end of file diff --git a/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py b/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py index 91ea69e8..db76cd32 100644 --- a/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py +++ b/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py @@ -41,6 +41,9 @@ 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( @@ -68,7 +71,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: @@ -108,10 +111,35 @@ 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 with the 3 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) + + has_valid_test_case = False for suite in suites: + if not suite.test_cases: + continue + has_valid_test_case = True suite.sort_test_cases() collection.add_test_suite(suite) + if not has_valid_test_case: + return None + return collection From ca7c92100aef64e52cd37908d296849d7a093a21 Mon Sep 17 00:00:00 2001 From: Hilton Lima Date: Wed, 1 Nov 2023 20:18:22 +0000 Subject: [PATCH 2/4] add custom folder --- .../sdk_tests/sdk_checkout/yaml_tests/yaml/custom/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/custom/.gitkeep diff --git a/test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/custom/.gitkeep b/test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/custom/.gitkeep new file mode 100644 index 00000000..e69de29b From 80f6c5f7ea7ee42bf26c04be2688e14f56eb4cf2 Mon Sep 17 00:00:00 2001 From: Hilton Lima Date: Wed, 1 Nov 2023 20:26:53 +0000 Subject: [PATCH 3/4] Add blank line --- test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py b/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py index db76cd32..7d8695e0 100644 --- a/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py +++ b/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py @@ -44,6 +44,7 @@ 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( From 4547f89e084f54fc2e569db17b99ae057e527938 Mon Sep 17 00:00:00 2001 From: Hilton Lima Date: Mon, 6 Nov 2023 17:29:09 +0000 Subject: [PATCH 4/4] review changes --- .../sdk_tests/sdk_checkout/yaml_tests/yaml/custom/.gitkeep | 3 +++ .../sdk_tests/support/yaml_tests/sdk_yaml_tests.py | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/custom/.gitkeep b/test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/custom/.gitkeep index e69de29b..d08ece25 100644 --- a/test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/custom/.gitkeep +++ b/test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/custom/.gitkeep @@ -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 \ No newline at end of file diff --git a/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py b/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py index 7d8695e0..02abc905 100644 --- a/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py +++ b/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py @@ -124,7 +124,7 @@ def sdk_yaml_test_collection( def custom_yaml_test_collection( yaml_test_folder: YamlTestFolder = CUSTOM_YAML_TEST_FOLDER, ) -> YamlCollectionDeclaration: - """Declare a new collection of test suites with the 3 test suites.""" + """Declare a new collection of test suites.""" collection = YamlCollectionDeclaration( name="Custom YAML Tests", folder=yaml_test_folder ) @@ -132,15 +132,13 @@ def custom_yaml_test_collection( files = yaml_test_folder.yaml_file_paths() suites = _parse_all_yaml(yaml_files=files, yaml_version=None) - has_valid_test_case = False for suite in suites: if not suite.test_cases: continue - has_valid_test_case = True suite.sort_test_cases() collection.add_test_suite(suite) - if not has_valid_test_case: + if not collection.test_suites: return None return collection