Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

octavia-cli: fix workspace not having anonymous_data_collection property #13869

Merged
merged 8 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions octavia-cli/integration_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

import os

import pytest
Expand Down
18 changes: 13 additions & 5 deletions octavia-cli/integration_tests/test_api_http_headers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

import logging

import pytest
from click.testing import CliRunner
from octavia_cli import api_http_headers, entrypoint

logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from vcrpy
vcr_log = logging.getLogger("vcr")
vcr_log.setLevel(logging.WARN)

AIRBYTE_URL = "http://localhost:8000"


@pytest.fixture(scope="module")
def vcr_config():
return {
"record_mode": "once",
"record_mode": "rewrite",
"match_on": ["method", "scheme", "host", "port", "path", "query", "headers"],
}

Expand All @@ -33,8 +40,8 @@ def option_based_headers():
return ["Another-Custom-Header", "Bar"], [api_http_headers.ApiHttpHeader("Another-Custom-Header", "Bar")]


@pytest.mark.vcr()
def test_api_http_headers(vcr_cassette, file_based_headers, option_based_headers):
@pytest.mark.vcr
def test_api_http_headers(vcr, file_based_headers, option_based_headers):
raw_option_based_headers, expected_option_based_headers = option_based_headers
custom_api_http_headers_yaml_file_path, expected_file_based_headers = file_based_headers
expected_headers = expected_option_based_headers + expected_file_based_headers
Expand All @@ -44,8 +51,9 @@ def test_api_http_headers(vcr_cassette, file_based_headers, option_based_headers
+ raw_option_based_headers
+ ["list", "connectors", "sources"]
)

result = runner.invoke(entrypoint.octavia, command_options, obj={})
assert result.exit_code == 0
for request in vcr_cassette.requests:
for request in vcr.requests:
for expected_header in expected_headers:
assert request.headers[expected_header.name] == expected_header.value
assert result.exit_code == 0
4 changes: 2 additions & 2 deletions octavia-cli/octavia_cli/api_http_headers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

from dataclasses import dataclass
from typing import List, Optional, Tuple

Expand Down Expand Up @@ -81,9 +82,8 @@ def merge_api_headers(
"""
if option_based_api_http_headers and api_http_headers_file_path:
click.echo(
"ℹ️ - You passed API HTTP headers in a file and in options at the same time. Option based headers will override file based headers."
"ℹ️ - You passed API HTTP headers in a file and in options at the same time. Option based headers will override file based headers."
)

option_based_headers = (
deserialize_option_based_headers(option_based_api_http_headers) if option_based_api_http_headers is not None else []
)
Expand Down
3 changes: 2 additions & 1 deletion octavia-cli/octavia_cli/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

from typing import List, Optional, Tuple

import airbyte_api_client
Expand Down Expand Up @@ -138,7 +139,7 @@ def get_workspace_id(api_client, user_defined_workspace_id):
def get_anonymous_data_collection(api_client, workspace_id):
api_instance = workspace_api.WorkspaceApi(api_client)
api_response = api_instance.get_workspace(WorkspaceIdRequestBody(workspace_id), _check_return_type=False)
return api_response.anonymous_data_collection
return api_response.get("anonymous_data_collection", True)


def add_commands_to_octavia():
Expand Down
1 change: 1 addition & 0 deletions octavia-cli/octavia_cli/init/commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

import importlib.resources as pkg_resources
import os
from pathlib import Path
Expand Down
4 changes: 2 additions & 2 deletions octavia-cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"Tracker": "https://github.com/airbytehq/airbyte/issues",
},
packages=find_packages(exclude=("unit_tests", "integration_tests", "docs")),
package_data={"octavia_cli.generate": ["templates/*.j2"], "octavia_cli.init": ["example_api_http_headers.yaml"]},
package_data={"octavia_cli.generate": ["templates/*.j2"], "octavia_cli.init.example_files": ["example_api_http_headers.yaml"]},
install_requires=[
"click~=8.0.3",
f"airbyte_api_client @ file://{os.getcwd()}/build/airbyte_api_client",
Expand All @@ -52,7 +52,7 @@
],
python_requires=">=3.9.11",
extras_require={
"tests": ["MyPy~=0.812", "pytest~=6.2.5", "pytest-cov", "pytest-mock", "pytest-vcr", "requests-mock", "pre-commit"],
"tests": ["MyPy~=0.812", "pytest~=6.2.5", "pytest-cov", "pytest-mock", "pytest-recording", "requests-mock", "pre-commit"],
"sphinx-docs": [
"Sphinx~=4.2",
"sphinx-rtd-theme~=1.0",
Expand Down
2 changes: 1 addition & 1 deletion octavia-cli/unit_tests/test_api_http_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_merge_api_headers(tmp_path, mocker, yaml_document, option_based_raw_hea
assert api_http_headers.merge_api_headers(option_based_raw_headers, yaml_file_path) == expected_merged_headers
if option_based_raw_headers and yaml_file_path:
api_http_headers.click.echo.assert_called_with(
"ℹ️ - You passed API HTTP headers in a file and in options at the same time. Option based headers will override file based headers."
"ℹ️ - You passed API HTTP headers in a file and in options at the same time. Option based headers will override file based headers."
)


Expand Down
3 changes: 2 additions & 1 deletion octavia-cli/unit_tests/test_entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

from typing import List, Optional

import click
Expand Down Expand Up @@ -189,7 +190,7 @@ def test_get_anonymous_data_collection(mocker, mock_api_client):
mock_api_instance = entrypoint.workspace_api.WorkspaceApi.return_value
assert (
entrypoint.get_anonymous_data_collection(mock_api_client, "my_workspace_id")
== mock_api_instance.get_workspace.return_value.anonymous_data_collection
== mock_api_instance.get_workspace.return_value.get.return_value
)
entrypoint.workspace_api.WorkspaceApi.assert_called_with(mock_api_client)
mock_api_instance.get_workspace.assert_called_with(WorkspaceIdRequestBody("my_workspace_id"), _check_return_type=False)
Expand Down
1 change: 1 addition & 0 deletions octavia-cli/unit_tests/test_init/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

from unittest.mock import mock_open, patch

import pytest
Expand Down