def filtered_schema_editor(*filters: List[str]):
"""Gets a schema editor, but filters executed SQL
statements based on the specified text filters.
Arguments:
filters:
List of strings to filter SQL
statements on.
"""
with connection.schema_editor() as schema_editor:
wrapper_for = schema_editor.execute
with mock.patch.object(BaseDatabaseSchemaEditor, 'execute', wraps=wrapper_for) as execute:
filter_results = {}
yield schema_editor, filter_results
for filter_text in filters:
filter_results[filter_text] = [
call for call in execute.mock_calls
if filter_text in str(call)
]
评论列表
文章目录