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()
def assert_empty_settings(): settings = Settings() assert settings.get_github_token() == "" assert settings.get_github_login() == "" assert settings.get_github_emails() == [] assert settings.get_slack_token() == "" assert settings.get_slack_channel() == ""
def _get_payload(self): settings = Settings() payload = { "token": settings.get_slack_token(), "channel": settings.get_slack_channel(), "text": self.message, "as_user": True, "link_names": True, } if self.reply_to is not None: payload.update({"thread_ts": self.reply_to.ts}) return payload
def test_setup_ok(runner): _add_graphql_response(200, {"data": {"viewer": {"login": "******"}}}) _add_rest_response("/user/emails", 200, [{ "email": "email1" }, { "email": "email2" }, { "email": "email3" }]) _add_post_slack_api_response(SLACK_AUTH_CHECK_ENDPOINT, { "ok": True, "user": "******" }) _add_get_slack_api_response(SLACK_CHANNEL_LIST_ENDPOINT, { "ok": True, "channels": [{ "name": "slack_channel" }] }) result = runner.invoke( cli.main, ["account", "setup"], input="\n".join([ " github_token ", "y", " slack_token ", " slack_channel " ]), ) assert result.exit_code == ExitCode.NO_ERROR.value assert result.output == "\n".join([ get_welcome_text(), get_github_text(), "GitHub token: ", "✓ GitHub, hello user1! 💕✨", "(optional) Configure Slack integration? [y/N] y", get_slack_text(), "Slack token: ", "Slack channel: # slack_channel ", "✓ Slack, hello user1! 🔌✨", "✓ Done, you can safely rerun this command at any time!\n", ]) settings = Settings() assert settings.get_github_token() == "github_token" assert settings.get_github_login() == "user1" assert settings.get_github_emails() == ["email1", "email2", "email3"] assert settings.get_slack_token() == "slack_token" assert settings.get_slack_channel() == "slack_channel"