Skip to content

Commit 9f21fae

Browse files
authored
🐛 octavia-cli: use list endpoint instead of list_latest (#11505)
1 parent a659b8c commit 9f21fae

File tree

13 files changed

+176
-132
lines changed

13 files changed

+176
-132
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#
2+
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
import os
6+
7+
import pytest
8+
import yaml
9+
from octavia_cli.apply.resources import Connection, Destination, Source
10+
from octavia_cli.entrypoint import get_api_client, get_workspace_id
11+
from octavia_cli.init.commands import DIRECTORIES_TO_CREATE as OCTAVIA_PROJECT_DIRECTORIES
12+
13+
14+
def silent_remove(path):
15+
try:
16+
os.remove(path)
17+
return True
18+
except FileNotFoundError:
19+
return False
20+
21+
22+
@pytest.fixture
23+
def octavia_tmp_project_directory(tmpdir):
24+
for directory in OCTAVIA_PROJECT_DIRECTORIES:
25+
tmpdir.mkdir(directory)
26+
return tmpdir
27+
28+
29+
@pytest.fixture(scope="session")
30+
def octavia_test_project_directory():
31+
return f"{os.path.dirname(__file__)}/configurations"
32+
33+
34+
@pytest.fixture(scope="session")
35+
def api_client():
36+
return get_api_client("http://localhost:8000")
37+
38+
39+
@pytest.fixture(scope="session")
40+
def workspace_id(api_client):
41+
return get_workspace_id(api_client, None)
42+
43+
44+
@pytest.fixture(scope="session")
45+
def source_configuration_and_path(octavia_test_project_directory):
46+
path = f"{octavia_test_project_directory}/sources/poke/configuration.yaml"
47+
with open(path, "r") as f:
48+
local_configuration = yaml.safe_load(f)
49+
return local_configuration, path
50+
51+
52+
@pytest.fixture(scope="session")
53+
def source_state_path(octavia_test_project_directory):
54+
state_path = f"{octavia_test_project_directory}/sources/poke/state.yaml"
55+
silent_remove(state_path)
56+
yield state_path
57+
silent_remove(state_path)
58+
59+
60+
@pytest.fixture(scope="session")
61+
def source(api_client, workspace_id, source_configuration_and_path, source_state_path):
62+
configuration, path = source_configuration_and_path
63+
source = Source(api_client, workspace_id, configuration, path)
64+
yield source
65+
source.api_instance.delete_source(source.resource_id_request_body)
66+
67+
68+
@pytest.fixture(scope="session")
69+
def destination_configuration_and_path(octavia_test_project_directory):
70+
path = f"{octavia_test_project_directory}/destinations/postgres/configuration.yaml"
71+
with open(path, "r") as f:
72+
local_configuration = yaml.safe_load(f)
73+
return local_configuration, path
74+
75+
76+
@pytest.fixture(scope="session")
77+
def destination_state_path(octavia_test_project_directory):
78+
state_path = f"{octavia_test_project_directory}/destinations/postgres/state.yaml"
79+
silent_remove(state_path)
80+
yield state_path
81+
silent_remove(state_path)
82+
83+
84+
@pytest.fixture(scope="session")
85+
def destination(api_client, workspace_id, destination_configuration_and_path, destination_state_path):
86+
configuration, path = destination_configuration_and_path
87+
destination = Destination(api_client, workspace_id, configuration, path)
88+
yield destination
89+
destination.api_instance.delete_destination(destination.resource_id_request_body)
90+
91+
92+
@pytest.fixture(scope="session")
93+
def connection_configuration_and_path(octavia_test_project_directory):
94+
path = f"{octavia_test_project_directory}/connections/poke_to_pg/configuration.yaml"
95+
with open(path, "r") as f:
96+
local_configuration = yaml.safe_load(f)
97+
return local_configuration, path
98+
99+
100+
@pytest.fixture(scope="session")
101+
def connection_state_path(octavia_test_project_directory):
102+
state_path = f"{octavia_test_project_directory}/connections/poke_to_pg/state.yaml"
103+
silent_remove(state_path)
104+
yield state_path
105+
silent_remove(state_path)
106+
107+
108+
def updated_connection_configuration_and_path(octavia_test_project_directory, source, destination):
109+
path = f"{octavia_test_project_directory}/connections/poke_to_pg/configuration.yaml"
110+
edited_path = f"{octavia_test_project_directory}/connections/poke_to_pg/updated_configuration.yaml"
111+
with open(path, "r") as dumb_local_configuration_file:
112+
local_configuration = yaml.safe_load(dumb_local_configuration_file)
113+
local_configuration["source_id"] = source.resource_id
114+
local_configuration["destination_id"] = destination.resource_id
115+
local_configuration["configuration"]["sourceId"] = source.resource_id
116+
local_configuration["configuration"]["destinationId"] = destination.resource_id
117+
with open(edited_path, "w") as updated_configuration_file:
118+
yaml.dump(local_configuration, updated_configuration_file)
119+
return local_configuration, edited_path
120+
121+
122+
@pytest.fixture(scope="session")
123+
def connection(api_client, workspace_id, octavia_test_project_directory, source, destination):
124+
configuration, configuration_path = updated_connection_configuration_and_path(octavia_test_project_directory, source, destination)
125+
connection = Connection(api_client, workspace_id, configuration, configuration_path)
126+
yield connection
127+
connection.api_instance.delete_connection(connection.resource_id_request_body)
128+
silent_remove(configuration_path)

octavia-cli/integration_tests/test_apply/test_resources.py

Lines changed: 1 addition & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,11 @@
22
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
33
#
44

5-
import os
6-
75
import pytest
8-
import yaml
9-
from octavia_cli.apply.resources import Connection, Destination, Source
10-
from octavia_cli.entrypoint import get_api_client, get_workspace_id
116

127
pytestmark = pytest.mark.integration
138

149

15-
@pytest.fixture(scope="module")
16-
def api_client():
17-
return get_api_client("http://localhost:8000")
18-
19-
20-
@pytest.fixture(scope="module")
21-
def workspace_id(api_client):
22-
return get_workspace_id(api_client, None)
23-
24-
25-
@pytest.fixture(scope="module")
26-
def source_configuration_and_path():
27-
path = f"{os.path.dirname(__file__)}/configurations/sources/poke/configuration.yaml"
28-
with open(path, "r") as f:
29-
local_configuration = yaml.safe_load(f)
30-
return local_configuration, path
31-
32-
33-
def silent_remove(path):
34-
try:
35-
os.remove(path)
36-
return True
37-
except FileNotFoundError:
38-
return False
39-
40-
41-
@pytest.fixture(scope="module")
42-
def source_state_path():
43-
state_path = f"{os.path.dirname(__file__)}/configurations/sources/poke/state.yaml"
44-
silent_remove(state_path)
45-
yield state_path
46-
silent_remove(state_path)
47-
48-
49-
@pytest.fixture(scope="module")
50-
def source(api_client, workspace_id, source_configuration_and_path, source_state_path):
51-
configuration, path = source_configuration_and_path
52-
source = Source(api_client, workspace_id, configuration, path)
53-
yield source
54-
source.api_instance.delete_source(source.resource_id_request_body)
55-
56-
5710
def test_source_lifecycle(source):
5811
assert not source.was_created
5912
source.create()
@@ -67,30 +20,6 @@ def test_source_lifecycle(source):
6720
assert source.catalog["streams"][0]["config"]["aliasName"] == "pokemon"
6821

6922

70-
@pytest.fixture(scope="module")
71-
def destination_configuration_and_path():
72-
path = f"{os.path.dirname(__file__)}/configurations/destinations/postgres/configuration.yaml"
73-
with open(path, "r") as f:
74-
local_configuration = yaml.safe_load(f)
75-
return local_configuration, path
76-
77-
78-
@pytest.fixture(scope="module")
79-
def destination_state_path():
80-
state_path = f"{os.path.dirname(__file__)}/configurations/destinations/postgres/state.yaml"
81-
silent_remove(state_path)
82-
yield state_path
83-
silent_remove(state_path)
84-
85-
86-
@pytest.fixture(scope="module")
87-
def destination(api_client, workspace_id, destination_configuration_and_path, destination_state_path):
88-
configuration, path = destination_configuration_and_path
89-
destination = Destination(api_client, workspace_id, configuration, path)
90-
yield destination
91-
destination.api_instance.delete_destination(destination.resource_id_request_body)
92-
93-
9423
def test_destination_lifecycle(destination):
9524
assert not destination.was_created
9625
destination.create()
@@ -103,41 +32,9 @@ def test_destination_lifecycle(destination):
10332
assert not destination.get_diff_with_remote_resource()
10433

10534

106-
@pytest.fixture(scope="module")
107-
def connection_configuration_and_path():
108-
path = f"{os.path.dirname(__file__)}/configurations/connections/poke_to_pg/configuration.yaml"
109-
with open(path, "r") as f:
110-
local_configuration = yaml.safe_load(f)
111-
return local_configuration, path
112-
113-
114-
@pytest.fixture(scope="module")
115-
def connection_state_path():
116-
state_path = f"{os.path.dirname(__file__)}/configurations/connections/poke_to_pg/state.yaml"
117-
silent_remove(state_path)
118-
yield state_path
119-
silent_remove(state_path)
120-
121-
122-
def updated_connection_configuration_and_path(source, destination):
123-
path = f"{os.path.dirname(__file__)}/configurations/connections/poke_to_pg/configuration.yaml"
124-
edited_path = f"{os.path.dirname(__file__)}/configurations/connections/poke_to_pg/updated_configuration.yaml"
125-
with open(path, "r") as dumb_local_configuration_file:
126-
local_configuration = yaml.safe_load(dumb_local_configuration_file)
127-
local_configuration["source_id"] = source.resource_id
128-
local_configuration["destination_id"] = destination.resource_id
129-
local_configuration["configuration"]["sourceId"] = source.resource_id
130-
local_configuration["configuration"]["destinationId"] = destination.resource_id
131-
with open(edited_path, "w") as updated_configuration_file:
132-
yaml.dump(local_configuration, updated_configuration_file)
133-
return local_configuration, edited_path
134-
135-
136-
def test_connection_lifecycle(source, destination, api_client, workspace_id, connection_state_path):
35+
def test_connection_lifecycle(source, destination, connection):
13736
assert source.was_created
13837
assert destination.was_created
139-
configuration, configuration_path = updated_connection_configuration_and_path(source, destination)
140-
connection = Connection(api_client, workspace_id, configuration, configuration_path)
14138
assert not connection.was_created
14239
connection.create()
14340
connection.state = connection._get_state_from_file()
@@ -147,5 +44,3 @@ def test_connection_lifecycle(source, destination, api_client, workspace_id, con
14744
assert 'changed from "active" to "inactive"' in connection.get_diff_with_remote_resource()
14845
connection.update()
14946
assert not connection.get_diff_with_remote_resource()
150-
connection.api_instance.delete_connection(connection.resource_id_request_body)
151-
silent_remove(configuration_path)

octavia-cli/integration_tests/test_generate/conftest.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

octavia-cli/integration_tests/test_generate/test_renderers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from octavia_cli.generate.renderers import ConnectionRenderer, ConnectorSpecificationRenderer
1111

1212
pytestmark = pytest.mark.integration
13+
1314
SOURCE_SPECS = "../airbyte-config/init/src/main/resources/seed/source_specs.yaml"
1415
DESTINATION_SPECS = "../airbyte-config/init/src/main/resources/seed/destination_specs.yaml"
1516

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

2627

2728
@pytest.mark.parametrize("spec_type, spec", get_all_specs_params())
28-
def test_render_spec(spec_type, spec, octavia_project_directory, mocker):
29+
def test_render_spec(spec_type, spec, octavia_tmp_project_directory, mocker):
2930
renderer = ConnectorSpecificationRenderer(
3031
resource_name=f"resource-{spec['dockerImage']}",
3132
definition=mocker.Mock(
@@ -37,7 +38,7 @@ def test_render_spec(spec_type, spec, octavia_project_directory, mocker):
3738
specification=mocker.Mock(connection_specification=spec["spec"]["connectionSpecification"]),
3839
),
3940
)
40-
output_path = renderer.write_yaml(octavia_project_directory)
41+
output_path = renderer.write_yaml(octavia_tmp_project_directory)
4142
with open(output_path, "r") as f:
4243
parsed_yaml = yaml.safe_load(f)
4344
assert all(
@@ -67,7 +68,7 @@ def test_render_spec(spec_type, spec, octavia_project_directory, mocker):
6768
],
6869
)
6970
def test_expected_output_connector_specification_renderer(
70-
resource_name, spec_type, input_spec_path, expected_yaml_path, octavia_project_directory, mocker
71+
resource_name, spec_type, input_spec_path, expected_yaml_path, octavia_tmp_project_directory, mocker
7172
):
7273
with open(os.path.join(EXPECTED_RENDERED_YAML_PATH, input_spec_path), "r") as f:
7374
input_spec = yaml.safe_load(f)
@@ -82,12 +83,12 @@ def test_expected_output_connector_specification_renderer(
8283
specification=mocker.Mock(connection_specification=input_spec["spec"]["connectionSpecification"]),
8384
),
8485
)
85-
output_path = renderer.write_yaml(octavia_project_directory)
86+
output_path = renderer.write_yaml(octavia_tmp_project_directory)
8687
expect_output_path = os.path.join(EXPECTED_RENDERED_YAML_PATH, expected_yaml_path)
8788
assert filecmp.cmp(output_path, expect_output_path)
8889

