Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/core/cshcalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]] = []

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions src/core/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions src/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 13 additions & 10 deletions src/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
52 changes: 51 additions & 1 deletion tests/src/core/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!"))
Expand Down
Loading