Beispiel #1
0
    def _update_email(self) -> None:
        """
        Updates the user's global config with their email address

        If the user has passed an email on the command line, this logic is skipped.
        """
        # import inside def for performance
        from validate_email import validate_email

        if not self.email:
            self.email = self.global_config.get("email")

        if not self.email or not validate_email(self.email):
            content.UpdateEmail.leader.echo()

            email = None
            while not (email and validate_email(email)):
                self.context.start_user_timer()
                self._validate_interactivity()
                email = content.UpdateEmail.prompt.echo(
                    type=str, default=bento.git.user_email())
                self.context.stop_user_timer()
                echo_newline()

            if email != constants.QA_TEST_EMAIL_ADDRESS:
                r = self._post_email_to_mailchimp(email)
                if not r:
                    content.UpdateEmail.failure.echo()

            self.global_config["email"] = email
            persist_global_config(self.global_config)
Beispiel #2
0
def test_already_registered(tmp_path: Path, capsys: CaptureFixture) -> None:
    """Asserts registration skipped if current"""

    with setup_global_gitignore(tmp_path):
        with tmp_config(tmp_path) as ctx:
            persist_global_config({
                "email": QA_TEST_EMAIL_ADDRESS,
                "terms_of_service": TERMS_OF_SERVICE_VERSION,
            })
            registrar = Registrar(click_context=ctx,
                                  agree=False,
                                  email=QA_TEST_EMAIL_ADDRESS)
            assert registrar.verify()

    output = capsys.readouterr()
    assert not output.err
    assert not output.out
Beispiel #3
0
    def _confirm_tos_update(self) -> bool:
        """
        Interactive process to confirm updated agreement to the Terms of Service

        :return: If the user has agreed to the updated ToS
        """
        if constants.TERMS_OF_SERVICE_KEY not in self.global_config:
            self.renderer.echo("confirm-tos", "fresh")
        else:
            # We care that the user has agreed to the current terms of service
            tos_version = self.global_config[constants.TERMS_OF_SERVICE_KEY]

            try:
                agreed_to_version = Version(tos_version)
                if agreed_to_version == Version(
                        constants.TERMS_OF_SERVICE_VERSION):
                    logging.info("User ToS agreement is current")
                    return True
            except InvalidVersion:
                self.renderer.echo("confirm-tos", "invalid-version")
                sys.exit(3)

            self.renderer.echo("confirm-tos", "upgrade")

        self.context.start_user_timer()
        self._validate_interactivity()
        agreed = click.confirm(
            "Continue and agree to Bento's terms of service and privacy policy?",
            default=True,
        )
        echo_newline()
        self.context.stop_user_timer()

        if agreed:
            self.global_config[
                constants.
                TERMS_OF_SERVICE_KEY] = constants.TERMS_OF_SERVICE_VERSION

            persist_global_config(self.global_config)
            return True
        else:
            self.renderer.echo("confirm-tos", "error")
            return False
Beispiel #4
0
    def _query_gitignore_update(self) -> Tuple[Path, bool]:
        """
        Determines if gitignore should be updated by init

        Requirements:
        - Interactive terminal
        - bento/ not in ignore file
        - User hasn't previously opted out
        - User agrees

        :return: A tuple of (the path to the global git ignore, whether to update the file)
        """

        gitignore_path = (bento.git.global_ignore_path(self.context.base_path)
                          or constants.DEFAULT_GLOBAL_GIT_IGNORE_PATH)

        if sys.stderr.isatty() and sys.stdin.isatty():
            opt_out_value = self.global_config.get(
                constants.GLOBAL_GIT_IGNORE_OPT_OUT)
            user_opted_out = opt_out_value is not None and opt_out_value is True
            if user_opted_out:
                return gitignore_path, False
            has_ignore = None
            if gitignore_path.exists():
                with gitignore_path.open("r") as fd:
                    has_ignore = next(filter(lambda l: ".bento" in l, fd),
                                      None)
            if has_ignore is None:
                self.context.start_user_timer()
                if content.UpdateGitignore.confirm.echo(gitignore_path):
                    gitignore_path.parent.resolve().mkdir(exist_ok=True,
                                                          parents=True)
                    content.UpdateGitignore.confirm_yes.echo()
                    return gitignore_path, True
                else:
                    self.global_config[
                        constants.GLOBAL_GIT_IGNORE_OPT_OUT] = True

                    persist_global_config(self.global_config)
                    content.UpdateGitignore.confirm_no.echo()
                self.context.stop_user_timer()
        return gitignore_path, False
Beispiel #5
0
    def _confirm_tos_update(self) -> bool:
        """
        Interactive process to confirm updated agreement to the Terms of Service

        :return: If the user has agreed to the updated ToS
        """
        if constants.TERMS_OF_SERVICE_KEY not in self.global_config:
            content.ConfirmTos.fresh.echo()
        else:
            # We care that the user has agreed to the current terms of service
            tos_version = self.global_config[constants.TERMS_OF_SERVICE_KEY]

            try:
                agreed_to_version = Version(tos_version)
                if agreed_to_version == Version(
                        constants.TERMS_OF_SERVICE_VERSION):
                    logging.info("User ToS agreement is current")
                    return True
            except InvalidVersion:
                content.ConfirmTos.invalid_version.echo()
                raise InvalidVersionException()

            content.ConfirmTos.upgrade.echo()

        self.context.start_user_timer()
        self._validate_interactivity()
        agreed = content.ConfirmTos.prompt.echo()
        echo_newline()
        self.context.stop_user_timer()

        if agreed:
            self.global_config[
                constants.
                TERMS_OF_SERVICE_KEY] = constants.TERMS_OF_SERVICE_VERSION

            persist_global_config(self.global_config)
            return True
        else:
            content.ConfirmTos.error.echo()
            return False
Beispiel #6
0
    def _update_email(self) -> None:
        """
        Updates the user's global config with their email address

        If the user has passed an email on the command line, this logic is skipped.
        """
        # import inside def for performance
        from validate_email import validate_email

        valid_configured_email = False
        if "email" in self.global_config:
            configured_email = self.global_config.get("email")
            if configured_email is not None:
                valid_configured_email = validate_email(configured_email)

        if (not self.email or
                not validate_email(self.email)) and not valid_configured_email:
            self.renderer.echo("update-email", "leader")

            email = None
            while not (email and validate_email(email)):
                self.context.start_user_timer()
                self._validate_interactivity()
                email = click.prompt(
                    self.renderer.text_at("update-email", "prompt"),
                    type=str,
                    default=bento.git.user_email(),
                )
                self.context.stop_user_timer()
                echo_newline()

            r = self._post_email_to_mailchimp(email)
            if not r:
                self.renderer.echo("update-email", "failure")

            self.global_config["email"] = email
            persist_global_config(self.global_config)