8990

90-
def test_expected_output_connection_renderer(octavia_project_directory, mocker):
91+
def test_expected_output_connection_renderer(octavia_tmp_project_directory, mocker):
9192
mock_source = mocker.Mock(
9293
resource_id="my_source_id",
9394
catalog={
@@ -150,6 +151,6 @@ def test_expected_output_connection_renderer(octavia_project_directory, mocker):
150151
mock_destination = mocker.Mock(resource_id="my_destination_id")
151152

152153
renderer = ConnectionRenderer("my_new_connection", mock_source, mock_destination)
153-
output_path = renderer.write_yaml(octavia_project_directory)
154+
output_path = renderer.write_yaml(octavia_tmp_project_directory)
154155
expect_output_path = os.path.join(EXPECTED_RENDERED_YAML_PATH, "connection/expected.yaml")
155156
assert filecmp.cmp(output_path, expect_output_path)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
6+
import pytest
7+
from octavia_cli.list.listings import Connections, DestinationConnectorsDefinitions, Destinations, SourceConnectorsDefinitions, Sources
8+
9+
pytestmark = pytest.mark.integration
10+
11+
12+
@pytest.mark.parametrize("ConnectorsDefinitionListing", [SourceConnectorsDefinitions, DestinationConnectorsDefinitions])
13+
def test_list_connectors(api_client, ConnectorsDefinitionListing):
14+
connector_definitions = ConnectorsDefinitionListing(api_client)
15+
listing = connector_definitions.get_listing()
16+
assert len(listing) > 0
17+
assert len(listing[0]) == len(ConnectorsDefinitionListing.fields_to_display)
18+
assert str(listing)
19+
20+
21+
@pytest.mark.parametrize("WorkspaceListing", [Sources, Destinations, Connections])
22+
def test_list_workspace_resource(api_client, source, destination, connection, workspace_id, WorkspaceListing):
23+
assert source.was_created
24+
assert destination.was_created
25+
assert connection.was_created
26+
connector_definitions = WorkspaceListing(api_client, workspace_id)
27+
listing = connector_definitions.get_listing()
28+
assert len(listing) >= 1
29+
assert len(listing[0]) == len(WorkspaceListing.fields_to_display)
30+
assert str(listing)

octavia-cli/octavia_cli/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
3+
#

0 commit comments

Comments
 (0)