Skip to content

Commit

Permalink
🎉 SAT: add assert that spec.json file does not have any $ref in it (#…
Browse files Browse the repository at this point in the history
…8842)

* 8288 Add assert that spec.json file does not have any `$ref` in it

* 8288 Format

* 8288 Remove unused lines

* 8288 Bump SAT version
  • Loading branch information
Zirochkaa authored Dec 17, 2021
1 parent 5e494a9 commit 6889a89
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.1.36
Add assert that spec.json file does not have any `$ref` in it: [#8842](https://github.com/airbytehq/airbyte/pull/8842)

## 0.1.32
Add info about skipped failed tests in /test command message on GitHub: [#8691](https://github.com/airbytehq/airbyte/pull/8691)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ COPY pytest.ini setup.py ./
COPY source_acceptance_test ./source_acceptance_test
RUN pip install .

LABEL io.airbyte.version=0.1.34
LABEL io.airbyte.version=0.1.36
LABEL io.airbyte.name=airbyte/source-acceptance-test

ENTRYPOINT ["python", "-m", "pytest", "-p", "source_acceptance_test.plugin", "-r", "fEsx"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#

import json
import logging
import re
from collections import Counter, defaultdict
Expand Down Expand Up @@ -41,6 +42,10 @@ def actual_connector_spec_fixture(request: BaseTest, docker_runner):
request.spec_cache = spec
return request.spec_cache

@pytest.fixture(name="connector_spec_dict")
def connector_spec_dict_fixture(request: BaseTest, actual_connector_spec):
return json.loads(actual_connector_spec.json())

def test_match_expected(
self, connector_spec: ConnectorSpecification, actual_connector_spec: ConnectorSpecification, connector_config: SecretDict
):
Expand Down Expand Up @@ -69,6 +74,12 @@ def test_has_secret(self):
def test_secret_never_in_the_output(self):
"""This test should be injected into any docker command it needs to know current config and spec"""

def test_defined_refs_exist_in_json_spec_file(self, connector_spec_dict: dict):
"""Checking for the presence of unresolved `$ref`s values within each json spec file"""
check_result = find_key_inside_schema(schema_item=connector_spec_dict)

assert not check_result, "Found unresolved `$refs` value in spec.json file"

def test_oauth_flow_parameters(self, actual_connector_spec: ConnectorSpecification):
"""
Check if connector has correct oauth flow parameters according to https://docs.airbyte.io/connector-development/connector-specification-reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,127 @@
from source_acceptance_test.tests.test_core import TestSpec as _TestSpec


@pytest.mark.parametrize(
"connector_spec, should_fail",
[
(
{
"connectionSpecification": {
"type": "object",
"properties": {
"client_id": {"type": "string"},
"client_secret": {"type": "string"},
"access_token": {"type": "string"},
"refresh_token": {"type": "string"},
"$ref": None,
},
}
},
True,
),
(
{
"advanced_auth": {
"auth_flow_type": "oauth2.0",
"predicate_key": ["credentials", "auth_type"],
"predicate_value": "Client",
"oauth_config_specification": {
"complete_oauth_output_specification": {
"type": "object",
"properties": {"refresh_token": {"type": "string"}, "$ref": None},
}
},
}
},
True,
),
(
{
"advanced_auth": {
"auth_flow_type": "oauth2.0",
"predicate_key": ["credentials", "auth_type"],
"predicate_value": "Client",
"oauth_config_specification": {
"complete_oauth_server_input_specification": {
"type": "object",
"properties": {"refresh_token": {"type": "string"}, "$ref": None},
}
},
}
},
True,
),
(
{
"advanced_auth": {
"auth_flow_type": "oauth2.0",
"predicate_key": ["credentials", "auth_type"],
"predicate_value": "Client",
"oauth_config_specification": {
"complete_oauth_server_output_specification": {
"type": "object",
"properties": {"refresh_token": {"type": "string"}, "$ref": None},
}
},
}
},
True,
),
(
{
"connectionSpecification": {
"type": "object",
"properties": {
"client_id": {"type": "string"},
"client_secret": {"type": "string"},
"access_token": {"type": "string"},
"refresh_token": {"type": "string"},
},
}
},
False,
),
(
{
"connectionSpecification": {
"type": "object",
"properties": {
"client_id": {"type": "string"},
"client_secret": {"type": "string"},
"access_token": {"type": "string"},
"refresh_token": {"type": "string"},
},
},
"advanced_auth": {
"auth_flow_type": "oauth2.0",
"predicate_key": ["credentials", "auth_type"],
"predicate_value": "Client",
"oauth_config_specification": {
"complete_oauth_server_output_specification": {
"type": "object",
"properties": {"refresh_token": {"type": "string"}},
}
},
},
},
False,
),
({"$ref": None}, True),
({"properties": {"user": {"$ref": None}}}, True),
({"properties": {"user": {"$ref": "user.json"}}}, True),
({"properties": {"user": {"type": "object", "properties": {"username": {"type": "string"}}}}}, False),
({"properties": {"fake_items": {"type": "array", "items": {"$ref": "fake_item.json"}}}}, True),
],
)
def test_ref_in_spec_schemas(connector_spec, should_fail):
t = _TestSpec()
if should_fail is True:
with pytest.raises(AssertionError):
t.test_defined_refs_exist_in_json_spec_file(connector_spec_dict=connector_spec)
else:
t.test_defined_refs_exist_in_json_spec_file(connector_spec_dict=connector_spec)


@pytest.mark.parametrize(
"schema, cursors, should_fail",
[
Expand Down

0 comments on commit 6889a89

Please sign in to comment.