Put fallbacks in their own file.
This commit is contained in:
parent
d358c55017
commit
3857674244
|
@ -1,7 +1,6 @@
|
|||
import os
|
||||
import sys
|
||||
import threading
|
||||
import types
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional
|
||||
|
@ -10,6 +9,8 @@ from uuid import uuid4, UUID
|
|||
import bcrypt
|
||||
import psycopg
|
||||
|
||||
from undercover.fallback import MockConnection
|
||||
|
||||
|
||||
@dataclass
|
||||
class Letter:
|
||||
|
@ -53,23 +54,6 @@ else:
|
|||
def connect():
|
||||
return MockConnection()
|
||||
|
||||
class MockConnection:
|
||||
mock_cursor = types.SimpleNamespace()
|
||||
mock_cursor.execute = lambda *a: ()
|
||||
mock_cursor.fetchone = lambda *a: None
|
||||
mock_cursor.fetchall = lambda *a: []
|
||||
|
||||
def __enter__(self, *a):
|
||||
return self
|
||||
|
||||
def __exit__(self, *a):
|
||||
pass
|
||||
|
||||
def cursor(self):
|
||||
return self.mock_cursor
|
||||
|
||||
def commit(self, *a):
|
||||
pass
|
||||
|
||||
|
||||
def login(user_email: str, password: str):
|
||||
|
|
|
@ -3,6 +3,7 @@ import os
|
|||
import sys
|
||||
|
||||
from mailjet_rest import Client
|
||||
from undercover.fallback import mock_sender
|
||||
|
||||
api_key = os.environ.get('MAILJET_API_KEY')
|
||||
api_secret = os.environ.get('MAILJET_SECRET_KEY')
|
||||
|
@ -14,6 +15,7 @@ if not mailjet:
|
|||
sys.stderr.write('Mailjet keys not configured: email access is disabled.\n')
|
||||
sys.stderr.write(' Emails will be printed to the console.\n')
|
||||
sys.stderr.write(' To enable, ensure MAILJET_API_KEY and MAILJET_SECRET_KEY are set\n')
|
||||
mailjet = mock_sender
|
||||
|
||||
|
||||
def send_password_reset(to_email: str, reset_link: str):
|
||||
|
@ -39,13 +41,9 @@ Or copy and paste this link into your browser: {reset_link}
|
|||
]
|
||||
}
|
||||
|
||||
if mailjet:
|
||||
result = mailjet.send.create(data=data)
|
||||
return 200 <= result.status_code <= 299
|
||||
|
||||
print(json.JSONEncoder(indent=2).encode(data))
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
send_password_reset('sage@sagev.space', 'https://sagev.space/')
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import types
|
||||
import json
|
||||
|
||||
class MockConnection:
|
||||
mock_cursor = types.SimpleNamespace()
|
||||
mock_cursor.execute = lambda *a: ()
|
||||
mock_cursor.fetchone = lambda *a: None
|
||||
mock_cursor.fetchall = lambda *a: []
|
||||
|
||||
def __enter__(self, *a):
|
||||
return self
|
||||
|
||||
def __exit__(self, *a):
|
||||
pass
|
||||
|
||||
def cursor(self):
|
||||
return self.mock_cursor
|
||||
|
||||
def commit(self, *a):
|
||||
pass
|
||||
|
||||
|
||||
class MockCreator:
|
||||
def create(self, data=None, *a):
|
||||
print(json.JSONEncoder(indent=2).encode(data))
|
||||
result = types.SimpleNamespace()
|
||||
result.status_code = 200
|
||||
return result
|
||||
|
||||
|
||||
mock_sender = types.SimpleNamespace()
|
||||
mock_sender.send = lambda self: MockCreator()
|
||||
|
Loading…
Reference in New Issue