ó
A()Qc           @  sŠ  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 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 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  e d e f d „  ƒ  Yƒ Z! e d e f d „  ƒ  Yƒ Z" e d e f d „  ƒ  Yƒ Z# d e f d „  ƒ  YZ$ d e f d „  ƒ  YZ% d S(   iÿÿÿÿ(   t   unicode_literals(   t   date(   t   modelst
   management(   t   create_permissions(   t   changepassword(   t   User(   t
   CustomUser(   t   skipIfCustomUser(   t   call_command(   t   CommandError(   t   get_validation_errors(   t   get_app(   t   TestCase(   t   override_settings(   t   six(   t   StringIOt   GetDefaultUsernameTestCasec           B  s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C  s   t  j |  _ d  S(   N(   R   t   get_system_usernamet   old_get_system_username(   t   self(    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   setUp   s    c         C  s   |  j  t _ d  S(   N(   R   R   R   (   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   tearDown   s    c         C  s   |  j  t j ƒ  t j ƒ d  S(   N(   t   assertIsInstanceR   R   R   t	   text_type(   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_actual_implementation   s    c         C  s&   d „  t  _ |  j t  j ƒ  d ƒ d  S(   Nc           S  s   d S(   Nu   joe(    (    (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   <lambda>!   s    u   joe(   R   R   t   assertEqualt   get_default_username(   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_simple    s    c         C  sX   t  j j j d d ƒ d „  t _ |  j t j ƒ  d ƒ |  j t j d t ƒ d ƒ d  S(   Nt   usernameu   joec           S  s   d S(   Nu   joe(    (    (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR   &   s    u    t   check_db(	   R   R   t   objectst   createR   R   R   R   t   False(   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_existing$   s
    c         C  s&   d „  t  _ |  j t  j ƒ  d ƒ d  S(   Nc           S  s   d S(   Nu   JÃºlia(    (    (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR   -   s    u   julia(   R   R   R   R   (   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt	   test_i18n+   s    (   t   __name__t
   __module__R   R   R   R   R#   R$   (    (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR      s   					t'   ChangepasswordManagementCommandTestCasec           B  s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C  s=   t  j j j d d d d ƒ |  _ t ƒ  |  _ t ƒ  |  _ d  S(   NR   u   joet   passwordu   qwerty(   R   R   R    t   create_usert   userR   t   stdoutt   stderr(   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR   4   s    !c         C  s   |  j  j ƒ  |  j j ƒ  d  S(   N(   R+   t   closeR,   (   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR   9   s    c         C  s˜   |  j  |  j j d ƒ ƒ t j ƒ  } d „  | _ | j d d |  j ƒ|  j j ƒ  j	 ƒ  } |  j
 | d ƒ |  j  t j j j d d ƒ j d ƒ ƒ d S(	   uL   Executing the changepassword management command should change joe's passwordu   qwertyc          W  s   d S(   Nu
   not qwerty(    (   t   args(    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR   A   s    u   joeR+   uM   Changing password for user 'joe'
Password changed successfully for user 'joe'R   u
   not qwertyN(   t
   assertTrueR*   t   check_passwordR   t   Commandt	   _get_passt   executeR+   t   getvaluet   stripR   R   R   R    t   get(   R   t   commandt   command_output(    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt6   test_that_changepassword_command_changes_joes_password=   s    c      
   C  sQ   t  j ƒ  } d „  | _ |  j t ƒ $ | j d d |  j d |  j ƒWd QXd S(   u}   
        A CommandError should be thrown by handle() if the user enters in
        mismatched passwords three times.
        c          W  s
   |  p	 d S(   Nu   foo(    (   R.   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR   O   s    u   joeR+   R,   N(   R   R1   R2   t   assertRaisesR
   R3   R+   R,   (   R   R7   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_that_max_tries_exits_1I   s    (   R%   R&   R   R   R9   R;   (    (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR'   1   s   			t(   CreatesuperuserManagementCommandTestCasec           B  sS   e  Z d  „  Z d „  Z d „  Z e d d ƒ d „  ƒ Z e d d ƒ d „  ƒ Z RS(   c      
   C  sŒ   t  ƒ  } t d d t d d d d d | ƒ| j ƒ  j ƒ  } |  j | d ƒ t j j d d ƒ } |  j | j	 d ƒ |  j
 | j ƒ  ƒ d	 S(
   u=   Check the operation of the createsuperuser management commandu   createsuperusert   interactiveR   u   joet   emailu   joe@somewhere.orgR+   u   Superuser created successfully.N(   R   R	   R"   R4   R5   R   R   R    R6   R>   t   assertFalset   has_usable_password(   R   t   new_ioR8   t   u(    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_createsuperuserX   s    		c         C  s’   t  ƒ  } t d d t d d d d d d d	 | ƒ| j ƒ  j ƒ  } |  j | d
 ƒ t j j d d ƒ } |  j | j	 d ƒ |  j
 | j ƒ  ƒ d  S(   Nu   createsuperuserR=   R   u   joe2R>   u   joe2@somewhere.orgt	   verbosityi    R+   u    (   R   R	   R"   R4   R5   R   R   R    R6   R>   R?   R@   (   R   RA   R8   RB   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_verbosity_zeroj   s    		c      
   C  sj   t  ƒ  } t d d t d d d d d | ƒt j j d d ƒ } |  j | j d ƒ |  j | j	 ƒ  ƒ d  S(   Nu   createsuperuserR=   R   u   joe+admin@somewhere.orgR>   u   joe@somewhere.orgR+   (
   R   R	   R"   R   t   _default_managerR6   R   R>   R?   R@   (   R   RA   RB   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_email_in_usernamez   s    		t   AUTH_USER_MODELu   auth.CustomUserc         C  sž   t  ƒ  } t d d t d d d d d | d t ƒ| j ƒ  j ƒ  } |  j | d	 ƒ t j j	 d d ƒ } |  j | j
 t d
 d d ƒ ƒ |  j | j ƒ  ƒ d S(   u=   A superuser can be created when a custom User model is in useu   createsuperuserR=   R>   u   joe@somewhere.orgt   date_of_birthu
   1976-04-01R+   t   skip_validationu   Superuser created successfully.i¸  i   i   N(   R   R	   R"   t   TrueR4   R5   R   R   RF   R6   RI   R   R?   R@   (   R   RA   R8   RB   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_swappable_user†   s    		c         C  sd   t  ƒ  } |  j t ƒ - t d d t d d d | d | d t ƒWd QX|  j t j j	 ƒ  d	 ƒ d S(
   uH   A Custom superuser won't be created when a required field isn't providedu   createsuperuserR=   R   u   joe@somewhere.orgR+   R,   RJ   Ni    (
   R   R:   R
   R	   R"   RK   R   R   RF   t   count(   R   RA   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt*   test_swappable_user_missing_required_fieldœ   s    		(   R%   R&   RC   RE   RG   R   RL   RN   (    (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR<   U   s
   			t!   CustomUserModelValidationTestCasec           B  s8   e  Z e d  d ƒ d „  ƒ Z e d  d ƒ d „  ƒ Z RS(   RH   u    auth.CustomUserBadRequiredFieldsc         C  s6   t  ƒ  } t | t d ƒ ƒ |  j d | j ƒ  ƒ d S(   u4   USERNAME_FIELD should not appear in REQUIRED_FIELDS.u   authuj   The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.N(   R   R   R   t   assertInR4   (   R   RA   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt$   test_username_not_in_required_fields°   s    	u    auth.CustomUserNonUniqueUsernamec         C  s6   t  ƒ  } t | t d ƒ ƒ |  j d | j ƒ  ƒ d S(   uB   A non-unique USERNAME_FIELD should raise a model validation error.u   authuK   The USERNAME_FIELD must be unique. Add unique=True to the field parameters.N(   R   R   R   RP   R4   (   R   RA   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_username_non_unique·   s    	(   R%   R&   R   RQ   RR   (    (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyRO   ¯   s   t   PermissionDuplicationTestCasec           B  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C  s   t  j j j |  _ d  S(   N(   R   t
   Permissiont   _metat   permissionst   _original_permissions(   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR   Á   s    c         C  s   |  j  t j j _ d  S(   N(   RW   R   RT   RU   RV   (   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyR   Ä   s    c      	   C  sš   d g t  j j _ t j |  t d t t  g  d d ƒd d d g t  j j _ t j |  t d t t  g  d d ƒd d g t  j j _ t t  g  d d ƒd S(   ur   
        Test that we show proper error message if we are trying to create
        duplicate permissions.
        u   change_permissionu   Can edit permission (duplicate)uj   The permission codename 'change_permission' clashes with a builtin permission for model 'auth.Permission'.RD   i    u   my_custom_permissionu   Some permissionu	   other_oneu   Some other permissionu.   Some permission with duplicate permission codeuY   The permission codename 'my_custom_permission' is duplicated for model 'auth.Permission'.N(   u   change_permissionu   Can edit permission (duplicate)(   u   my_custom_permissionu   Some permission(   u	   other_oneu   Some other permission(   u   my_custom_permissionu.   Some permission with duplicate permission code(   u   my_custom_permissionu   Some permission(   u	   other_oneu   Some other permission(   R   RT   RU   RV   R   t   assertRaisesRegexR
   R   (   R   (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   test_duplicated_permissionsÇ   s    (   R%   R&   R   R   RY   (    (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyRS   ¿   s   		N(&   t
   __future__R    t   datetimeR   t   django.contrib.authR   R   t   django.contrib.auth.managementR   t'   django.contrib.auth.management.commandsR   t   django.contrib.auth.modelsR   t   django.contrib.auth.testsR   t   django.contrib.auth.tests.utilsR   t   django.core.managementR	   t   django.core.management.baseR
   t!   django.core.management.validationR   t   django.db.models.loadingR   t   django.testR   t   django.test.utilsR   t   django.utilsR   t   django.utils.sixR   R   R'   R<   RO   RS   (    (    (    s=   ../Django//lib/python/django/contrib/auth/tests/management.pyt   <module>   s.   #Y