Skip to content

Commit

Permalink
🐛 octavia-cli: use list endpoint instead of list_latest (#11505)
Browse files Browse the repository at this point in the history
  • Loading branch information
alafanechere authored Mar 30, 2022
1 parent a659b8c commit 9f21fae
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 132 deletions.
128 changes: 128 additions & 0 deletions octavia-cli/integration_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#

import os

import pytest
import yaml
from octavia_cli.apply.resources import Connection, Destination, Source
from octavia_cli.entrypoint import get_api_client, get_workspace_id
from octavia_cli.init.commands import DIRECTORIES_TO_CREATE as OCTAVIA_PROJECT_DIRECTORIES


def silent_remove(path):
try:
os.remove(path)
return True
except FileNotFoundError:
return False


@pytest.fixture
def octavia_tmp_project_directory(tmpdir):
for directory in OCTAVIA_PROJECT_DIRECTORIES:
tmpdir.mkdir(directory)
return tmpdir


@pytest.fixture(scope="session")
def octavia_test_project_directory():
return f"{os.path.dirname(__file__)}/configurations"


@pytest.fixture(scope="session")
def api_client():
return get_api_client("http://localhost:8000")


@pytest.fixture(scope="session")
def workspace_id(api_client):
return get_workspace_id(api_client, None)


@pytest.fixture(scope="session")
def source_configuration_and_path(octavia_test_project_directory):
path = f"{octavia_test_project_directory}/sources/poke/configuration.yaml"
with open(path, "r") as f:
local_configuration = yaml.safe_load(f)
return local_configuration, path


@pytest.fixture(scope="session")
def source_state_path(octavia_test_project_directory):
state_path = f"{octavia_test_project_directory}/sources/poke/state.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)


@pytest.fixture(scope="session")
def source(api_client, workspace_id, source_configuration_and_path, source_state_path):
configuration, path = source_configuration_and_path
source = Source(api_client, workspace_id, configuration, path)
yield source
source.api_instance.delete_source(source.resource_id_request_body)


@pytest.fixture(scope="session")
def destination_configuration_and_path(octavia_test_project_directory):
path = f"{octavia_test_project_directory}/destinations/postgres/configuration.yaml"
with open(path, "r") as f:
local_configuration = yaml.safe_load(f)
return local_configuration, path


@pytest.fixture(scope="session")
def destination_state_path(octavia_test_project_directory):
state_path = f"{octavia_test_project_directory}/destinations/postgres/state.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)


@pytest.fixture(scope="session")
def destination(api_client, workspace_id, destination_configuration_and_path, destination_state_path):
configuration, path = destination_configuration_and_path
destination = Destination(api_client, workspace_id, configuration, path)
yield destination
destination.api_instance.delete_destination(destination.resource_id_request_body)


@pytest.fixture(scope="session")
def connection_configuration_and_path(octavia_test_project_directory):
path = f"{octavia_test_project_directory}/connections/poke_to_pg/configuration.yaml"
with open(path, "r") as f:
local_configuration = yaml.safe_load(f)
return local_configuration, path


@pytest.fixture(scope="session")
def connection_state_path(octavia_test_project_directory):
state_path = f"{octavia_test_project_directory}/connections/poke_to_pg/state.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)


def updated_connection_configuration_and_path(octavia_test_project_directory, source, destination):
path = f"{octavia_test_project_directory}/connections/poke_to_pg/configuration.yaml"
edited_path = f"{octavia_test_project_directory}/connections/poke_to_pg/updated_configuration.yaml"
with open(path, "r") as dumb_local_configuration_file:
local_configuration = yaml.safe_load(dumb_local_configuration_file)
local_configuration["source_id"] = source.resource_id
local_configuration["destination_id"] = destination.resource_id
local_configuration["configuration"]["sourceId"] = source.resource_id
local_configuration["configuration"]["destinationId"] = destination.resource_id
with open(edited_path, "w") as updated_configuration_file:
yaml.dump(local_configuration, updated_configuration_file)
return local_configuration, edited_path


@pytest.fixture(scope="session")
def connection(api_client, workspace_id, octavia_test_project_directory, source, destination):
configuration, configuration_path = updated_connection_configuration_and_path(octavia_test_project_directory, source, destination)
connection = Connection(api_client, workspace_id, configuration, configuration_path)
yield connection
connection.api_instance.delete_connection(connection.resource_id_request_body)
silent_remove(configuration_path)
107 changes: 1 addition & 106 deletions octavia-cli/integration_tests/test_apply/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,11 @@
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#

import os

import pytest
import yaml
from octavia_cli.apply.resources import Connection, Destination, Source
from octavia_cli.entrypoint import get_api_client, get_workspace_id

pytestmark = pytest.mark.integration


@pytest.fixture(scope="module")
def api_client():
return get_api_client("http://localhost:8000")


@pytest.fixture(scope="module")
def workspace_id(api_client):
return get_workspace_id(api_client, None)


@pytest.fixture(scope="module")
def source_configuration_and_path():
path = f"{os.path.dirname(__file__)}/configurations/sources/poke/configuration.yaml"
with open(path, "r") as f:
local_configuration = yaml.safe_load(f)
return local_configuration, path


def silent_remove(path):
try:
os.remove(path)
return True
except FileNotFoundError:
return False


@pytest.fixture(scope="module")
def source_state_path():
state_path = f"{os.path.dirname(__file__)}/configurations/sources/poke/state.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)


@pytest.fixture(scope="module")
def source(api_client, workspace_id, source_configuration_and_path, source_state_path):
configuration, path = source_configuration_and_path
source = Source(api_client, workspace_id, configuration, path)
yield source
source.api_instance.delete_source(source.resource_id_request_body)


def test_source_lifecycle(source):
assert not source.was_created
source.create()
Expand All @@ -67,30 +20,6 @@ def test_source_lifecycle(source):
assert source.catalog["streams"][0]["config"]["aliasName"] == "pokemon"


@pytest.fixture(scope="module")
def destination_configuration_and_path():
path = f"{os.path.dirname(__file__)}/configurations/destinations/postgres/configuration.yaml"
with open(path, "r") as f:
local_configuration = yaml.safe_load(f)
return local_configuration, path


@pytest.fixture(scope="module")
def destination_state_path():
state_path = f"{os.path.dirname(__file__)}/configurations/destinations/postgres/state.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)


@pytest.fixture(scope="module")
def destination(api_client, workspace_id, destination_configuration_and_path, destination_state_path):
configuration, path = destination_configuration_and_path
destination = Destination(api_client, workspace_id, configuration, path)
yield destination
destination.api_instance.delete_destination(destination.resource_id_request_body)


def test_destination_lifecycle(destination):
assert not destination.was_created
destination.create()
Expand All @@ -103,41 +32,9 @@ def test_destination_lifecycle(destination):
assert not destination.get_diff_with_remote_resource()


@pytest.fixture(scope="module")
def connection_configuration_and_path():
path = f"{os.path.dirname(__file__)}/configurations/connections/poke_to_pg/configuration.yaml"
with open(path, "r") as f:
local_configuration = yaml.safe_load(f)
return local_configuration, path


@pytest.fixture(scope="module")
def connection_state_path():
state_path = f"{os.path.dirname(__file__)}/configurations/connections/poke_to_pg/state.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)


def updated_connection_configuration_and_path(source, destination):
path = f"{os.path.dirname(__file__)}/configurations/connections/poke_to_pg/configuration.yaml"
edited_path = f"{os.path.dirname(__file__)}/configurations/connections/poke_to_pg/updated_configuration.yaml"
with open(path, "r") as dumb_local_configuration_file:
local_configuration = yaml.safe_load(dumb_local_configuration_file)
local_configuration["source_id"] = source.resource_id
local_configuration["destination_id"] = destination.resource_id
local_configuration["configuration"]["sourceId"] = source.resource_id
local_configuration["configuration"]["destinationId"] = destination.resource_id
with open(edited_path, "w") as updated_configuration_file:
yaml.dump(local_configuration, updated_configuration_file)
return local_configuration, edited_path


def test_connection_lifecycle(source, destination, api_client, workspace_id, connection_state_path):
def test_connection_lifecycle(source, destination, connection):
assert source.was_created
assert destination.was_created
configuration, configuration_path = updated_connection_configuration_and_path(source, destination)
connection = Connection(api_client, workspace_id, configuration, configuration_path)
assert not connection.was_created
connection.create()
connection.state = connection._get_state_from_file()
Expand All @@ -147,5 +44,3 @@ def test_connection_lifecycle(source, destination, api_client, workspace_id, con
assert 'changed from "active" to "inactive"' in connection.get_diff_with_remote_resource()
connection.update()
assert not connection.get_diff_with_remote_resource()
connection.api_instance.delete_connection(connection.resource_id_request_body)
silent_remove(configuration_path)
13 changes: 0 additions & 13 deletions octavia-cli/integration_tests/test_generate/conftest.py

This file was deleted.

13 changes: 7 additions & 6 deletions octavia-cli/integration_tests/test_generate/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from octavia_cli.generate.renderers import ConnectionRenderer, ConnectorSpecificationRenderer

pytestmark = pytest.mark.integration

SOURCE_SPECS = "../airbyte-config/init/src/main/resources/seed/source_specs.yaml"
DESTINATION_SPECS = "../airbyte-config/init/src/main/resources/seed/destination_specs.yaml"

Expand All @@ -25,7 +26,7 @@ def get_all_specs_params():


@pytest.mark.parametrize("spec_type, spec", get_all_specs_params())
def test_render_spec(spec_type, spec, octavia_project_directory, mocker):
def test_render_spec(spec_type, spec, octavia_tmp_project_directory, mocker):
renderer = ConnectorSpecificationRenderer(
resource_name=f"resource-{spec['dockerImage']}",
definition=mocker.Mock(
Expand All @@ -37,7 +38,7 @@ def test_render_spec(spec_type, spec, octavia_project_directory, mocker):
specification=mocker.Mock(connection_specification=spec["spec"]["connectionSpecification"]),
),
)
output_path = renderer.write_yaml(octavia_project_directory)
output_path = renderer.write_yaml(octavia_tmp_project_directory)
with open(output_path, "r") as f:
parsed_yaml = yaml.safe_load(f)
assert all(
Expand Down Expand Up @@ -67,7 +68,7 @@ def test_render_spec(spec_type, spec, octavia_project_directory, mocker):
],
)
def test_expected_output_connector_specification_renderer(
resource_name, spec_type, input_spec_path, expected_yaml_path, octavia_project_directory, mocker
resource_name, spec_type, input_spec_path, expected_yaml_path, octavia_tmp_project_directory, mocker
):
with open(os.path.join(EXPECTED_RENDERED_YAML_PATH, input_spec_path), "r") as f:
input_spec = yaml.safe_load(f)
Expand All @@ -82,12 +83,12 @@ def test_expected_output_connector_specification_renderer(
specification=mocker.Mock(connection_specification=input_spec["spec"]["connectionSpecification"]),
),
)
output_path = renderer.write_yaml(octavia_project_directory)
output_path = renderer.write_yaml(octavia_tmp_project_directory)
expect_output_path = os.path.join(EXPECTED_RENDERED_YAML_PATH, expected_yaml_path)
assert filecmp.cmp(output_path, expect_output_path)


