Skip to content

Instantly share code, notes, and snippets.

@quamilek
Created March 15, 2016 10:10
Show Gist options
  • Save quamilek/2d210c13078e791ded07 to your computer and use it in GitHub Desktop.
Save quamilek/2d210c13078e791ded07 to your computer and use it in GitHub Desktop.
Assert messages django
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