fix(config): return None if env var is empty or non-existent (#315)

* fix(config): return None if env var is empty or non-existent
* chore: fix pylint issues
* fix: add unit test for non-existent env vars
This commit is contained in:
2024-11-21 22:26:07 +00:00
committed by GitHub
parent 31269af218
commit f611b685b3
10 changed files with 172 additions and 82 deletions

View File

@ -1,20 +1,12 @@
#!/usr/bin/env python3
"""Submit task command."""
import logging
import sentry_sdk
import sentry_sdk
from webex_bot.models.command import Command
from webex_bot.models.response import Response, response_from_adaptive_card
from webexteamssdk.models.cards import (
AdaptiveCard,
Column,
ColumnSet,
Date,
FontSize,
FontWeight,
Text,
TextBlock,
)
from webexteamssdk.models.cards import (AdaptiveCard, Column, ColumnSet, Date,
FontSize, FontWeight, Text, TextBlock)
from webexteamssdk.models.cards.actions import Submit
from app.utils.config import config
@ -24,7 +16,10 @@ log: logging.Logger = logging.getLogger(__name__)
class SubmitTaskCommand(Command):
"""Submit task command."""
def __init__(self) -> None:
"""Submit task command."""
super().__init__(
command_keyword="submit_feedback_dstgmyn",
help_message="Submit Task",
@ -34,9 +29,11 @@ class SubmitTaskCommand(Command):
self.sender: str = ""
def pre_execute(self, message, attachment_actions, activity) -> None:
"""Pre-execute method."""
self.sender = activity.get("actor").get("id")
def execute(self, message, attachment_actions, activity) -> Response:
"""Execute method."""
card_body: list = [
ColumnSet(
columns=[
@ -48,7 +45,8 @@ class SubmitTaskCommand(Command):
size=FontSize.MEDIUM,
),
TextBlock(
f"Add a task to {config.admin_first_name}'s To Do list. All fields are required. Please don't use special characters.",
f"Add a task to {config.admin_first_name}'s To Do list. "
+ "All fields are required. Please don't use special characters.",
wrap=True,
isSubtle=True,
),
@ -62,7 +60,9 @@ class SubmitTaskCommand(Command):
Column(
width=2,
items=[
Text(id="issue_title", placeholder="Summary", maxLength=100),
Text(
id="issue_title", placeholder="Summary", maxLength=100
),
Text(
id="issue_description",
placeholder="Description",
@ -85,7 +85,8 @@ class SubmitTaskCommand(Command):
items=[
Text(
id="issue_requester",
placeholder="Requester Email (leave blank to submit for yourself)",
placeholder="Requester Email "
+ "(leave blank to submit for yourself)",
maxLength=100,
),
],
@ -119,19 +120,26 @@ class SubmitTaskCommand(Command):
class SubmitTaskCallback(Command):
"""Submit task callback."""
def __init__(self) -> None:
"""Submit task callback."""
super().__init__(
card_callback_keyword="submit_task_callback_rbamzfyx", delete_previous_message=True
card_callback_keyword="submit_task_callback_rbamzfyx",
delete_previous_message=True,
)
self.msg: str = ""
def pre_execute(self, message, attachment_actions, activity) -> None:
"""Pre-execute method."""
issue_title: str = attachment_actions.inputs.get("issue_title")
issue_description: str = attachment_actions.inputs.get("issue_description")
completion_date: str = attachment_actions.inputs.get("completion_date")
sender: str = attachment_actions.inputs.get("sender")
issue_requester: str = attachment_actions.inputs.get("issue_requester") or sender
issue_requester: str = (
attachment_actions.inputs.get("issue_requester") or sender
)
if not issue_title or not issue_description or not completion_date:
self.msg = "Please complete all fields."
@ -145,29 +153,38 @@ class SubmitTaskCallback(Command):
)
self.msg = (
"Submitting your task..." if result else "Failed to submit task. Please try again."
"Submitting your task..."
if result
else "Failed to submit task. Please try again."
)
def execute(self, message, attachment_actions, activity) -> str:
"""Execute method."""
with sentry_sdk.start_transaction(name="submit_task_callback"):
return self.msg
class MyTasksCallback(Command):
"""My tasks callback."""
def __init__(self) -> None:
"""My tasks callback."""
super().__init__(
card_callback_keyword="my_tasks_callback_rbamzfyx", delete_previous_message=True
card_callback_keyword="my_tasks_callback_rbamzfyx",
delete_previous_message=True,
)
self.msg: str = ""
def pre_execute(self, message, attachment_actions, activity) -> str:
"""Pre-execute method."""
with sentry_sdk.start_transaction(name="my_tasks_preexec"):
return "Getting your tasks..."
def execute(self, message, attachment_actions, activity) -> str | None:
"""Execute method."""
sender: str = attachment_actions.inputs.get("sender")
result: bool = get_tasks(requestor=sender)
with sentry_sdk.start_transaction(name="my_tasks_exec"):
if not result:
return "Failed to get tasks. Please try again."
return
return None