Пример #1
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'
        )
Пример #2
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'
        )
Пример #3
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')
Пример #4
0
def test_query_extended_config(mock_connect):
    """Test query with extended config."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        test_fixtures.populate_isolated_filesystem(
            'extended_config.yml',
            'fake_query.sql'
        )
        result = runner.invoke(
            cli.cli,
            ['-c', 'config.yml', 'query', 'query.sql']
        )
        assert result.exit_code == 0

        assert mock_connect.called_with(
            'MY_MSSQL.example.com',
            'a_user',
            'a_password',
            port=2345,
            timeout=10
        )