Skip to content

Commit

Permalink
Add tests and fix docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
robertopreste committed Jun 26, 2019
1 parent 3f245b0 commit 4552418
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 23 deletions.
4 changes: 1 addition & 3 deletions quickci/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
@click.group()
@click.version_option()
def main():
"""
Have a quick look at the status of CI projects from the command line.
"""
"""Have a quick look at the status of CI projects from the command line."""
pass


Expand Down
7 changes: 4 additions & 3 deletions quickci/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
@click.group()
@click.pass_context
def config(ctx):
"""
Create or update the configuration file.
"""
"""Create or update the configuration file."""
ctx.obj = Config()
pass


@config.command(short_help="Show the config file.")
@click.pass_obj
def show(obj):
"""Display the content of the configuration file."""
click.echo(obj.show())
return 0


@config.command(short_help="Create a new config file.")
@click.pass_obj
def create(obj):
"""Create a new configuration file or overwrite an existing one."""
if obj.check_file():
click.echo(f"Configuration file already present in {obj.config_path}")
if not click.confirm("Do you really want to overwrite it?",
Expand All @@ -44,6 +44,7 @@ def create(obj):
@click.argument("token", type=str)
@click.pass_obj
def update(obj, service, token):
"""Update a specific service token in the configuration file."""
obj.update(service, token)
obj.save()
click.echo(f"Updated token for {service}.")
Expand Down
20 changes: 5 additions & 15 deletions quickci/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
@click.group(invoke_without_command=True)
@click.pass_context
def status(ctx):
"""
Return the status of the master branch of each project in each CI.
"""
"""Return the status of the master branch of each project in each CI."""
ctx.obj = Config().parse()
if ctx.invoked_subcommand is None:
ctx.invoke(travis)
Expand All @@ -24,9 +22,7 @@ def status(ctx):
@click.option("--token", "-t", help="Travis CI auth token", default=None)
@click.pass_obj
def travis(obj, token):
"""
Return the status of the master branch of each project in Travis CI.
"""
"""Return the status of the master branch of each project in Travis CI."""
if token:
res = TravisCI(token=token)
else:
Expand All @@ -41,9 +37,7 @@ def travis(obj, token):
@click.option("--token", "-t", help="CircleCI auth token", default=None)
@click.pass_obj
def circle(obj, token):
"""
Return the status of the master branch of each project in CircleCI.
"""
"""Return the status of the master branch of each project in CircleCI."""
if token:
res = CircleCI(token=token)
else:
Expand All @@ -58,9 +52,7 @@ def circle(obj, token):
@click.option("--token", "-t", help="AppVeyor auth token", default=None)
@click.pass_obj
def appveyor(obj, token):
"""
Return the status of the master branch of each project in AppVeyor.
"""
"""Return the status of the master branch of each project in AppVeyor."""
if token:
res = AppVeyor(token=token)
else:
Expand All @@ -75,9 +67,7 @@ def appveyor(obj, token):
@click.option("--token", "-t", help="Buddy auth token", default=None)
@click.pass_obj
def buddy(obj, token):
"""
Return the status of the master branch of each project in Buddy.
"""
"""Return the status of the master branch of each project in Buddy."""
if token:
res = Buddy(token=token)
else:
Expand Down
90 changes: 88 additions & 2 deletions tests/test_quickci.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Created by Roberto Preste
import pytest
from click.testing import CliRunner
from quickci import quickci
from quickci import cli


Expand All @@ -12,11 +11,98 @@ def test_cli():
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert "Have a quick look at the status of CI" in result.output
assert "Show this message and exit." in result.output


def test_cli_help():
"""Test the CLI help."""
runner = CliRunner()
result = runner.invoke(cli.main, ['--help'])
result = runner.invoke(cli.main, ["--help"])
assert result.exit_code == 0
assert "Have a quick look at the status of CI" in result.output
assert "Show this message and exit." in result.output


def test_cli_config():
"""Test the config command group."""
runner = CliRunner()
result = runner.invoke(cli.main, ["config"])
assert result.exit_code == 0
assert "config [OPTIONS] COMMAND [ARGS]" in result.output
assert "Show this message and exit." in result.output


def test_cli_config_help():
"""Test the config command group help."""
runner = CliRunner()
result = runner.invoke(cli.main, ["config", "--help"])
assert result.exit_code == 0
assert "config [OPTIONS] COMMAND [ARGS]" in result.output
assert "Show this message and exit." in result.output


def test_cli_config_show():
"""Test the config show command."""
runner = CliRunner()
result = runner.invoke(cli.main, ["config", "show"])
assert result.exit_code == 0
assert "APPVEYOR_TOKEN" in result.output
assert "BUDDY_TOKEN" in result.output
assert "CIRCLECI_TOKEN" in result.output
assert "TRAVISCI_TOKEN" in result.output


def test_cli_status():
"""Test the status command group."""
runner = CliRunner()
result = runner.invoke(cli.main, ["status"])
assert result.exit_code == 0
assert "Travis CI" in result.output
assert "CircleCI" in result.output
assert "AppVeyor" in result.output
assert "Buddy" in result.output


def test_cli_status_help():
"""Test the status command group help."""
runner = CliRunner()
result = runner.invoke(cli.main, ["status", "--help"])
assert result.exit_code == 0
assert "appveyor" in result.output
assert "buddy" in result.output
assert "circle" in result.output
assert "travis" in result.output
assert "Show this message and exit." in result.output


def test_cli_status_travis():
"""Test the status travis command."""
runner = CliRunner()
result = runner.invoke(cli.main, ["status", "travis"])
assert result.exit_code == 0
assert "Travis CI" in result.output


def test_cli_status_circle():
"""Test the status circle command."""
runner = CliRunner()
result = runner.invoke(cli.main, ["status", "circle"])
assert result.exit_code == 0
assert "CircleCI" in result.output


def test_cli_status_appveyor():
"""Test the status appveyor command."""
runner = CliRunner()
result = runner.invoke(cli.main, ["status", "appveyor"])
assert result.exit_code == 0
assert "AppVeyor" in result.output


def test_cli_status_buddy():
"""Test the status buddy command."""
runner = CliRunner()
result = runner.invoke(cli.main, ["status", "buddy"])
assert result.exit_code == 0
assert "Buddy" in result.output

0 comments on commit 4552418

Please sign in to comment.