Skip to content

Commit

Permalink
test octavia command group
Browse files Browse the repository at this point in the history
  • Loading branch information
alafanechere committed Jan 6, 2022
1 parent c15835f commit 2afe6c2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ repos:
rev: v0.910-1
hooks:
- id: mypy
exclude: octavia-cli/airbyte_api_client/
exclude: |
(?x)^.*(
octavia-cli/airbyte_api_client/|
octavia-cli/unit_tests/|
).?$
- repo: local
hooks:
- id: spec-linter
Expand Down
26 changes: 23 additions & 3 deletions octavia-cli/unit_tests/test_entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
from unittest import mock

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


def test_octavia():
@click.command()
@click.pass_context
def dumb(ctx):
pass


@mock.patch("octavia_cli.entrypoint.workspace_api")
@mock.patch("octavia_cli.entrypoint.airbyte_api_client")
def test_octavia(mock_airbyte_api_client: mock.Mock, mock_workspace_api: mock.Mock):
context_object = {}
mock_api_instance = mock_workspace_api.WorkspaceApi.return_value
mock_api_instance.list_workspaces.return_value = mock.MagicMock(workspaces=[mock.MagicMock(workspace_id="expected_workspace_id")])

entrypoint.octavia.add_command(dumb)
runner = CliRunner()
result = runner.invoke(entrypoint.octavia)
result = runner.invoke(entrypoint.octavia, ["--airbyte-url", "test-airbyte-url", "dumb"], obj=context_object)
mock_airbyte_api_client.Configuration.assert_called_with(host="test-airbyte-url/api")
mock_airbyte_api_client.ApiClient.assert_called_with(mock_airbyte_api_client.Configuration.return_value)
mock_workspace_api.WorkspaceApi.assert_called_with(mock_airbyte_api_client.ApiClient.return_value)
mock_api_instance.list_workspaces.assert_called_once()
assert context_object["API_CLIENT"] == mock_airbyte_api_client.ApiClient.return_value
assert context_object["WORKSPACE_ID"] == "expected_workspace_id"
assert result.exit_code == 0
assert result.output.startswith("Usage: octavia [OPTIONS] COMMAND [ARGS]...")


@pytest.mark.parametrize(
Expand Down

0 comments on commit 2afe6c2

Please sign in to comment.