0

I am working for a web-app using django-1.6 where there will be application(s) coming in and going through various stages of scrutiny. On satisfying criteria(s), they get approved and promoted to the next stage or get deferred. I was testing the approval transition. And landed up in situation where I need to assert if approvable application(s) have their status changed to pending for the next stage. So, this is how I do it right now:

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

what I am looking for is something like

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

which would assure that all the objects in the list stage1_approved_mentor_applications have their status as 'stage2.pending'. One way would be to pass it to a function taking a list and returning True on all status being 'stage2.pending' and False if otherwise. This function will be called in assertTrue. Wondering if there's already a workaround for this that would save me from reinventing the wheel.

Can anyone help me with that? Thanks in advance.

3 Answers 3

4

what about this:

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

so you know what status is different

Sign up to request clarification or add additional context in comments.

Comments

2

How about this?

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

Comments

0

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

1 Comment

It Works! Boklucius..also thanks for the answer freakish and kharandziuk..Isn't there some assert that iterates internally...I mean I want to do away with writing the iteration myself...some inbuilt assert.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.