Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
natikgadzhi committed Dec 16, 2024
1 parent d6e0f14 commit 5ae7cfe
Show file tree
Hide file tree
Showing 300 changed files with 4,697 additions and 4,763 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@

DOCUMENTATION_FILE_PATH_IN_AIRBYTE_REPO = Path("docs/contributing-to-airbyte/resources/qa-checks.md")


@pytest.fixture
def airbyte_repo():
return git.Repo(search_parent_directories=True)


@pytest.mark.asyncio
async def test_generated_qa_checks_documentation_is_up_to_date(airbyte_repo, tmp_path):
# Arrange
current_doc = (airbyte_repo.working_dir / DOCUMENTATION_FILE_PATH_IN_AIRBYTE_REPO).read_text()
newly_generated_doc_path = tmp_path / "qa-checks.md"

# Act
await CliRunner().invoke(generate_documentation, [str(tmp_path / "qa-checks.md")], catch_exceptions=False)

# Assert
suggested_command = f"connectors-qa generate-documentation {DOCUMENTATION_FILE_PATH_IN_AIRBYTE_REPO}"
assert newly_generated_doc_path.read_text() == current_doc, f"The generated documentation is not up to date. Please run `{suggested_command}` and commit the changes."
assert (
newly_generated_doc_path.read_text() == current_doc
), f"The generated documentation is not up to date. Please run `{suggested_command}` and commit the changes."
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_fail_when_icon_path_is_not_named_icon_svg(self, tmp_path, mocker):
assert result.status == CheckStatus.FAILED
assert result.message == "Icon file is not a SVG file"


def test_fail_when_icon_file_is_not_valid_svg(self, tmp_path, mocker):
# Arrange
connector = mocker.MagicMock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_fail_when_documentation_file_path_does_not_exists(self, mocker, tmp_pat
ab_internal_sl=300,
language="python",
connector_type="source",
documentation_file_path=tmp_path / "not_existing_documentation.md"
documentation_file_path=tmp_path / "not_existing_documentation.md",
)

