-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(qa-checks): Add AcceptanceTestsEnabledCheck (#38736)
Co-authored-by: alafanechere <[email protected]>
- Loading branch information
1 parent
e56dc9d
commit 6db379d
Showing
12 changed files
with
245 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "connector_ops" | ||
version = "0.4.0" | ||
version = "0.5.0" | ||
description = "Packaged maintained by the connector operations team to perform CI for connectors" | ||
authors = ["Airbyte <[email protected]>"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "connectors-qa" | ||
version = "1.3.2" | ||
version = "1.4.0" | ||
description = "A package to run QA checks on Airbyte connectors, generate reports and documentation." | ||
authors = ["Airbyte <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
airbyte-ci/connectors/connectors_qa/src/connectors_qa/checks/testing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
|
||
|
||
from connector_ops.utils import Connector # type: ignore | ||
from connectors_qa.models import Check, CheckCategory, CheckResult | ||
from pydash.collections import find # type: ignore | ||
|
||
|
||
class TestingCheck(Check): | ||
category = CheckCategory.TESTING | ||
|
||
|
||
class AcceptanceTestsEnabledCheck(TestingCheck): | ||
applies_to_connector_cloud_usage = ["medium", "high"] | ||
applies_to_connector_types = ["source"] | ||
name = "Medium to High Use Connectors must enable acceptance tests" | ||
description = "Medium to High Use Connectors must enable acceptance tests via the `connectorTestSuitesOptions.suite:acceptanceTests` in their respective metadata.yaml file to ensure that the connector is working as expected." | ||
test_suite_name = "acceptanceTests" | ||
|
||
def does_not_have_acceptance_tests_enabled(self, connector: Connector) -> bool: | ||
metadata = connector.metadata | ||
connector_test_suites_options = metadata.get("connectorTestSuitesOptions", []) | ||
acceptance_tests_suite = find(connector_test_suites_options, {"suite": self.test_suite_name}) | ||
return bool(acceptance_tests_suite) is False | ||
|
||
def _run(self, connector: Connector) -> CheckResult: | ||
if self.does_not_have_acceptance_tests_enabled(connector): | ||
return self.create_check_result( | ||
connector=connector, | ||
passed=False, | ||
message=f"The {self.test_suite_name} test suite must be enabled for medium/high use connectors. Please enable this test suite in the connectorTestSuitesOptions field of the metadata.yaml file.", | ||
) | ||
return self.create_check_result( | ||
connector=connector, | ||
passed=True, | ||
message=f"{connector.cloud_usage} cloud usage connector has enabled {self.test_suite_name}.", | ||
) | ||
|
||
|
||
ENABLED_CHECKS = [AcceptanceTestsEnabledCheck()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
airbyte-ci/connectors/connectors_qa/tests/unit_tests/test_checks/test_testing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
|
||
import pytest | ||
from connector_ops.utils import ConnectorLanguage | ||
from connectors_qa.checks import testing | ||
from connectors_qa.models import CheckStatus | ||
|
||
METADATA_CASE_NO_TEST_SUITE_OPTIONS = { | ||
"foo": "bar", | ||
} | ||
|
||
METADATA_CASE_EMPTY_TEST_SUITE_OPTIONS = { | ||
"connectorTestSuitesOptions": [], | ||
} | ||
|
||
METADATA_CASE_NONE_TEST_SUITE_OPTIONS = { | ||
"connectorTestSuitesOptions": None, | ||
} | ||
|
||
METADATA_CASE_MISSING_ACCEPTANCE_TEST_SUITE_OPTIONS = { | ||
"connectorTestSuitesOptions": [ | ||
{ | ||
"suite": "unit", | ||
"testSecrets": {}, | ||
}, | ||
], | ||
} | ||
|
||
METADATA_CASE_WITH_ACCEPTANCE_TEST_SUITE_OPTIONS_NO_SECRETS = { | ||
"connectorTestSuitesOptions": [ | ||
{ | ||
"suite": testing.AcceptanceTestsEnabledCheck.test_suite_name, | ||
}, | ||
], | ||
} | ||
|
||
METADATA_CASE_WITH_ACCEPTANCE_TEST_SUITE_OPTIONS_EMPTY_SECRETS = { | ||
"connectorTestSuitesOptions": [ | ||
{ | ||
"suite": testing.AcceptanceTestsEnabledCheck.test_suite_name, | ||
"testSecrets": {}, | ||
}, | ||
], | ||
} | ||
|
||
METADATA_CASE_WITH_ACCEPTANCE_TEST_SUITE_OPTIONS_NONE_SECRETS = { | ||
"connectorTestSuitesOptions": [ | ||
{ | ||
"suite": testing.AcceptanceTestsEnabledCheck.test_suite_name, | ||
"testSecrets": None, | ||
}, | ||
], | ||
} | ||
|
||
METADATA_CASE_WITH_ACCEPTANCE_TEST_SUITE_OPTIONS = { | ||
"connectorTestSuitesOptions": [ | ||
{ | ||
"suite": testing.AcceptanceTestsEnabledCheck.test_suite_name, | ||
"testSecrets": { | ||
"testSecret": "test" | ||
}, | ||
}, | ||
{ | ||
"suite": "unit", | ||
"testSecrets": {}, | ||
}, | ||
], | ||
} | ||
|
||
THRESHOLD_USAGE_VALUES = ["high", "medium"] | ||
OTHER_USAGE_VALUES = ["low", "none", "unknown", None, ""] | ||
|
||
DYNAMIC_ACCEPTANCE_TESTS_ENABLED_CASES = [ | ||
METADATA_CASE_WITH_ACCEPTANCE_TEST_SUITE_OPTIONS, | ||
METADATA_CASE_WITH_ACCEPTANCE_TEST_SUITE_OPTIONS_NONE_SECRETS, | ||
METADATA_CASE_WITH_ACCEPTANCE_TEST_SUITE_OPTIONS_EMPTY_SECRETS, | ||
METADATA_CASE_WITH_ACCEPTANCE_TEST_SUITE_OPTIONS_NO_SECRETS, | ||
] | ||
|
||
DYNAMIC_ACCEPTANCE_TESTS_DISABLED_CASES = [ | ||
METADATA_CASE_NO_TEST_SUITE_OPTIONS, | ||
METADATA_CASE_EMPTY_TEST_SUITE_OPTIONS, | ||
METADATA_CASE_NONE_TEST_SUITE_OPTIONS, | ||
METADATA_CASE_MISSING_ACCEPTANCE_TEST_SUITE_OPTIONS, | ||
] | ||
|
||
|
||
class TestAcceptanceTestsEnabledCheck: | ||
@pytest.mark.parametrize( | ||
"cases_to_test, usage_values_to_test, expected_result", | ||
[ | ||
( | ||
DYNAMIC_ACCEPTANCE_TESTS_DISABLED_CASES + DYNAMIC_ACCEPTANCE_TESTS_ENABLED_CASES, | ||
OTHER_USAGE_VALUES, | ||
CheckStatus.SKIPPED | ||
), | ||
( | ||
DYNAMIC_ACCEPTANCE_TESTS_ENABLED_CASES, | ||
THRESHOLD_USAGE_VALUES, | ||
CheckStatus.PASSED | ||
), | ||
( | ||
DYNAMIC_ACCEPTANCE_TESTS_DISABLED_CASES, | ||
THRESHOLD_USAGE_VALUES, | ||
CheckStatus.FAILED | ||
) | ||
], | ||
) | ||
def test_check_always_passes_when_usage_threshold_is_not_met(self, mocker, cases_to_test, usage_values_to_test, expected_result): | ||
for usage_value in usage_values_to_test: | ||
for metadata_case in cases_to_test: | ||
# Arrange | ||
connector = mocker.MagicMock(cloud_usage=usage_value, metadata=metadata_case, language=ConnectorLanguage.PYTHON, connector_type="source") | ||
|
||
# Act | ||
result = testing.AcceptanceTestsEnabledCheck().run(connector) | ||
|
||
# Assert | ||
assert result.status == expected_result, f"Usage value: {usage_value}, metadata case: {metadata_case}, expected result: {expected_result}" |
Oops, something went wrong.