Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rquidute committed Nov 9, 2023
1 parent 817f72a commit beb46b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
40 changes: 22 additions & 18 deletions app/tests/python_tests/test_sdk_python_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# flake8: noqa
# Ignore flake8 check for this file
from pathlib import Path
from unittest import mock

import pytest

Expand All @@ -33,31 +34,34 @@
sdk_python_test_collection,
)

VERSION_FILE_FILENAME = ".version"
VERSION_FILE_PATH = Path("/app/backend/test_collections/sdk_tests/sdk_checkout/")


@pytest.fixture
def python_test_collection() -> PythonCollectionDeclaration:
test_sdk_python_path = Path(__file__).parent / "test_python_script"
folder = PythonTestFolder(
path=test_sdk_python_path, filename_pattern="UnitTest_TC_*"
)
return sdk_python_test_collection(folder)
with mock.patch.object(Path, "exists", return_value=True), mock.patch(
"test_collections.sdk_tests.support.python_testing.models.python_test_folder.open",
new=mock.mock_open(read_data="unit-test-python-version"),
):
folder = PythonTestFolder(
path=test_sdk_python_path, filename_pattern="UnitTest_TC_*"
)
return sdk_python_test_collection(folder)


# def test_sdk_python_test_collection(
# python_test_collection: PythonCollectionDeclaration,
# ) -> None:
# assert python_test_collection.name == "SDK Python Tests"
# assert len(python_test_collection.test_suites.keys()) == 1
def test_sdk_python_test_collection(
python_test_collection: PythonCollectionDeclaration,
) -> None:
assert python_test_collection.name == "SDK Python Tests"
assert len(python_test_collection.test_suites.keys()) == 1

# # test version number
# test_sdk_python_version_path = VERSION_FILE_PATH / VERSION_FILE_FILENAME
# with open(test_sdk_python_version_path, "r") as version_file:
# assert (
# python_test_collection.python_test_version == version_file.read().rstrip()
# )
# test version number
test_sdk_python_version_path = (
"/app/backend/app/tests/python_tests/test_python_script/.version"
)
with open(test_sdk_python_version_path, "r") as version_file:
assert (
python_test_collection.python_test_version == version_file.read().rstrip()
)


def test_automated_suite(python_test_collection: PythonCollectionDeclaration) -> None:
Expand Down
36 changes: 21 additions & 15 deletions app/tests/yaml_tests/test_sdk_yaml_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#
from pathlib import Path
from unittest import mock

import pytest

Expand All @@ -31,25 +32,30 @@
sdk_yaml_test_collection,
)

VERSION_FILE_FILENAME = ".version"
VERSION_FILE_PATH = Path("/app/backend/test_collections/sdk_tests/sdk_checkout/")


@pytest.fixture
def yaml_collection() -> YamlCollectionDeclaration:
test_sdk_yaml_path = Path(__file__).parent / "test_yamls"
folder = YamlTestFolder(path=test_sdk_yaml_path, filename_pattern="UnitTest_TC_*")
return sdk_yaml_test_collection(folder)


# def test_sdk_yaml_collection(yaml_collection: YamlCollectionDeclaration) -> None:
# assert yaml_collection.name == "SDK YAML Tests"
# assert len(yaml_collection.test_suites.keys()) == 3

# # test version number
# test_sdk_yaml_version_path = VERSION_FILE_PATH / VERSION_FILE_FILENAME
# with open(test_sdk_yaml_version_path, "r") as version_file:
# assert yaml_collection.yaml_version == version_file.read().rstrip()
with mock.patch.object(Path, "exists", return_value=True), mock.patch(
"test_collections.sdk_tests.support.yaml_tests.models.yaml_test_folder.open",
new=mock.mock_open(read_data="unit-test-yaml-version"),
):
folder = YamlTestFolder(
path=test_sdk_yaml_path, filename_pattern="UnitTest_TC_*"
)
return sdk_yaml_test_collection(folder)


def test_sdk_yaml_collection(
yaml_collection: YamlCollectionDeclaration,
) -> None:
assert yaml_collection.name == "SDK YAML Tests"
assert len(yaml_collection.test_suites.keys()) == 3

# test version number
test_sdk_yaml_path = "/app/backend/app/tests/yaml_tests/test_yamls/.version"
with open(test_sdk_yaml_path, "r") as version_file:
assert yaml_collection.yaml_version == version_file.read().rstrip()


def test_manual_suite(yaml_collection: YamlCollectionDeclaration) -> None:
Expand Down

0 comments on commit beb46b3

Please sign in to comment.