# Act
Expand All @@ -217,11 +217,7 @@ def test_fail_when_documentation_file_path_does_not_exists(self, mocker, tmp_pat
def test_fail_when_documentation_file_path_is_none(self, mocker):
# Arrange
connector = mocker.Mock(
technical_name="test-connector",
ab_internal_sl=300,
language="python",
connector_type="source",
documentation_file_path=None
technical_name="test-connector", ab_internal_sl=300, language="python", connector_type="source", documentation_file_path=None
)

# Act
Expand Down Expand Up @@ -263,34 +259,28 @@ def test_fail_when_documentation_file_has_missing_headers(self, connector_with_i
assert "Actual Heading: 'For Airbyte Cloud:'. Expected Heading: 'Setup guide'" in result.message

def test_fail_when_documentation_file_not_have_all_required_fields_in_prerequisites_section_content(
self,
connector_with_invalid_documentation
self, connector_with_invalid_documentation
):
# Act
result = documentation.CheckPrerequisitesSectionDescribesRequiredFieldsFromSpec()._run(
connector_with_invalid_documentation
)
result = documentation.CheckPrerequisitesSectionDescribesRequiredFieldsFromSpec()._run(connector_with_invalid_documentation)

# Assert
assert result.status == CheckStatus.FAILED
assert "Missing descriptions for required spec fields: github repositories" in result.message

def test_fail_when_documentation_file_has_invalid_source_section_content(
self,
connector_with_invalid_documentation
):
def test_fail_when_documentation_file_has_invalid_source_section_content(self, connector_with_invalid_documentation):
# Act
result = documentation.CheckSourceSectionContent()._run(connector_with_invalid_documentation)

# Assert
assert result.status == CheckStatus.FAILED
assert "Connector GitHub section content does not follow standard template:" in result.message
assert "+ This page contains the setup guide and reference information for the [GitHub]({docs_link}) source connector." in result.message
assert (
"+ This page contains the setup guide and reference information for the [GitHub]({docs_link}) source connector."
in result.message
)

def test_fail_when_documentation_file_has_invalid_for_airbyte_cloud_section_content(
self,
connector_with_invalid_documentation
):
def test_fail_when_documentation_file_has_invalid_for_airbyte_cloud_section_content(self, connector_with_invalid_documentation):
# Act
result = documentation.CheckForAirbyteCloudSectionContent()._run(connector_with_invalid_documentation)

Expand All @@ -299,10 +289,7 @@ def test_fail_when_documentation_file_has_invalid_for_airbyte_cloud_section_cont
assert "Connector For Airbyte Cloud: section content does not follow standard template:" in result.message
assert "+ 1. [Log into your Airbyte Cloud](https://cloud.airbyte.com/workspaces) account." in result.message

def test_fail_when_documentation_file_has_invalid_for_airbyte_open_section_content(
self,
connector_with_invalid_documentation
):
def test_fail_when_documentation_file_has_invalid_for_airbyte_open_section_content(self, connector_with_invalid_documentation):
# Act
result = documentation.CheckForAirbyteOpenSectionContent()._run(connector_with_invalid_documentation)

Expand All @@ -311,23 +298,19 @@ def test_fail_when_documentation_file_has_invalid_for_airbyte_open_section_conte
assert "Connector For Airbyte Open Source: section content does not follow standard template" in result.message
assert "+ 1. Navigate to the Airbyte Open Source dashboard." in result.message

def test_fail_when_documentation_file_has_invalid_supported_sync_modes_section_content(
self,
connector_with_invalid_documentation
):
def test_fail_when_documentation_file_has_invalid_supported_sync_modes_section_content(self, connector_with_invalid_documentation):
# Act
result = documentation.CheckSupportedSyncModesSectionContent()._run(connector_with_invalid_documentation)

# Assert
assert result.status == CheckStatus.FAILED
assert "Connector Supported sync modes section content does not follow standard template:" in result.message
assert ("+ The GitHub source connector supports the following"
" [sync modes](https://docs.airbyte.com/cloud/core-concepts/#connection-sync-modes):") in result.message
assert (
"+ The GitHub source connector supports the following"
" [sync modes](https://docs.airbyte.com/cloud/core-concepts/#connection-sync-modes):"
) in result.message

def test_fail_when_documentation_file_has_invalid_tutorials_section_content(
self,
connector_with_invalid_documentation
):
def test_fail_when_documentation_file_has_invalid_tutorials_section_content(self, connector_with_invalid_documentation):
# Act
result = documentation.CheckTutorialsSectionContent()._run(connector_with_invalid_documentation)

Expand All @@ -336,10 +319,7 @@ def test_fail_when_documentation_file_has_invalid_tutorials_section_content(
assert "Connector Tutorials section content does not follow standard template:" in result.message
assert "+ Now that you have set up the GitHub source connector, check out the following GitHub tutorials:" in result.message

def test_fail_when_documentation_file_has_invalid_changelog_section_content(
self,
connector_with_invalid_documentation
):
def test_fail_when_documentation_file_has_invalid_changelog_section_content(self, connector_with_invalid_documentation):
# Act
result = documentation.CheckChangelogSectionContent()._run(connector_with_invalid_documentation)

Expand All @@ -356,87 +336,63 @@ def test_pass_when_documentation_file_has_correct_headers(self, connector_with_c
assert result.status == CheckStatus.PASSED
assert result.message == "Documentation guidelines are followed"

def test_pass_when_documentation_file_has_correct_prerequisites_section_content(
self,
connector_with_correct_documentation
):
def test_pass_when_documentation_file_has_correct_prerequisites_section_content(self, connector_with_correct_documentation):
# Act
result = documentation.CheckPrerequisitesSectionDescribesRequiredFieldsFromSpec()._run(connector_with_correct_documentation)

# Assert
assert result.status == CheckStatus.PASSED
assert "All required fields from spec are present in the connector documentation" in result.message

def test_pass_when_documentation_file_has_correct_source_section_content(
self,
connector_with_correct_documentation
):
def test_pass_when_documentation_file_has_correct_source_section_content(self, connector_with_correct_documentation):
# Act
result = documentation.CheckSourceSectionContent()._run(connector_with_correct_documentation)

# Assert
assert result.status == CheckStatus.PASSED
assert "Documentation guidelines are followed" in result.message

def test_pass_when_documentation_file_has_correct_for_airbyte_cloud_section_content(
self,
connector_with_correct_documentation
):
def test_pass_when_documentation_file_has_correct_for_airbyte_cloud_section_content(self, connector_with_correct_documentation):
# Act
result = documentation.CheckForAirbyteCloudSectionContent()._run(connector_with_correct_documentation)

# Assert
assert result.status == CheckStatus.PASSED
assert "Documentation guidelines are followed" in result.message

def test_pass_when_documentation_file_has_correct_for_airbyte_open_section_content(
self,
connector_with_correct_documentation
):
def test_pass_when_documentation_file_has_correct_for_airbyte_open_section_content(self, connector_with_correct_documentation):
# Act
result = documentation.CheckForAirbyteOpenSectionContent()._run(connector_with_correct_documentation)

# Assert
assert result.status == CheckStatus.PASSED
assert "Documentation guidelines are followed" in result.message

def test_pass_when_documentation_file_has_correct_supported_sync_modes_section_content(
self,
connector_with_correct_documentation
):
def test_pass_when_documentation_file_has_correct_supported_sync_modes_section_content(self, connector_with_correct_documentation):
# Act
result = documentation.CheckSupportedSyncModesSectionContent()._run(connector_with_correct_documentation)

# Assert
assert result.status == CheckStatus.PASSED
assert "Documentation guidelines are followed" in result.message

def test_pass_when_documentation_file_has_correct_tutorials_section_content(
self,
connector_with_correct_documentation
):
def test_pass_when_documentation_file_has_correct_tutorials_section_content(self, connector_with_correct_documentation):
# Act
result = documentation.CheckTutorialsSectionContent()._run(connector_with_correct_documentation)

# Assert
assert result.status == CheckStatus.PASSED
assert "Documentation guidelines are followed" in result.message

def test_pass_when_documentation_file_has_correct_headers_order(
self,
connector_with_correct_documentation
):
def test_pass_when_documentation_file_has_correct_headers_order(self, connector_with_correct_documentation):
# Act
result = documentation.CheckDocumentationHeadersOrder()._run(connector_with_correct_documentation)

# Assert
assert result.status == CheckStatus.PASSED
assert "Documentation guidelines are followed" in result.message

def test_pass_when_documentation_file_has_correct_changelog_section_content(
self,
connector_with_correct_documentation
):
def test_pass_when_documentation_file_has_correct_changelog_section_content(self, connector_with_correct_documentation):
# Act
result = documentation.CheckChangelogSectionContent()._run(connector_with_correct_documentation)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def test_pass_if_publish_to_pypi_is_disabled(self, mocker):
assert result.status == CheckStatus.PASSED
assert "PyPi publishing is declared" in result.message


class TestCheckConnectorLicense:
def test_fail_when_license_is_missing(self, mocker):
# Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
"connectorTestSuitesOptions": [
{
"suite": testing.AcceptanceTestsEnabledCheck.test_suite_name,
"testSecrets": {
"testSecret": "test"
},
"testSecrets": {"testSecret": "test"},
},
{
"suite": "unit",
Expand All @@ -71,10 +69,10 @@
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,
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 = [
Expand All @@ -89,21 +87,9 @@ 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
)
(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):
Expand All @@ -115,11 +101,13 @@ def test_check_always_passes_when_usage_threshold_is_not_met(self, mocker, cases
metadata=metadata_case,
language=ConnectorLanguage.PYTHON,
connector_type="source",
ab_internal_sl=100
ab_internal_sl=100,
)

# 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}"
assert (
result.status == expected_result
), f"Usage value: {usage_value}, metadata case: {metadata_case}, expected result: {expected_result}"
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ class BaseBackend(ABC):
"""

@abstractmethod
def write(self, airbyte_messages: Iterable[AirbyteMessage]) -> None:
...
def write(self, airbyte_messages: Iterable[AirbyteMessage]) -> None: ...
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ def _get_filepaths_and_messages(self, message: AirbyteMessage) -> tuple[tuple[st
stream_file_path_data_only = self.record_per_stream_directory / f"{sanitize_stream_name(stream_name)}_data_only.jsonl"
self.record_per_stream_paths[stream_name] = stream_file_path
self.record_per_stream_paths_data_only[stream_name] = stream_file_path_data_only
return (self.RELATIVE_RECORDS_PATH, str(stream_file_path), str(stream_file_path_data_only),), (
return (
self.RELATIVE_RECORDS_PATH,
str(stream_file_path),
str(stream_file_path_data_only),
), (
message.json(sort_keys=True),
message.json(sort_keys=True),
json.dumps(message.record.data, sort_keys=True),
Expand Down
22 changes: 12 additions & 10 deletions airbyte-ci/connectors/live-tests/src/live_tests/commons/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ async def bind_container(self, container: dagger.Container) -> dagger.Container:
python_version_minor_only = ".".join(python_version.split(".")[:-1])
requests_cert_path = f"/usr/local/lib/python{python_version_minor_only}/site-packages/certifi/cacert.pem"
try:
return await (
container.with_service_binding(self.hostname, await self.get_service())
.with_mounted_cache("/mitmproxy_dir", self.mitmproxy_dir_cache)
.with_exec(["cp", cert_path_in_volume, requests_cert_path])
.with_exec(["cp", cert_path_in_volume, ca_certificate_path])
# The following command make the container use the proxy for all outgoing HTTP requests
.with_env_variable("REQUESTS_CA_BUNDLE", requests_cert_path)
.with_exec(["update-ca-certificates"])
.with_env_variable("http_proxy", f"{self.hostname}:{self.PROXY_PORT}")
.with_env_variable("https_proxy", f"{self.hostname}:{self.PROXY_PORT}")
return (
await (
container.with_service_binding(self.hostname, await self.get_service())
.with_mounted_cache("/mitmproxy_dir", self.mitmproxy_dir_cache)
.with_exec(["cp", cert_path_in_volume, requests_cert_path])
.with_exec(["cp", cert_path_in_volume, ca_certificate_path])
# The following command make the container use the proxy for all outgoing HTTP requests
.with_env_variable("REQUESTS_CA_BUNDLE", requests_cert_path)
.with_exec(["update-ca-certificates"])
.with_env_variable("http_proxy", f"{self.hostname}:{self.PROXY_PORT}")
.with_env_variable("https_proxy", f"{self.hostname}:{self.PROXY_PORT}")
)
)
except dagger.DaggerError as e:
# This is likely hapenning on Java connector images whose certificates location is different
Expand Down
10 changes: 5 additions & 5 deletions airbyte-ci/connectors/live-tests/src/live_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ def pytest_configure(config: Config) -> None:
prompt_for_confirmation(user_email)

track_usage(
"production-ci"
if config.stash[stash_keys.IS_PRODUCTION_CI]
else "local-ci"
if config.stash[stash_keys.RUN_IN_AIRBYTE_CI]
else user_email,
(
"production-ci"
if config.stash[stash_keys.IS_PRODUCTION_CI]
else "local-ci" if config.stash[stash_keys.RUN_IN_AIRBYTE_CI] else user_email
),
vars(config.option),
)
config.stash[stash_keys.AIRBYTE_API_KEY] = get_airbyte_api_key()
Expand Down
Loading

0 comments on commit 5ae7cfe

Please sign in to comment.