コード例 #1
0
def test_breakdown_default(groc_connection, groc_db_url,
                           connection_function_scope,
                           stores_and_purchases_function_scope):

    groc_connection.return_value = connection_function_scope
    g = Groc()
    today = datetime.date.today()
    month, year = [today.strftime('%m')], [today.strftime('%Y')]

    data = g.breakdown(month, year)
    table = from_db_cursor(data)
    field_names = [name for name in table.field_names]

    # No purchases exist for the current month.
    # Add a row with dashes if table empty
    temp_str = table.get_string()
    temp_table = copy.deepcopy(table)
    temp_table.clear_rows()
    if temp_str == temp_table.get_string():
        table.add_row(['--' for x in field_names])

    # Rmove columns used for db ordering
    field_names.remove('num_month')
    field_names.remove('min purchase')
    field_names.remove('max purchase')
    field_names.remove('avg purchase')
    field_names.remove('store count')
    output_msg = table.get_string(fields=field_names)

    runner = CliRunner()
    result = runner.invoke(groc_cli, ['breakdown'])
    assert result.exit_code == 0
    assert result.output == f'{output_msg}\n'
コード例 #2
0
def test_breakdown_year_month_year_verbose(
        groc_connection, groc_db_url, connection_function_scope,
        stores_and_purchases_function_scope):

    groc_connection.return_value = connection_function_scope
    g = Groc()
    month, year = ['01', '02'], ['2019']

    data = g.breakdown(month, year)
    table = from_db_cursor(data)
    field_names = [name for name in table.field_names]

    # Rmove columns used for db ordering
    field_names.remove('num_month')
    output_msg = table.get_string(fields=field_names)

    runner = CliRunner()
    result = runner.invoke(
        groc_cli,
        ['breakdown', '-m', '01', '-m', '02', '-y', '2019', '--verbose'])
    assert result.exit_code == 0
    assert result.output == f'{output_msg}\n'
コード例 #3
0
ファイル: test_models.py プロジェクト: sjbitcode/groc
def test_breakdown(
    mock_count_total, mock_create_connection, mock_os_path_expanduser
):
    g = Groc()
    g.breakdown('01', '2019')
    mock_count_total.assert_called_with('some-connection', '01', '2019')