Created
March 15, 2016 10:10
-
-
Save quamilek/2d210c13078e791ded07 to your computer and use it in GitHub Desktop.
Assert messages django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.test import TestCase | |
class WithMessagesTestCase(TestCase): | |
def assertTextInMessage(self, response, text): | |
messages = response.context['messages'] | |
for message in messages: | |
if text in message.message: | |
return | |
raise AssertionError('Text: `{}` not found in messages'.format(text)) | |
def assertTextNotInMessage(self, response, text): | |
messages = response.context['messages'] | |
for message in messages: | |
if text not in message.message: | |
return | |
raise AssertionError('Text: `{}` found in messages'.format(text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment