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
11 changes: 0 additions & 11 deletions src/aggregator/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import random
from collections import defaultdict
from functools import partial

from .bots.bot_logic import BotLogic
from .messages import (
Expand All @@ -13,7 +12,6 @@
ProblemMachineLeftOnBySomeoneElse,
ProblemMachineLeftOnByUser,
ProblemsLeavingSpaceNotification,
StaleCheckoutNotification,
TestNotification,
)
from .model import (
Expand Down Expand Up @@ -323,15 +321,6 @@ def _check_out_stale_user(self, user_id, ts_checkin, elapsed_time_in_hours, logg
if self.crm_adapter:
self.crm_adapter.user_checkout(user_id, logger)

notification = StaleCheckoutNotification(
user, ts_checkin, self.urls.notification_settings(), self.urls.space_state()
)
self.task_scheduler.schedule_task_at_time(
self.clock.now().replace(hour=8, minute=0),
partial(self.send_user_notification, user, notification),
logger,
)

def send_user_notification(self, user, notification, logger):
if self.telegram_bot and user.uses_telegram_bot():
chat_id = None
Expand Down
74 changes: 0 additions & 74 deletions src/aggregator/logic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,80 +55,6 @@ def test_enter_and_leave_space(self):
],
)

def test_stale_checkout_detection(self):
# Check in at 11pm
self.clock.set_time_of_day("23:00")
self.aggregator.user_entered_space(STEFANO.user_id, self.logger)

# After an hour (at midnight)
self.clock.add(1, "hour")
space_state = self.aggregator.get_space_state_for_json(self.logger)
self.assertEqual(
space_state["users_in_space"],
[
{
"ts_checkin": "23:00:00 03/02/2019",
"ts_checkin_human": "an hour ago",
"user": {
"email": "stefano@stefanomasini.com",
"first_name": "Stefano",
"full_name": "Stefano Masini",
"last_name": "Masini",
"user_id": 1,
},
"machines_on": [],
},
],
)

# At 5 am
self.clock.add(5, "hour")
space_state = self.aggregator.get_space_state_for_json(self.logger)
self.assertEqual(
space_state["users_in_space"],
[
{
"ts_checkin": "23:00:00 03/02/2019",
"ts_checkin_human": "6 hours ago",
"user": {
"email": "stefano@stefanomasini.com",
"first_name": "Stefano",
"full_name": "Stefano Masini",
"last_name": "Masini",
"user_id": 1,
},
"machines_on": [],
},
],
)

# Detect stale checkins
self.aggregator.clean_stale_user_checkins(self.logger)
space_state = self.aggregator.get_space_state_for_json(self.logger)
self.assertEqual(space_state["users_in_space"], [])
self.assertEqual(self.bot_messages, [])

# At 9 am
self.clock.add(4, "hour")
self.task_scheduler.actually_execute_due_tasks(self.logger)
self.assertEqual(
self.bot_messages,
[
(1, "StaleCheckoutNotification"),
],
)
self.bot_messages = []
self.assertEqual(
self.emails_sent,
[
(1, "StaleCheckoutNotification"),
],
)

# No more messages after that
self.task_scheduler.actually_execute_due_tasks(self.logger)
self.assertEqual(self.bot_messages, [])

def test_warn_user_when_he_leaves_and_his_machine_is_on(self):
self.aggregator.user_entered_space(STEFANO.user_id, self.logger)

Expand Down
27 changes: 0 additions & 27 deletions src/aggregator/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,6 @@ class MessageCancelAction(BaseBotMessage):
# -- Notifications ----


class StaleCheckoutNotification(BaseBotMessage):
def __init__(self, user, ts_checkin, notification_settings_url, space_state_url):
self.user = user
self.ts_checkin = ts_checkin
self.notification_settings_url = notification_settings_url
self.space_state_url = space_state_url

def get_text(self):
return f"Did you forget to checkout yesterday?\nYou entered the Space at {self.ts_checkin.human_str()}"

def get_email_text(self):
return (
f"Hello {self.user.first_name},\n\n"
"It looks like you might have forgotten to checkout at the space yesterday?\n"
f"According to the logs you entered the space at {self.ts_checkin.human_str()}, but there's no trace of a checkout.\n\n"
"Checking out is useful so that other people know when to expect other fellow makers at the space, and it allows me to provide useful reminders, "
"like if the lights are still on when the last person leaves.\n\n"
"Checking out can be done when you leave, by simply swiping your card again, while you hold the door open on your way out.\n"
f"Or it can also be done via the Space State page: {self.space_state_url}\n"
f"page: {self.notification_settings_url}\n\n"
"The MakerSpace BOT\n\n"
)

def get_subject_for_email(self):
return "Forgot to checkout"


class MachineLeftOnNotification(BaseBotMessage):
def __init__(self, machine):
self.machine = machine
Expand Down