def assertSQLQueries(self, model=None, check_other_fields=True):
"""
Asserts that the SQL from the queries don't mention
the readonly field. SELECTS are authorized, though.
model allow you to specify the model for which readonly
fields will be checked
"""
model = model or Car
readonly_fields = model.ReadonlyMeta.readonly
with CaptureQueriesContext(connection=connection) as capture:
yield capture
unchecked_queries = frozenset("SELECT SAVEPOINT RELEASE".split())
for query in self._filter_queries(capture, exclude=unchecked_queries):
for field in readonly_fields:
self.assertNotIn(field, query['sql'])
if check_other_fields:
fields = {field.name
for field in model._meta.fields
if not field.primary_key}
read_write_fields = fields - frozenset(readonly_fields)
for field in read_write_fields:
self.assertIn(field, query['sql'])
评论列表
文章目录