def test_expected_output_connection_renderer(octavia_project_directory, mocker):
def test_expected_output_connection_renderer(octavia_tmp_project_directory, mocker):
mock_source = mocker.Mock(
resource_id="my_source_id",
catalog={
Expand Down Expand Up @@ -150,6 +151,6 @@ def test_expected_output_connection_renderer(octavia_project_directory, mocker):
mock_destination = mocker.Mock(resource_id="my_destination_id")

renderer = ConnectionRenderer("my_new_connection", mock_source, mock_destination)
output_path = renderer.write_yaml(octavia_project_directory)
output_path = renderer.write_yaml(octavia_tmp_project_directory)
expect_output_path = os.path.join(EXPECTED_RENDERED_YAML_PATH, "connection/expected.yaml")
assert filecmp.cmp(output_path, expect_output_path)
30 changes: 30 additions & 0 deletions octavia-cli/integration_tests/test_list/test_listings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#


import pytest
from octavia_cli.list.listings import Connections, DestinationConnectorsDefinitions, Destinations, SourceConnectorsDefinitions, Sources

pytestmark = pytest.mark.integration


@pytest.mark.parametrize("ConnectorsDefinitionListing", [SourceConnectorsDefinitions, DestinationConnectorsDefinitions])
def test_list_connectors(api_client, ConnectorsDefinitionListing):
connector_definitions = ConnectorsDefinitionListing(api_client)
listing = connector_definitions.get_listing()
assert len(listing) > 0
assert len(listing[0]) == len(ConnectorsDefinitionListing.fields_to_display)
assert str(listing)


@pytest.mark.parametrize("WorkspaceListing", [Sources, Destinations, Connections])
def test_list_workspace_resource(api_client, source, destination, connection, workspace_id, WorkspaceListing):
assert source.was_created
assert destination.was_created
assert connection.was_created
connector_definitions = WorkspaceListing(api_client, workspace_id)
listing = connector_definitions.get_listing()
assert len(listing) >= 1
assert len(listing[0]) == len(WorkspaceListing.fields_to_display)
assert str(listing)
3 changes: 3 additions & 0 deletions octavia-cli/octavia_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
Loading

0 comments on commit 9f21fae

Please sign in to comment.