'Both central and distributed servers use the Django messaging system.
This code will verify that a message with the given type contains the specified text.'

def browser_check_django_message(self, message_type=None, contains=None, exact=None, num_messages=1):

    if (num_messages > 0):
        messages = WebDriverWait(self.browser, 15).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'alert')))
    else:
        messages = []
    if isinstance(contains, str):
        messages = [message for message in messages if (contains in message.text)]
    if (num_messages is not None):
        msg = ("Make    sure    there    are    %d    message(s),    type='%s'." % (num_messages, (message_type if message_type else '(any)')))
        self.assertEqual(num_messages, len(messages), msg)
    for (i, message) in enumerate(messages):
        if (type(contains) == list):
            contain = contains[i]
        else:
            contain = contains
        if (type(exact) == list):
            exac = exact[i]
        else:
            exac = exact
        if (contain is not None):
            self.assertIn(contain, message.text, ("Make    sure    message    contains    '%s'" % contain))
        if (exac is not None):
            self.assertEqual(exac, message.text, ("Make    sure    message    =    '%s'" % exac))
