
O'^c           @   s   d  d l  Z  d  d l 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
 e	 f d     YZ e  j e e d e d S(   iN(   t   datetime(   t   make_password(   t   User(   t   timezone(   t   AutoFixture(   t
   generatorsi   (   t	   get_fieldt   UserFixturec           B   sN   e  Z d  Z d e f d     YZ e Z d   Z d   Z d   Z	 d   Z
 RS(   s  
    :class:`UserFixture` is automatically used by default to create new
    ``User`` instances. It uses the following values to assure that you can
    use the generated instances without any modification:

    * ``username`` only contains chars that are allowed by django's auth forms.
    * ``email`` is unique.
    * ``first_name`` and ``last_name`` are single, random words of the lorem
      ipsum text.
    * ``is_staff`` and ``is_superuser`` are always ``False``.
    * ``is_active`` is always ``True``.
    * ``date_joined`` and ``last_login`` are always in the past and it is
      assured that ``date_joined`` will be lower than ``last_login``.
    t   Valuesc           B   s   e  Z e j d  d d e j e j d  Z e j d  Z	 e j d  Z
 e d    Z e Z e Z e Z e j d e j    Z e j d e j    Z RS(   t
   max_lengthi   t   charst   _i   c           C   s
   t  d   S(   N(   R   t   None(    (    (    s:   /tmp/pip-unpacked-wheel-K50F1D/autofixture/autofixtures.pyt   <lambda>"   t    t   max_date(   t   __name__t
   __module__R   t   StringGeneratort   stringt   ascii_letterst   digitst   usernamet   LoremWordGeneratort
   first_namet	   last_namet   staticmethodt   passwordt   Truet	   is_activet   Falset   is_stafft   is_superusert   DateTimeGeneratorR   t   nowt   date_joinedt
   last_login(    (    (    s:   /tmp/pip-unpacked-wheel-K50F1D/autofixture/autofixtures.pyR      s   	c         O   sl   | j  d d  |  _ | j  d d  |  _ t t |   j | |   |  j rh t j |  j  |  j	 d <n  d S(   s:  
        By default the password is set to an unusable value, this makes it
        impossible to login with the generated users. If you want to use for
        example ``autofixture.create_one('auth.User')`` in your unittests to have
        a user instance which you can use to login with the testing client you
        can provide a ``username`` and a ``password`` argument. Then you can do
        something like::

            autofixture.create_one('auth.User', username='foo', password='bar`)
            self.client.login(username='foo', password='bar')
        R   R   N(
   t   popR   R   R   t   superR   t   __init__R   t   StaticGeneratort   field_values(   t   selft   argst   kwargs(    (    s:   /tmp/pip-unpacked-wheel-K50F1D/autofixture/autofixtures.pyR'   -   s    	c         C   s@   t  j j d | j  j   r< t j t | d  f   n  d  S(   Nt   email(   R   t   objectst   filterR-   t   existst   autofixturet   InvalidConstraintR   (   R*   t   modelt   instance(    (    s:   /tmp/pip-unpacked-wheel-K50F1D/autofixture/autofixtures.pyt   unique_email@   s    c         C   s   |  j  |  j  d  S(   N(   t   add_constraintR5   (   R*   (    (    s:   /tmp/pip-unpacked-wheel-K50F1D/autofixture/autofixtures.pyt   prepare_classD   s    c         C   sl   t  } | j | j k  r- | j | _ t } n  |  j rO | j |  j  t } n  | rh | rh | j   n  | S(   N(   R   R$   R#   R   R   t   set_passwordt   save(   R*   R4   t   committ   changed(    (    s:   /tmp/pip-unpacked-wheel-K50F1D/autofixture/autofixtures.pyt   post_process_instanceG   s    			(   R   R   t   __doc__t   objectR   R   t
   follow_m2mR'   R5   R7   R<   (    (    (    s:   /tmp/pip-unpacked-wheel-K50F1D/autofixture/autofixtures.pyR      s   			t   fail_silently(   R1   R   R    t   django.contrib.auth.hashersR   t   django.contrib.auth.modelsR   t   django.utilsR   R   R   t   compatR   R   t   registerR   (    (    (    s:   /tmp/pip-unpacked-wheel-K50F1D/autofixture/autofixtures.pyt   <module>   s   H