tests.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:django-readonly-field 作者: peopledoc 项目源码 文件源码
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'])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号