errands
small jobs the runtime does for the studio.
git clone https://owenrusk.dev/errands.git
errands / tests/fakes.py -rw-r--r-- · 1138 bytes
1 from email.message import EmailMessage 2 3 4 def raw(sender="someone@example.com", subject="hello", body="hello\n", message_id="<1@example.com>") -> bytes: 5 msg = EmailMessage() 6 msg["From"] = sender 7 msg["To"] = "support@papermothgames.com" 8 msg["Subject"] = subject 9 msg["Message-ID"] = message_id 10 msg.set_content(body) 11 return bytes(msg) 12 13 14 class FakeBox: 15 def __init__(self, messages: dict[bytes, bytes]): 16 self.messages = messages 17 self.stored: list[tuple] = [] 18 self.closed = False 19 20 def uid(self, command, *args): 21 if command == "search": 22 return "OK", [b" ".join(self.messages)] 23 if command == "fetch": 24 return "OK", [(b"", self.messages[args[0]])] 25 if command == "store": 26 self.stored.append(args) 27 return "OK", [] 28 raise AssertionError(command) 29 30 def logout(self): 31 self.closed = True 32 33 34 class FakeServer: 35 def __init__(self): 36 self.sent = [] 37 self.quit_called = False 38 39 def send_message(self, msg): 40 self.sent.append(msg) 41 42 def quit(self): 43 self.quit_called = True