在Django中为单元测试创​​建测试数据库时,Permission.objects.get方法不起作用

问题描述

我编写了用于创建组的Django信号,并为不同用户角色的这些组分配了权限,但是当我运行测试用例时,却遇到了创建测试数据库的权限错误

signal.py

from django.contrib.auth.models import Permission,Group

def create_group():
    permission = Permission.objects.get(codename=codename,contant_type=contant_type)

当我运行迁移时,这对我来说很好用,但是当我尝试运行测试用例时,在创建测试数据库时会出错。

django.contrib.auth.models.DoesNotExist: Permission matching query does not exist.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)