Esempio n. 1
0
def test_query_csv(mock_connect):
    """Test query with CSV output."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        test_fixtures.populate_isolated_filesystem(
            'basic_config.yml',
            'fake_query.sql'
        )
        result = runner.invoke(
            cli.cli,
            ['-c', 'config.yml', '-o', 'csv', 'query', 'query.sql']
        )
        assert result.exit_code == 0
        assert result.output in [
            test_fixtures.get_file_contents(
                'csv_outputs/query_expected_csv_output.csv'
            ),
            test_fixtures.get_file_contents(
                'csv_outputs/query_expected_csv_output_2.csv'
            )
        ]
        assert mock_connect.called_with(
            'MY_MSSQL.example.com',
            'a_user',
            'a_password'
        )
Esempio n. 2
0
def test_template_query_basic(mock_connect):
    """Test query with Pretty output."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        test_fixtures.populate_isolated_filesystem(
            'basic_config.yml',
            'fake_template_query.sql'
        )
        result = runner.invoke(
            cli.cli,
            ['-c', 'config.yml', '-o', 'pretty',
             'template_query', '-v', 'last_name:Troxel', 'query.sql']
        )
        assert result.exit_code == 0
        assert result.output in [
            test_fixtures.get_file_contents(
                'pretty_outputs/query_expected_pretty_output3'
            ),
            test_fixtures.get_file_contents(
                'pretty_outputs/query_expected_pretty_output4'
            )
        ]
        assert mock_connect.called_with(
            'MY_MSSQL.example.com',
            'a_user',
            'a_password'
        )
Esempio n. 3
0
def test_pretty_print():
    """Test that output is properly pretty printed from dictionary object."""
    obj = [{
        "one": "red",
        "two": "blue"
    }, {
        "one": datetime(2016, 10, 20, 21, 10, 36, 621341),
        "two": "black"
    }]
    output = formats.pretty_print(obj)
    assert output in [
        get_file_contents(
            'pretty_outputs/query_expected_pretty_output').strip(),
        get_file_contents(
            'pretty_outputs/query_expected_pretty_output2').strip()
    ]
Esempio n. 4
0
def test_render_template():
    """Test that jinja2 query templates are properly rendered."""
    query = StringIO(
        test_fixtures.get_file_contents('fake_template_query.sql')
    )
    query = cli.render_template(query, last_name="Troxel")
    assert query == "SELECT * FROM bogus_table WHERE last_name = Troxel;"
Esempio n. 5
0
def test_query_basic(mock_connect):
    """Test query with basic options (json)."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        test_fixtures.populate_isolated_filesystem('basic_config.yml',
                                                   'fake_query.sql')
        result = runner.invoke(cli.cli,
                               ['query', '-c', 'config.yml', 'query.sql'])
        assert result.exit_code == 0
        assert json.loads(result.output) == json.loads(
            test_fixtures.get_file_contents(
                'json_outputs/query_expected_json_output.json'))
        assert mock_connect.called_with('MY_MSSQL.example.com', 'a_user',
                                        'a_password')