Пример #1
0
 def test__parse_connection_specification(self, mocker):
     mocker.patch.object(renderers, "parse_fields")
     schema = {"required": ["foo"], "properties": {"foo": "bar"}}
     definition = mocker.Mock()
     spec_renderer = renderers.ConnectorSpecificationRenderer("my_resource_name", definition)
     parsed_schema = spec_renderer._parse_connection_specification(schema)
     assert renderers.parse_fields.call_count == 1
     assert parsed_schema[0], renderers.parse_fields.return_value
     renderers.parse_fields.assert_called_with(["foo"], {"foo": "bar"})
Пример #2
0
 def test__parse_connection_specification_one_of(self, mocker):
     mocker.patch.object(renderers, "parse_fields")
     schema = {"oneOf": [{"required": ["foo"], "properties": {"foo": "bar"}}, {"required": ["free"], "properties": {"free": "beer"}}]}
     spec_renderer = renderers.ConnectorSpecificationRenderer("my_resource_name", mocker.Mock())
     parsed_schema = spec_renderer._parse_connection_specification(schema)
     assert renderers.parse_fields.call_count == 2
     assert parsed_schema[0], renderers.parse_fields.return_value
     assert parsed_schema[1], renderers.parse_fields.return_value
     assert len(parsed_schema) == len(schema["oneOf"])
     renderers.parse_fields.assert_called_with(["free"], {"free": "beer"})
Пример #3
0
 def test__render(self, mocker):
     mocker.patch.object(renderers.ConnectorSpecificationRenderer, "_parse_connection_specification")
     mocker.patch.object(renderers.ConnectorSpecificationRenderer, "TEMPLATE")
     spec_renderer = renderers.ConnectorSpecificationRenderer("my_resource_name", mocker.Mock())
     rendered = spec_renderer._render()
     spec_renderer._parse_connection_specification.assert_called_with(spec_renderer.definition.specification.connection_specification)
     spec_renderer.TEMPLATE.render.assert_called_with(
         {
             "resource_name": spec_renderer.resource_name,
             "definition": spec_renderer.definition,
             "configuration_fields": spec_renderer._parse_connection_specification.return_value,
         }
     )
     assert rendered == spec_renderer.TEMPLATE.render.return_value
Пример #4
0
def import_source_or_destination(
    api_client: airbyte_api_client.ApiClient,
    workspace_id: str,
    ResourceClass: Type[Union[UnmanagedSource, UnmanagedDestination]],
    resource_to_get: str,
) -> str:
    """Helper function to import sources & destinations.

    Args:
        api_client (airbyte_api_client.ApiClient): the Airbyte API client.
        workspace_id (str): current Airbyte workspace id.
        ResourceClass (Union[UnmanagedSource, UnmanagedDestination]): the Airbyte Resource Class.
        resource_to_get (str): the name or ID of the resource in the current Airbyte workspace id.

    Returns:
        str: The generated import message.
    """
    remote_configuration = json.loads(
        get_json_representation(api_client, workspace_id, ResourceClass,
                                resource_to_get))

    resource_type = ResourceClass.__name__.lower()

    definition = definitions.factory(
        resource_type, api_client, workspace_id,
        remote_configuration[f"{resource_type}_definition_id"])

    renderer = renderers.ConnectorSpecificationRenderer(
        remote_configuration["name"], definition)

    new_configuration_path = renderer.import_configuration(
        project_path=".",
        configuration=remote_configuration["connection_configuration"])
    managed_resource, state = resources.factory(
        api_client, workspace_id, new_configuration_path).manage(
            remote_configuration[f"{resource_type}_id"])
    message = f"✅ - Imported {resource_type} {managed_resource.name} in {new_configuration_path}. State stored in {state.path}"
    click.echo(click.style(message, fg="green"))
    message = f"⚠️  - Please update any secrets stored in {new_configuration_path}"
    click.echo(click.style(message, fg="yellow"))
Пример #5
0
    def test_write_yaml(self, mocker, overwrite):

        mocker.patch.object(renderers.ConnectorSpecificationRenderer, "get_output_path")
        mocker.patch.object(renderers.ConnectorSpecificationRenderer, "_parse_connection_specification")
        mocker.patch.object(
            renderers.ConnectorSpecificationRenderer, "TEMPLATE", mocker.Mock(render=mocker.Mock(return_value="rendered_string"))
        )
        mocker.patch.object(renderers.ConnectorSpecificationRenderer, "_confirm_overwrite", mocker.Mock(return_value=overwrite))

        spec_renderer = renderers.ConnectorSpecificationRenderer("my_resource_name", mocker.Mock(type="source"))
        if overwrite:
            with patch("builtins.open", mock_open()) as mock_file:
                output_path = spec_renderer.write_yaml(".")
            spec_renderer.TEMPLATE.render.assert_called_with(
                {
                    "resource_name": "my_resource_name",
                    "definition": spec_renderer.definition,
                    "configuration_fields": spec_renderer._parse_connection_specification.return_value,
                }
            )
            mock_file.assert_called_with(output_path, "w")
        else:
            output_path = spec_renderer.write_yaml(".")
        assert output_path == spec_renderer.get_output_path.return_value
Пример #6
0
 def test_init(self, mocker):
     assert renderers.ConnectorSpecificationRenderer.TEMPLATE == renderers.JINJA_ENV.get_template("source_or_destination.yaml.j2")
     definition = mocker.Mock()
     spec_renderer = renderers.ConnectorSpecificationRenderer("my_resource_name", definition)
     assert spec_renderer.resource_name == "my_resource_name"
     assert spec_renderer.definition == definition