Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django测试-未创建模型实例_Python_Django_Django Testing_Django Tests_Model Mommy - Fatal编程技术网

Python django测试-未创建模型实例

Python django测试-未创建模型实例,python,django,django-testing,django-tests,model-mommy,Python,Django,Django Testing,Django Tests,Model Mommy,在使用Django和DRF的测试类中,我遇到了为特定模型创建夹具的问题。我正在使用,但即使仅为该模型使用Django ORM创建单个实例也不起作用: 来自rest\u framework.test导入APIRequestFactory,APITestCase 从模型ê妈咪导入妈咪 从api.v1导入视图 从company.models.models导入CompanyUserProfile、ManagerRelation、DynamicRelation User=get\u User\u mode

在使用Django和DRF的测试类中,我遇到了为特定模型创建夹具的问题。我正在使用,但即使仅为该模型使用Django ORM创建单个实例也不起作用:

来自rest\u framework.test导入APIRequestFactory,APITestCase
从模型ê妈咪导入妈咪
从api.v1导入视图
从company.models.models导入CompanyUserProfile、ManagerRelation、DynamicRelation
User=get\u User\u model()
类APIViewsTestCase(APITestCase):
@类方法
def设置测试数据(cls):
监管机构id=“1337”
emp_group_id=“119”
prd_范围_id=“1334”
user=mommy.make(用户)
setattr(cls,'用户',用户)
company\u user\u profile\u 1=mommy.make(CompanyUserProfile)
请求者=make.make(
CompanyUserProfile,是否为_manager=True,
监管id=监管id,emp集团id=emp集团id,
prd\U范围\U id=prd\U范围\U id,用户=用户
)
cls.user=user
经理关系=妈妈(
ManagerRelation,manager\u id=requestor.id,mgr\u type=“Direct mgr”,\u quantity=5
)
动态关系=make.make(
DynamicRelation,target_id=requestor.id,_quantity=5
)
def设置(自身)->无:
super().setUp()
self.client.force\u身份验证(user=self.user)
def测试员工视图(自我):
CompanyUserProfile.objects.create(
guid=uuid.uuid4(),
csod_user_id='idcbijnccdocwocd',csod_username='djchbdcjnwdskjcn',
id=3333
)
打印('cup count:',CompanyUserProfile.objects.count())
打印('user count:',user.objects.count())
打印('m_rels count:',ManagerRelation.objects.count())
打印('d_rels count:',DynamicRelation.objects.count())
rsp=self.client.get('/api/v1/employees/'))
self.assertEqual(rsp.status\u代码,HTTPStatus.OK)
但是,不创建
CompanyUserProfile
记录,使用
make
CompanyUserProfile.objects.create

-- test run output
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
cup count: 0
user count: 1
m_rels count: 5
d_rels count: 5
Destroying test database for alias 'default'...
CompanyUserProfile
继承自
AbstractCornerstoneUserProfile
(抽象基础模型),这是该模型与其他模型的主要区别

你知道这其中的根本原因吗?

更新: 解决->100%我的错误,
CompanyUserProfile
的自定义
ModelManager
排除了在
CompanyUserProfile.objects.count()上创建的对象
更新:
已解决->100%我的错误,
CompanyUserProfile
的自定义
ModelManager
排除了在
CompanyUserProfile上创建的对象。objects.count()

不要将已解决添加到问题的标题,以表明您已经有了解决方案,相反,我们邀请您发布答案。不要在问题的标题中添加“已解决”以表明您已经有了解决方案,我们邀请您发布答案