ó
Ý*µPc           @   s
  d  d l  m  Z  d  d l m Z d  d l m Z d  d l m Z d  d l m Z m	 Z	 d  d l
 m Z d  d l m Z d  d l m Z e d	 e f d
 „  ƒ  Yƒ Z d e f d „  ƒ  YZ e d e f d „  ƒ  Yƒ Z d e f d „  ƒ  YZ e d e f d „  ƒ  Yƒ Z d S(   iÿÿÿÿ(   t   datetime(   t   settings(   t   authenticate(   t   RemoteUserBackend(   t   Usert   AnonymousUser(   t   skipIfCustomUser(   t   TestCase(   t   timezonet   RemoteUserTestc           B   se   e  Z d  Z d Z d Z d Z d Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z RS(   s   django.contrib.auth.tests.urlss3   django.contrib.auth.middleware.RemoteUserMiddlewares.   django.contrib.auth.backends.RemoteUserBackendt	   knownusert
   knownuser2c         C   sF   t  j |  _ t  j |  _ t  j |  j f 7_ t  j |  j f 7_ d  S(   N(   R   t   MIDDLEWARE_CLASSESt   curr_middlewaret   AUTHENTICATION_BACKENDSt	   curr_autht
   middlewaret   backend(   t   self(    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   setUp   s    c         C   sî   t  j j ƒ  } |  j j d ƒ } |  j | j d j ƒ  ƒ |  j t  j j ƒ  | ƒ |  j j d d d ƒ} |  j | j d j ƒ  ƒ |  j t  j j ƒ  | ƒ |  j j d d d ƒ} |  j | j d j ƒ  ƒ |  j t  j j ƒ  | ƒ d S(   sq   
        Tests requests where no remote user is specified and insures that no
        users get created.
        s   /remote_user/t   usert   REMOTE_USERt    N(
   R   t   objectst   countt   clientt   gett
   assertTruet   contextt   is_anonymoust   assertEqualt   None(   R   t	   num_userst   response(    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   test_no_remote_user   s    c         C   sª   t  j j ƒ  } |  j j d d d ƒ} |  j | j d j d ƒ |  j t  j j ƒ  | d ƒ t  j j d d ƒ |  j j d d d ƒ} |  j t  j j ƒ  | d ƒ d S(   sj   
        Tests the case where the username passed in the header does not exist
        as a User.
        s   /remote_user/R   t   newuserR   i   t   usernameN(   R   R   R   R   R   R   R   R$   (   R   R    R!   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   test_unknown_user0   s    c         C   sÕ   t  j j d d ƒ t  j j d d ƒ t  j j ƒ  } |  j j d d |  j ƒ} |  j | j d j	 d ƒ |  j t  j j ƒ  | ƒ |  j j d d |  j
 ƒ} |  j | j d j	 d ƒ |  j t  j j ƒ  | ƒ d S(   sY   
        Tests the case where the username passed in the header is a valid User.
        R$   R
   R   s   /remote_user/R   R   N(   R   R   t   createR   R   R   t
   known_userR   R   R$   t   known_user2(   R   R    R!   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   test_known_user?   s    c         C   sñ   t  j j d d ƒ } t d d d ƒ } t j rH | j d t j ƒ } n  | | _	 | j
 ƒ  |  j j d d |  j ƒ} |  j | | j d j	 ƒ t  j j d d ƒ } | | _	 | j
 ƒ  |  j j d d |  j ƒ} |  j | | j d j	 ƒ d	 S(
   s    
        Tests that a user's last_login is set the first time they make a
        request but not updated in subsequent requests with the same session.
        R$   R
   iÐ  i   t   tzinfos   /remote_user/R   R   N(   R   R   R&   R    R   t   USE_TZt   replaceR   t   utct
   last_logint   saveR   R   R'   t   assertNotEqualR   R   (   R   R   t   default_loginR!   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   test_last_loginO   s    		
	
c         C   sì   t  j j d d ƒ |  j j d d |  j ƒ} |  j | j d j d ƒ |  j j d ƒ } |  j | j d j	 ƒ  t
 ƒ t  j j d d d d ƒ |  j j d d d d ƒ t d d d d ƒ |  j j d ƒ } |  j | j d j d ƒ d	 S(
   s™   
        Tests that a logged in user is logged out automatically when
        the REMOTE_USER header disappears during the same browser session.
        R$   R
   s   /remote_user/R   R   t	   modelusert   passwordt   fooN(   R   R   R&   R   R   R'   R   R   R$   R   t   Truet   create_usert   loginR   (   R   R!   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   test_header_disappearse   s    c         C   s   |  j  t _ |  j t _ d S(   s0   Restores settings to avoid breaking other tests.N(   R   R   R   R   R   (   R   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   tearDowny   s    (   t   __name__t
   __module__t   urlsR   R   R'   R(   R   R"   R%   R)   R2   R9   R:   (    (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyR	      s   						t   RemoteUserNoCreateBackendc           B   s   e  Z d  Z e Z RS(   s*   Backend that doesn't create unknown users.(   R;   R<   t   __doc__t   Falset   create_unknown_user(    (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyR>      s   t   RemoteUserNoCreateTestc           B   s   e  Z d  Z d Z d „  Z RS(   s   
    Contains the same tests as RemoteUserTest, but using a custom auth backend
    class that doesn't create unknown users.
    s?   django.contrib.auth.tests.remote_user.RemoteUserNoCreateBackendc         C   s^   t  j j ƒ  } |  j j d d d ƒ} |  j | j d j ƒ  ƒ |  j t  j j ƒ  | ƒ d  S(   Ns   /remote_user/R   R#   R   (	   R   R   R   R   R   R   R   R   R   (   R   R    R!   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyR%   Ž   s    (   R;   R<   R?   R   R%   (    (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyRB   „   s   t   CustomRemoteUserBackendc           B   s    e  Z d  Z d „  Z d „  Z RS(   s;   
    Backend that overrides RemoteUserBackend methods.
    c         C   s   | j  d ƒ d S(   s8   
        Grabs username before the @ character.
        t   @i    (   t   split(   R   R$   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   clean_usernameš   s    c         C   s   d | _  | j ƒ  | S(   s,   
        Sets user's email address.
        s   user@example.com(   t   emailR/   (   R   R   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   configure_user    s    	
(   R;   R<   R?   RF   RH   (    (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyRC   •   s   	t   RemoteUserCustomTestc           B   s2   e  Z d  Z d Z d Z d Z d „  Z d „  Z RS(   su   
    Tests a custom RemoteUserBackend subclass that overrides the clean_username
    and configure_user methods.
    s=   django.contrib.auth.tests.remote_user.CustomRemoteUserBackends   knownuser@example.coms   knownuser2@example.comc         C   s[   t  t |  ƒ j ƒ  |  j t j j d d ƒ j d ƒ |  j t j j d d ƒ j d ƒ d S(   s˜   
        The strings passed in REMOTE_USER should be cleaned and the known users
        should not have been configured with an email address.
        R$   R
   R   R   N(   t   superRI   R)   R   R   R   R   RG   (   R   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyR)   ·   s    "c         C   s?   t  t |  ƒ j ƒ  t j j d d ƒ } |  j | j d ƒ d S(   sV   
        The unknown user created should be configured with an email address.
        R$   R#   s   user@example.comN(   RJ   RI   R%   R   R   R   R   RG   (   R   R#   (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyR%   À   s    (   R;   R<   R?   R   R'   R(   R)   R%   (    (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyRI   ©   s   		N(   R    t   django.confR   t   django.contrib.authR   t   django.contrib.auth.backendsR   t   django.contrib.auth.modelsR   R   t   django.contrib.auth.tests.utilsR   t   django.testR   t   django.utilsR   R	   R>   RB   RC   RI   (    (    (    s>   ../Django//lib/python/django/contrib/auth/tests/remote_user.pyt   <module>   s   r