#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyramid.events import BeforeRender, ContextFound, NewRequest, NewResponse

from .csrf import validate_against_csrf
from .hsts import hsts_redirect_to_https, set_hsts_header
from .i18n import add_underscore_translation
from .nav import add_is_active_function
from .seen import set_seen_cookie, get_has_been_seen
from .session import get_session_id
from .utils import *

def includeme(config):
    """Allow developers to use ``config.include('pyramid_weblayer')`` to register
      the ``add_underscore_translation`` subscriber::
      
      setUp::
      
          >>> from mock import Mock
          >>> mock_config = Mock()
      
      test::
      
          >>> includeme(mock_config)
          >>> expected = (validate_against_csrf, NewRequest)
          >>> mock_config.add_subscriber.call_args_list[0][0] == expected 
          True
          >>> expected = (add_underscore_translation, BeforeRender)
          >>> mock_config.add_subscriber.call_args_list[1][0] == expected
          True
      
    """
    
    # CSRF validation.
    config.add_subscriber(validate_against_csrf, ContextFound)
    
    # Provide `_` template namespace.
    config.add_subscriber(add_underscore_translation, BeforeRender)
    config.add_subscriber(add_is_active_function, BeforeRender)
    
    # Optionally force https://
    config.add_subscriber(hsts_redirect_to_https, NewRequest)
    config.add_subscriber(set_hsts_header, NewResponse)
    
    # Has been seen flag.
    config.add_subscriber(set_seen_cookie, NewResponse)
    config.set_request_property(get_has_been_seen, 'has_been_seen', reify=True)
    
    # Session id.
    config.set_request_property(get_session_id, 'session_id', reify=True)
    
    # Favicon and robots.txt.
    config.add_route('favicon_ico', 'favicon.ico')
    config.add_route('robots_txt', 'robots.txt')
    config.scan('pyramid_weblayer')


@@ -590,12 +590,12 @@
     
-setU
+Setu
 p::%0A
@@ -682,373 +682,1496 @@
     
-%0A      test::%0A      %0A          %3E%3E%3E includeme(mock_config)%0A          %3E%3E%3E expected = (validate_against_csrf, NewRequest)%0A          %3E%3E%3E mock_config.add_subscriber.call_args_list%5B0%5D%5B0%5D == expected %0A          True%0A          %3E%3E%3E expected = (add_underscore_translation, BeforeRender)%0A          %3E%3E%3E mock_config.add_subscriber.call_args_list%5B1%5D%5B0%5D == expected%0A          True
+    %3E%3E%3E includeme(mock_config)%0A      %0A      CSRF validation::%0A      %0A          %3E%3E%3E mock_config.add_subscriber.assert_any_call(validate_against_csrf, %0A          ...         ContextFound)%0A      %0A      Provide %60_%60 template namespace::%0A      %0A          %3E%3E%3E mock_config.add_subscriber.assert_any_call(add_underscore_translation,%0A          ...         BeforeRender)%0A          %3E%3E%3E mock_config.add_subscriber.assert_any_call(add_is_active_function,%0A          ...         BeforeRender)%0A      %0A      Optionally force https::%0A      %0A          %3E%3E%3E mock_config.add_subscriber.assert_any_call(hsts_redirect_to_https, %0A          ...         NewRequest)%0A          %3E%3E%3E mock_config.add_subscriber.assert_any_call(set_hsts_header, %0A          ...         NewResponse)%0A      %0A      Has been seen flag.::%0A      %0A          %3E%3E%3E mock_config.add_subscriber.assert_any_call(set_seen_cookie, %0A          ...         NewResponse)%0A          %3E%3E%3E mock_config.set_request_property.assert_any_call(get_has_been_seen,%0A          ...         'has_been_seen', reify=True)%0A      %0A      Session ID::%0A      %0A          %3E%3E%3E mock_config.set_request_property.assert_any_call(get_session_id, %0A          ...         'session_id', reify=True)%0A      %0A      Prereq routes::%0A      %0A          %3E%3E%3E mock_config.add_route.assert_any_call('favicon_ico', 'favicon.ico')%0A          %3E%3E%3E mock_config.add_route.assert_any_call('robots_txt', 'robots.txt')%0A      %0A      Scan::%0A      %0A          %3E%3E%3E mock_config.scan.assert_called_with('pyramid_weblayer')
 %0A   

update `includeme` doctest.