-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
62 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Jim Halpert, Sales, Salesman, [email protected] | ||
Dwight Schrute, Sales, Manager, [email protected] | ||
Gabe Lewis, Directory, Manager, [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,47 @@ | ||
import argparse | ||
from importlib import metadata | ||
|
||
from dundie.core import load # noqa | ||
import rich_click as click | ||
from rich.console import Console | ||
from rich.table import Table | ||
|
||
from dundie import core | ||
|
||
click.rich_click.USE_RICH_MARKUP = True | ||
click.rich_click.USE_MARKDOWN = True | ||
click.rich_click.SHOW_ARGUMENTS = True | ||
click.rich_click.GRUOP_ARGUMENTS_OPTIONS = True | ||
click.rich_click.SHOW_METAVARS_COLUMN = False | ||
click.rich_click.APPEND_METAVARS_HELP = True | ||
|
||
|
||
@click.group() | ||
@click.version_option(metadata.version("dundie")) | ||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Dunder Mifflin Rewards CLI", | ||
epilog="Enjoy and use with cautious.", | ||
) | ||
parser.add_argument( | ||
"subcommand", | ||
type=str, | ||
help="The subcommand to run", | ||
choices=("load", "show", "send"), | ||
default="help", | ||
) | ||
parser.add_argument( | ||
"filepath", type=str, help="Filepath to load", default=None | ||
) | ||
args = parser.parse_args() | ||
|
||
print(*globals()[args.subcommand](args.filepath)) | ||
"""Dunder Mifflin Rewards System. | ||
This CLI application controls Dunder Mifflin Rewards. | ||
""" | ||
|
||
|
||
@main.command() | ||
@click.argument("filepath", type=click.Path(exists=True)) | ||
def load(filepath): | ||
"""Loads the file to the database. | ||
## Features | ||
- Validates data | ||
- Parses the file | ||
- Loads to database | ||
""" | ||
table = Table(title="Dunder Mifflin Associates") | ||
headers = ["name", "dept", "role", "e-mail"] | ||
for header in headers: | ||
table.add_column(header, style="italic cyan1") | ||
|
||
result = core.load(filepath) | ||
for person in result: | ||
table.add_row(*[field.strip() for field in person.split(",")]) | ||
|
||
console = Console() | ||
console.print(table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PEOPLE_FILE = "tests/assets/people.csv" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
from subprocess import CalledProcessError, check_output | ||
|
||
import pytest | ||
from click.testing import CliRunner | ||
|
||
from dundie.cli import load, main | ||
|
||
from .constants import PEOPLE_FILE | ||
|
||
cmd = CliRunner() | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.medium | ||
def test_load_positive_call_load_command(): | ||
"""Test command load""" | ||
out = ( | ||
check_output(["dundie", "load", "assets/people.csv"]) | ||
.decode("utf-8") | ||
.split("\n") | ||
) | ||
assert len(out) == 2 | ||
out = cmd.invoke(load, PEOPLE_FILE) | ||
assert "Dunder Mifflin Associates" in out.output | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.medium | ||
@pytest.mark.parametrize("wrong_command", ["loady", "carrega", "start"]) | ||
def test_load_negative_call_load_command_with_wrong_params(wrong_command): | ||
"""Test command load""" | ||
with pytest.raises(CalledProcessError) as error: | ||
check_output(["dundie", wrong_command, "assets/people.csv"]).decode( | ||
"utf-8" | ||
).split("\n") | ||
|
||
assert "status 2" in str(error.getrepr()) | ||
out = cmd.invoke(main, wrong_command, PEOPLE_FILE) | ||
assert out.exit_code != 0 | ||
assert f"No such command '{wrong_command}'" in out.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
click | ||
rich | ||
rich-click |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters