diff --git a/mkdocs.yml b/mkdocs.yml index 1b7673e..a806442 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -38,7 +38,7 @@ use_directory_urls: false nav: - Home: index.md - Getting Started: getting-started/getting-started.md - - Backend: + - Backend: - Calendar: core/csh_calendar.md - Slack: core/slack.md - Wikithoughts: core/wikithoughts.md diff --git a/src/core/cshcalendar.py b/src/core/cshcalendar.py index 01b7c34..a5788cc 100644 --- a/src/core/cshcalendar.py +++ b/src/core/cshcalendar.py @@ -136,6 +136,7 @@ def repl(match: re.Match[str]) -> str: return TIME_PATTERN.sub(repl, unformatted_string) + def format_events(events: list[CalendarInfo]) -> list[dict[str, str]]: """ Formats a parsed list of CalendarInfos, and returns the HTML required for front end @@ -150,7 +151,7 @@ def format_events(events: list[CalendarInfo]) -> list[dict[str, str]]: current_date: date = datetime.now(ZoneInfo(CALENDAR_TIMEZONE)) if not events: - return {"data": [{"header": ":(", "content": "No Events on the Calendar"}]} + return [{"header": ":(", "content": "No Events on the Calendar"}] formatted_list: list[dict[str, str]] = [] @@ -291,9 +292,9 @@ async def get_future_events() -> list[CalendarInfo]: if cal_correct_length: logger.info("Calendar cache is full length, rebuilding async!") - async with asyncio.TaskGroup() as taskGroup: - taskGroup.create_task(rebuild_calendar()) - # Calendar is correct length, we can just run this in the background + asyncio.create_task( + rebuild_calendar() + ) # Calendar is correct length, we can just run this in the background else: logger.info("Calendar cache is NOT full length, yielding rebuild!") await rebuild_calendar() diff --git a/src/core/slack.py b/src/core/slack.py index 1b410b3..699d6ca 100644 --- a/src/core/slack.py +++ b/src/core/slack.py @@ -32,11 +32,10 @@ "user": "Jumpstart", "timestamp": datetime.now(ZoneInfo(CALENDAR_TIMEZONE)) .strftime("%I:%M %p") - .lstrip("0") + .lstrip("0"), } - def clean_text(raw: str) -> str: """ Strip Slack mrkdwn, HTML entities, and formatting characters. diff --git a/src/main.py b/src/main.py index 0fd0da7..8b94c94 100644 --- a/src/main.py +++ b/src/main.py @@ -27,8 +27,7 @@ @asynccontextmanager async def lifespan(app: FastAPI): logger.info("Starting up the Jumpstart application!") - async with asyncio.TaskGroup() as tg: - tg.create_task(cshcalendar.rebuild_calendar()) + asyncio.create_task(cshcalendar.rebuild_calendar()) await wikithoughts.auth_bot() yield diff --git a/src/static/css/style.css b/src/static/css/style.css index f3f7066..4df74f6 100644 --- a/src/static/css/style.css +++ b/src/static/css/style.css @@ -8,12 +8,6 @@ --shadow-color: rgb(176,25,126, 0.5); /* Used for the shadow in the calendar */ } -/* b { - display: flex; - align-items: center; - justify-content: center; -} */ - .theme-dark { --panel-header-color: #B0197E; --panel-header-text-color: #FFFFFF; diff --git a/src/static/js/main.js b/src/static/js/main.js index 457cb72..9fca239 100644 --- a/src/static/js/main.js +++ b/src/static/js/main.js @@ -48,12 +48,13 @@ function setWeatherTheme(newTheme) { newWidget.id = "weather-image"; newWidget.href = "https://forecast7.com/en/43d16n77d61/rochester/?unit=us"; - newWidget.setAttribute("data-label_1", "ROCHESTER"); - newWidget.setAttribute("data-label_2", "WEATHER"); - newWidget.setAttribute("data-font", "Fira Sans"); - newWidget.setAttribute("data-icons", "Climacons Animated"); - newWidget.setAttribute("data-days", "100"); - newWidget.setAttribute("data-theme", newTheme); + newWidget.dataset.label_1 = "ROCHESTER"; + + newWidget.dataset.label_2 = "WEATHER"; + newWidget.dataset.font = "Fira Sans"; + newWidget.dataset.icons = "Climacons Animated"; + newWidget.dataset.days = "100"; + newWidget.dataset.theme = newTheme; newWidget.textContent = "ROCHESTER WEATHER"; oldWidget.replaceWith(newWidget); @@ -63,10 +64,11 @@ function setNewPageTheme(newTheme) { if (newTheme === currentPageTheme) return; currentPageTheme = newTheme; - document.body.classList.forEach(cls => { - if (cls.startsWith('theme-')) { - document.body.classList.remove(cls); - }}); + for (const classList of document.body.classList) { + if (classList.startsWith("theme-")) { + document.body.classList.remove(classList) + } + } document.body.classList.toggle(newTheme); } @@ -96,6 +98,7 @@ async function generateCalendar(calData) { calendar.replaceChildren(); calendar.appendChild(document.createElement("br")); + for (const event of calData) { const newEvent = createCalendarEvent(event.header, event.content); calendar.appendChild(newEvent); diff --git a/tests/src/core/test_slack.py b/tests/src/core/test_slack.py index ea952a4..2360710 100644 --- a/tests/src/core/test_slack.py +++ b/tests/src/core/test_slack.py @@ -46,9 +46,57 @@ def test_clean_text_and_convert_response(monkeypatch): assert slack.convert_user_response_to_bool(yes_payload) is True assert slack.convert_user_response_to_bool(no_payload) is False # malformed payload - assert slack.convert_user_response_to_bool({}) is False + assert slack.convert_user_response_to_bool(True) is False +def test_get_username(monkeypatch): + """ + Test the get_username function in the slack module. + + Args: + monkeypatch: The pytest monkeypatch fixture. + """ + slack = import_slack_module(monkeypatch) + + class FakeClient(): + def __init__(self,display_name=None,real_name=None,name=None): + self.display_name:str | None = display_name + self.real_name:str | None = real_name + self.name:str | None = name + + async def users_info(self, user): + return { + "ok": True, + "user": { + "profile":{ + "display_name": self.display_name + }, + "real_name": self.real_name, + "name": self.name, + }, + } + + #Test Display Name + monkeypatch.setattr(slack, "client", FakeClient(display_name="DisplayName")) + username = asyncio.run(slack.get_username(user_id="")) + assert username == "DisplayName" + + #Test Real Name + monkeypatch.setattr(slack, "client", FakeClient(real_name="RealName")) + username = asyncio.run(slack.get_username(user_id="")) + assert username == "RealName" + + #Test Account Name + monkeypatch.setattr(slack, "client", FakeClient(name="AccountName")) + username = asyncio.run(slack.get_username(user_id="")) + assert username == "AccountName" + + # Test Unknown + monkeypatch.setattr(slack, "client", FakeClient()) + username = asyncio.run(slack.get_username(user_id="")) + assert username == "Unknown" + + # Test Failure def test_gather_emojis_success_and_failure(monkeypatch): """ Test the gather_emojis function in the slack module. @@ -107,6 +155,8 @@ async def chat_postMessage(self, *, channel, text, blocks): recorded["text"] = text recorded["blocks"] = blocks + asyncio.run(slack.request_upload_via_dm("U123", "Announcement!")) + monkeypatch.setattr(slack, "client", FakeClient()) asyncio.run(slack.request_upload_via_dm("U123", "Announcement!"))