2022-09-26 22:47:38 -04:00
|
|
|
import types
|
|
|
|
import json
|
|
|
|
|
2022-09-27 08:32:32 -04:00
|
|
|
|
2022-09-26 22:47:38 -04:00
|
|
|
class MockConnection:
|
|
|
|
mock_cursor = types.SimpleNamespace()
|
|
|
|
mock_cursor.execute = lambda *a: ()
|
|
|
|
mock_cursor.fetchone = lambda *a: None
|
|
|
|
mock_cursor.fetchall = lambda *a: []
|
|
|
|
|
2022-09-28 17:53:32 -04:00
|
|
|
def __enter__(self, *a) -> object:
|
2022-09-26 22:47:38 -04:00
|
|
|
return self
|
|
|
|
|
2022-09-28 17:53:32 -04:00
|
|
|
def __exit__(self, *a) -> None:
|
2022-09-26 22:47:38 -04:00
|
|
|
pass
|
|
|
|
|
2022-09-28 17:53:32 -04:00
|
|
|
def cursor(self) -> object:
|
2022-09-26 22:47:38 -04:00
|
|
|
return self.mock_cursor
|
|
|
|
|
2022-09-28 17:53:32 -04:00
|
|
|
def commit(self, *a) -> None:
|
2022-09-26 22:47:38 -04:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class MockCreator:
|
2022-09-27 08:32:32 -04:00
|
|
|
@staticmethod
|
2022-09-28 17:53:32 -04:00
|
|
|
def create(data=None, *a) -> object:
|
2022-09-26 22:47:38 -04:00
|
|
|
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()
|
|
|
|
|