Matthew Karas
05/20/2022, 3:02 PMZach
05/20/2022, 3:37 PMjamie
05/20/2022, 3:44 PM@resource
def mock_db_resource():
return MockDBResource()
class MockDBResource:
def __init__(self):
self.db = {}
def add_item(self, item):
self.db[item.name] = item
....
where your MockDBResource implements the same methods as your normal db resourceMatthew Karas
05/20/2022, 3:55 PMZach
05/20/2022, 3:59 PM@resource
def mock_db_resource():
mock_db_resource = MagicMock()
mock_db_resource.query.return_value = [{'a': 1, 'b': 2}]
return mock_db_resource
then you just use the mock_db_resource in your tests when testing the op / jobMatthew Karas
05/20/2022, 4:09 PM