2014-03-05 44 views
0

我正在使用django-1.6的web应用程序工作,其中将有应用程序进入并经历各个审查阶段。在满足标准的情况下,他们得到批准并晋升到下一阶段或延期。我正在测试审批过渡。如果可以批准的应用程序的状态已更改为下一阶段的待定状态,则需要声明该情况。所以,这就是我现在就做:Python:断言列表中的所有对象都具有特定的属性值

self.assertEqual('stage2.pending', stage1_approved_mentor_applications[0].status) 

我所寻找的是类似

self.assertEqual('stage2.pending', stage1_approved_mentor_applications.status) 

这将确保在列表stage1_approved_mentor_applications所有的对象都具有自己的状态为“阶段2 .pending”。一种方法是将它传递给一个获取列表的函数,并在所有状态为'stage2.pending'时返回True,否则返回False。这个函数将在assertTrue中调用。想知道是否已经有了解决方法,可以帮助我避免重蹈覆辙。

任何人都可以帮助我吗?提前致谢。

回答

4

你看这个:

for s in stage1_approved_mentor_applications: 
    self.assertEqual('stage2.pending', s.status) 

让你知道什么地位不同

0

self.assertTrue( all([x is 'stage2.pending' for x in stage1_approved_mentor_applications] ))

+0

它的作品! Boklucius ..也非常感谢你的回答怪异和kharandziuk ..不存在一些内部迭代的断言...我的意思是我想取消自己写的迭代...一些内置断言。 – quickbrownfox

2

这个怎么样?

self.assertFalse(
    any(obj.status != 'stage2.pending' for obj in stage1_approved_mentor_applications) 
) 
相关问题