def test_create(self):
     session_data = {}
     container = controllers.FlashMessagesContainer(session_data)
     assert len(container) == 0
     assert repr(
         container
     ) == '<watson.framework.controllers.FlashMessagesContainer messages:0>'
 def test_add_message_write_storage(self):
     session = sessions.File(id=1234)
     session.destroy()
     container = controllers.FlashMessagesContainer(session)
     assert len(session['flash_messages']) == 0
     container.add('Test')
     assert len(session['flash_messages']) == 1
     container.clear()
     assert len(session['flash_messages']) == 0
示例#3
0
def flash_messages(context):
    """Retrieves the flash messages from the controller.

    Example:

    .. code-block:: python

        {{ flash_messages() }}
    """
    app_context = context['context']
    if 'flash_messages' not in app_context:
        if 'request' in app_context and app_context['request'].session:
            app_context['flash_messages'] = controllers.FlashMessagesContainer(
                app_context['request'].session)
        else:
            app_context['flash_messages'] = {}
    return context['context']['flash_messages']
 def test_set_existing_container(self):
     existing_container = controllers.FlashMessagesContainer({})
     existing_container.add('Test')
     session_data = {'flash_messages': existing_container}
     new_container = controllers.FlashMessagesContainer(session_data)
     assert len(new_container) == 1
 def test_add_messages(self):
     session_data = {}
     container = controllers.FlashMessagesContainer(session_data)
     container.add_messages(['testing'])
     assert len(container) == 1
 def test_add_same_message_to_container(self):
     container = controllers.FlashMessagesContainer({})
     container.add('Test')
     container.add('Test')
     assert len(container) == 1