def it_should_show_help(capsys) -> None:
        with pytest.raises(SystemExit):
            args = [
                *_server_args(),
                *_integrated_security_arg(),
            ]

            parse_main_arguments(args)

            _assert_error_message(capsys)
    def it_should_require_password(capsys) -> None:
        with pytest.raises(SystemExit):
            args = [
                *_server_args(),
                *_db_name_args(),
                *_username_args(),
            ]

            parse_main_arguments(args)

            _assert_error_message(capsys)
    def it_should_store_the_file_path(capsys) -> None:
        args = [
            *_server_args(),
            *_db_name_args(),
            *_integrated_security_arg(),
            *_exception_report_args(),
        ]

        parsed = parse_main_arguments(args)

        assert parsed.exceptions_report_directory == REPORT_DIR
    def it_should_not_require_username_and_password(capsys) -> None:
        args = [
            *_server_args(),
            *_db_name_args(),
            *_integrated_security_arg(),
        ]

        parsed = parse_main_arguments(args)

        assert parsed is not None, "No arguments detected"

        _assert_no_messages(capsys)
        def it_should_add_Encrypt_to_connection_string(capsys) -> None:
            args = [
                *_server_args(),
                *_db_name_args(),
                *_integrated_security_arg(),
                *_encrypt_args(),
            ]
            parsed = parse_main_arguments(args)

            _assert_no_messages(capsys)

            url = str(parsed.get_adapter().engine.url)
            assert "Encrypt=yes" in url
            assert "TrustServerCertificate=yes" not in url
        def it_should_set_trusted_connection_in_the_connection_string(
            capsys, ) -> None:
            args = [
                *_server_args(), *_db_name_args(), *_integrated_security_arg()
            ]

            parsed = parse_main_arguments(args)

            _assert_no_messages(capsys)

            assert parsed is not None, "No arguments detected"

            # Only need to confirm that the adapter was created
            assert parsed.get_adapter() is not None
        def it_should_parse_the_log_level(capsys) -> None:
            args = [
                *_server_args(),
                *_db_name_args(),
                *_integrated_security_arg(),
                "--log-level",
                "DEBUG",
            ]

            parsed = parse_main_arguments(args)

            _assert_no_messages(capsys)

            assert parsed is not None, "No arguments detected"
            assert parsed.log_level == "DEBUG"
    def it_should_inject_port_into_connection_string(capsys) -> None:
        args = [
            *_server_args(),
            *_db_name_args(),
            *_integrated_security_arg(),
            *_port_args(),
        ]

        parsed = parse_main_arguments(args)

        _assert_no_messages(capsys)

        assert parsed is not None, "No arguments detected"

        assert parsed.port == PORT
    def fixture(capsys) -> MainArguments:
        # Arrange
        args = [
            *_server_args(),
            *_db_name_args(),
            *_username_args(),
            *_password_args(),
            *_port_args(),
            *_engine_postgresql(),
        ]

        # Act
        parsed = parse_main_arguments(args)

        _assert_no_messages(capsys)

        return parsed
Ejemplo n.º 10
0
def main() -> None:
    global logger

    load_dotenv()
    arguments = parse_main_arguments(sys.argv[1:])
    _configure_logging(arguments)
    error_tracker: ErrorHandler = ErrorHandler()

    try:
        run(arguments)
    except Exception as error:
        logger.error(error)
        print(error.__traceback__, file=sys.stderr)

    if error_tracker.fired:
        print(
            "A fatal error occurred, please review the log output for more information.",
            file=sys.stderr,
        )
        sys.exit(1)
    sys.exit(0)