Exemplo n.º 1
0
def _setup_slack():
    settings = Settings()

    if settings.is_slack_valid():
        if not click.confirm("Reset Slack config?", prompt_suffix=" "):
            return
    else:
        if not click.confirm("(optional) Configure Slack integration?",
                             prompt_suffix=" "):
            return

    click.echo(get_slack_text())
    token = click.prompt("Slack token", type=click.STRING,
                         hide_input=True).strip()
    channel = click.prompt("Slack channel",
                           type=click.STRING,
                           prompt_suffix=": #").strip()
    settings.set_slack_token(token)
    settings.set_slack_channel(channel)

    try:
        auth_query = SlackAuthCheck()
        auth_query.execute()  # pylint: disable=no-value-for-parameter
        channel_query = SlackChannelListQuery()
        channel_query.execute()
        if channel not in channel_query.channels:
            raise click.ClickException("Channel does not exist")
    except Exception as exception:
        settings.reset_slack()
        raise exception

    click.secho("✓ Slack, hello {}! 🔌✨".format(auth_query.user),
                bold=True)
Exemplo n.º 2
0
def test_set_get_reset_settings():
    settings = Settings()
    settings.set_github_token("github_token")
    settings.set_github_login("github_login")
    settings.set_github_emails(
        ["github_email1", "github_email2", "github_email3"])

    assert settings.is_github_valid()
    assert not settings.is_slack_valid()
    assert settings.get_github_token() == "github_token"
    assert settings.get_github_login() == "github_login"
    assert settings.get_github_emails() == [
        "github_email1", "github_email2", "github_email3"
    ]

    settings.set_slack_token("slack_token")
    settings.set_slack_channel("slack_channel")

    assert settings.is_github_valid()
    assert settings.is_slack_valid()
    assert settings.get_slack_token() == "slack_token"
    assert settings.get_slack_channel() == "slack_channel"

    settings.reset_slack()
    assert not settings.is_slack_valid()
    settings.reset_github()
    assert not settings.is_github_valid()
    assert_empty_settings()
Exemplo n.º 3
0
def fill_settings():
    settings = Settings()
    settings.set_github_emails(
        ["*****@*****.**", "*****@*****.**", "*****@*****.**"])
    settings.set_github_login("user1")
    settings.set_github_token("github_token")
    settings.set_slack_token("slack_token")
    settings.set_slack_channel("slack_channel")