コード例 #1
0
def test_delete(db_non_empty):
    # GIVEN a non empty db
    a_card = cards.list_cards()[0]
    id = a_card.id
    count_before = cards.count()

    # WHEN we delete one item
    cards.delete_card(id)
    count_after = cards.count()

    # THEN the card is no longer in the db
    all_cards = cards.list_cards()
    assert a_card not in all_cards
    assert count_after == count_before - 1
コード例 #2
0
def test_list(db_empty):
    some_cards = [Card(summary="one"), Card(summary="two")]
    for c in some_cards:
        cards.add_card(c)

    all_cards = cards.list_cards()
    assert all_cards == some_cards
コード例 #3
0
def test_list_filter_by_priority(db_empty):
    some_cards = [
        Card(summary="one", priority=2),
        Card(summary="two"),
        Card(summary="three", priority=1),
    ]
    for c in some_cards:
        cards.add_card(c)

    one_and_above = cards.list_cards(filter={"priority": 1})
    two_and_above = cards.list_cards(filter={"priority": 2})
    one, two, three = some_cards
    assert three in one_and_above

    assert one in two_and_above
    assert three in two_and_above
    assert two not in two_and_above
コード例 #4
0
def test_update(db_non_empty):
    # GIVEN a card known to be in the db
    all_cards = cards.list_cards()
    a_card = all_cards[0]

    # WHEN we update() the card with new info
    cards.update_card(a_card.id, Card(owner="okken", done=True))

    # THEN we can retrieve the card with get() and
    # and it has all of our changes
    updated_card = cards.get_card(a_card.id)
    expected = Card(summary=a_card.summary, owner="okken", done=True)
    assert updated_card == expected
コード例 #5
0
ファイル: cli.py プロジェクト: kpinjari/cards
def list_cards(noowner, owner, priority, done, format):
    """
    List cards in db.
    """
    set_cards_db_path()
    filter = {
        'noowner': noowner,
        'owner': owner,
        'priority': priority,
        'done': done
    }
    the_cards = cards.list_cards(filter=filter)

    #  json is a special case
    if format == 'json':
        items = [c.to_dict() for c in the_cards]
        print(json.dumps({"cards": items}, sort_keys=True, indent=4))
        return

    # who's going to remember 'pipe' for markdown?
    if format == 'markdown':
        format = 'pipe'

    if format == 'packed':
        for t in the_cards:
            done = 'x' if t.done else 'o'
            owner = 'unassigned' if t.owner is None else t.owner
            line = f'{t.id} {owner} {t.priority} {done} {t.summary}'
            print(line)
        return

    # all formats except json/none use tabulate
    items = []
    for t in the_cards:
        done = ' x ' if t.done else ''
        owner = '' if t.owner is None else t.owner
        items.append((t.id, owner, t.priority, done, t.summary))

    print(
        tabulate(items,
                 headers=('ID', 'owner', 'priority', 'done', 'summary'),
                 tablefmt=format))
コード例 #6
0
def list_cards(
    noowner: bool = typer.Option(
        None,
        "-n",
        "--noowner",
        "--no-owner",
        help="list cards without owners",
    ),
    owner: str = typer.Option(None,
                              "-o",
                              "--owner",
                              help="filter on the cards owner"),
    priority: int = typer.Option(
        None,
        "-p",
        "--priority",
        help="fliter on this priority and above",
    ),
    done: bool = typer.Option(
        None,
        "-d",
        "--done",
        help="filter on cards with given done state",
    ),
    format: str = typer.Option(
        DEFAULT_TABLEFORMAT,
        "-f",
        "--format",
        help='table fomratting option, eg. "grid", "simple", "html"',
    ),
):
    """
    List cards in db.
    """
    set_cards_db_path()
    filter = {
        "noowner": noowner,
        "owner": owner,
        "priority": priority,
        "done": done
    }
    the_cards = cards.list_cards(filter=filter)

    #  json is a special case
    if format == "json":
        items = [c.to_dict() for c in the_cards]
        print(json.dumps({"cards": items}, sort_keys=True, indent=4))
        return

    # who's going to remember 'pipe' for markdown?
    if format == "markdown":
        format = "pipe"

    if format == "packed":
        for t in the_cards:
            done = "x" if t.done else "o"
            owner = "unassigned" if t.owner is None else t.owner
            line = f"{t.id} {owner} {t.priority} {done} {t.summary}"
            print(line)
        return

    # all formats except json/none use tabulate
    items = []
    for t in the_cards:
        done = " x " if t.done else ""
        owner = "" if t.owner is None else t.owner
        items.append((t.id, owner, t.priority, done, t.summary))

    print(
        tabulate(
            items,
            headers=("ID", "owner", "priority", "done", "summary"),
            tablefmt=format,
        ), )