def mock_slack(monkeypatch): mock_slack = MagicMock(spec=SlackClient("")) mock_slack.get_channel_name.return_value = "#inc-test-channel" mock_slack.send_or_update_message_block.return_value = { "ok": True, "ts": 1234, } monkeypatch.setattr(settings, "SLACK_CLIENT", mock_slack) return mock_slack
def get_env_var(setting, warn_only=False): value = os.getenv(setting, None) if not value: error_msg = f"ImproperlyConfigured: Set {setting} environment variable" if warn_only: logger.warn(error_msg) else: raise ImproperlyConfigured(error_msg) else: value = value.replace('"', "") # remove start/end quotes return value SLACK_TOKEN = get_env_var("SLACK_TOKEN") SLACK_CLIENT = SlackClient(SLACK_TOKEN) SITE_URL = os.environ.get("SITE_URL") if os.environ.get("POSTGRES"): DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", "HOST": os.getenv("DB_HOST", "postgres"), "PORT": os.getenv("DB_PORT", "5432"), "USER": os.getenv("DB_USER", "postgres"), "NAME": os.getenv("DB_NAME", "postgres"), "PASSWORD": os.environ.get("DB_PASSWORD"), "OPTIONS": {"sslmode": os.getenv("DB_SSL_MODE", "disable")}, } }
"vertical-align", "text-align", "border-style", "border-width", "float", "margin", "margin-bottom", "margin-left", "margin-right", "margin-top", ] def get_env_var(setting, warn_only=False): value = os.getenv(setting, None) if not value: error_msg = f"ImproperlyConfigured: Set {setting} environment variable" if warn_only: logger.warn(error_msg) else: raise ImproperlyConfigured(error_msg) else: value = value.replace('"', "") # remove start/end quotes return value SLACK_TOKEN = get_env_var("SLACK_TOKEN") SLACK_CLIENT = SlackClient(SLACK_TOKEN)
def get_env_var(setting, warn_only=False, default=None): value = os.getenv(setting, default) if not value: error_msg = f"ImproperlyConfigured: Set {setting} environment variable" if warn_only: logger.warning(error_msg) else: raise ImproperlyConfigured(error_msg) else: value = value.replace('"', '') # remove start/end quotes return value SITE_URL = get_env_var("SITE_URL", default="http://localhost:8000") SLACK_TOKEN = get_env_var("SLACK_TOKEN") SLACK_CLIENT = SlackClient(SLACK_TOKEN) SLACK_SIGNING_SECRET = get_env_var("SLACK_SIGNING_SECRET") INCIDENT_CHANNEL_NAME = get_env_var("INCIDENT_CHANNEL_NAME") INCIDENT_BOT_NAME = get_env_var("INCIDENT_BOT_NAME") SECRET_KEY = get_env_var("SECRET_KEY") INCIDENT_BOT_ID = get_env_var( "INCIDENT_BOT_ID", default=SLACK_CLIENT.get_user_id(INCIDENT_BOT_NAME)) INCIDENT_CHANNEL_ID = get_env_var( "INCIDENT_CHANNEL_ID", default=SLACK_CLIENT.get_channel_id(INCIDENT_CHANNEL_NAME)) STATUS_PAGE_PLAYBOOK_URL = get_env_var("STATUS_PAGE_PLAYBOOK_URL") PLAYBOOKS_URL = get_env_var("PLAYBOOKS_URL")