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

CLI tests ssues/431 #455

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
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
70 changes: 70 additions & 0 deletions .history/receptorctl/tests/test_cli_20211122111952.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from receptorctl import cli as commands

# The goal is to write tests following the click documentation:
# https://click.palletsprojects.com/en/8.0.x/testing/

import pytest, json


@pytest.mark.usefixtures("receptor_mesh_mesh1")
class TestCommands:
def test_cmd_status(self, invoke_as_json):
result, json_output = invoke_as_json(commands.status, [])
assert result.exit_code == 0
assert set(
[
"Advertisements",
"Connections",
"KnownConnectionCosts",
"NodeID",
"RoutingTable",
"SystemCPUCount",
"SystemMemoryMiB",
"Version",
]
) == set(
json_output.keys()
), "The command returned unexpected keys from json output"

def test_cmd_ping(self, invoke):
result = invoke(commands.ping, ["node2"])
assert result.exit_code == 0
assert "Reply from node2 in" in result.output

@pytest.mark.skip(
reason="skip code is 0 bug related here https://github.com/ansible/receptor/issues/431"
)
def test_cmd_work_missing_subcommand(self, invoke):
result = invoke(commands.work, [])
assert result.exit_code != 0
assert "Usage: cli work [OPTIONS] COMMAND [ARGS]..." in result.output

@pytest.mark.skip(
reason="skip code is 0 bug related here https://github.com/ansible/receptor/issues/431"
)
@pytest.mark.parametrize(
"command, error_message",
[
("cancel", "No unit IDs supplied: Not doing anything"),
("release", "No unit IDs supplied: Not doing anything"),
("results", "Usage: cli work results [OPTIONS] UNIT_ID"),
("submit", "Usage: cli work submit [OPTIONS] WORKTYPE [CMDPARAMS]"),
],
)
def test_cmd_work_missing_param(self, invoke, command, error_message):
result = invoke(commands.work, [command])
assert result.exit_code != 0
assert error_message in result.stdout

def test_cmd_work_cancel_successfully(self, invoke):
# Require fixture with a node running work
pass

def test_cmd_work_list_empty_work_unit(self, invoke):
result = invoke(commands.work, ["list"])
assert result.exit_code == 0
assert json.loads(result.output) == {}

def test_cmd_work_list_successfully(self, invoke):
# Require fixture with a node running work
pass
71 changes: 71 additions & 0 deletions .history/receptorctl/tests/test_cli_20211122112215.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from receptorctl import cli as commands

# The goal is to write tests following the click documentation:
# https://click.palletsprojects.com/en/8.0.x/testing/

import pytest
import json


@pytest.mark.usefixtures("receptor_mesh_mesh1")
class TestCommands:
def test_cmd_status(self, invoke_as_json):
result, json_output = invoke_as_json(commands.status, [])
assert result.exit_code == 0
assert set(
[
"Advertisements",
"Connections",
"KnownConnectionCosts",
"NodeID",
"RoutingTable",
"SystemCPUCount",
"SystemMemoryMiB",
"Version",
]
) == set(
json_output.keys()
), "The command returned unexpected keys from json output"

def test_cmd_ping(self, invoke):
result = invoke(commands.ping, ["node2"])
assert result.exit_code == 0
assert "Reply from node2 in" in result.output

@pytest.mark.skip(
reason="skip code is 0 bug related here https://github.com/ansible/receptor/issues/431"
)
def test_cmd_work_missing_subcommand(self, invoke):
result = invoke(commands.work, [])
assert result.exit_code != 0
assert "Usage: cli work [OPTIONS] COMMAND [ARGS]..." in result.output

@pytest.mark.skip(
reason="skip code is 0 bug related here https://github.com/ansible/receptor/issues/431"
)
@pytest.mark.parametrize(
"command, error_message",
[
("cancel", "No unit IDs supplied: Not doing anything"),
("release", "No unit IDs supplied: Not doing anything"),
("results", "Usage: cli work results [OPTIONS] UNIT_ID"),
("submit", "Usage: cli work submit [OPTIONS] WORKTYPE [CMDPARAMS]"),
],
)
def test_cmd_work_missing_param(self, invoke, command, error_message):
result = invoke(commands.work, [command])
assert result.exit_code != 0
assert error_message in result.stdout

def test_cmd_work_cancel_successfully(self, invoke):
# Require fixture with a node running work
pass

def test_cmd_work_list_empty_work_unit(self, invoke):
result = invoke(commands.work, ["list"])
assert result.exit_code == 0
assert json.loads(result.output) == {}

def test_cmd_work_list_successfully(self, invoke):
# Require fixture with a node running work
pass
44 changes: 44 additions & 0 deletions receptorctl/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# https://click.palletsprojects.com/en/8.0.x/testing/

import pytest
import json


@pytest.mark.usefixtures("receptor_mesh_mesh1")
Expand All @@ -25,3 +26,46 @@ def test_cmd_status(self, invoke_as_json):
) == set(
json_output.keys()
), "The command returned unexpected keys from json output"

def test_cmd_ping(self, invoke):
result = invoke(commands.ping, ["node2"])
assert result.exit_code == 0
assert "Reply from node2 in" in result.output

@pytest.mark.skip(
reason="skip code is 0 bug related here https://github.com/ansible/receptor/issues/431"
)
def test_cmd_work_missing_subcommand(self, invoke):
result = invoke(commands.work, [])
assert result.exit_code != 0
assert "Usage: cli work [OPTIONS] COMMAND [ARGS]..." in result.output

@pytest.mark.skip(
reason="skip code is 0 bug related here https://github.com/ansible/receptor/issues/431"
)
@pytest.mark.parametrize(
"command, error_message",
[
("cancel", "No unit IDs supplied: Not doing anything"),
("release", "No unit IDs supplied: Not doing anything"),
("results", "Usage: cli work results [OPTIONS] UNIT_ID"),
("submit", "Usage: cli work submit [OPTIONS] WORKTYPE [CMDPARAMS]"),
],
)
def test_cmd_work_missing_param(self, invoke, command, error_message):
result = invoke(commands.work, [command])
assert result.exit_code != 0
assert error_message in result.stdout

def test_cmd_work_cancel_successfully(self, invoke):
# Require fixture with a node running work
pass

def test_cmd_work_list_empty_work_unit(self, invoke):
result = invoke(commands.work, ["list"])
assert result.exit_code == 0
assert json.loads(result.output) == {}

def test_cmd_work_list_successfully(self, invoke):
# Require fixture with a node running work
pass