ó
O'—^c           @  sT  d  d l  m 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  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 d „ Z e d k	 rmd e j j j  j! f d „  ƒ  YZ" d e# f d „  ƒ  YZ$ d e j% j& f d „  ƒ  YZ' d e j( f d „  ƒ  YZ) n	 d „  Z) e d k	 ržd e j f d „  ƒ  YZ* n	 d „  Z* d e f d „  ƒ  YZ+ d e f d „  ƒ  YZ, d  e+ e f d! „  ƒ  YZ- d" e
 j. f d# „  ƒ  YZ/ d$ e
 j0 f d% „  ƒ  YZ1 d& e
 j2 f d' „  ƒ  YZ3 d( e
 j4 f d) „  ƒ  YZ5 d S(*   iÿÿÿÿ(   t   unicode_literalsN(   t   settings(   t   ImproperlyConfigured(   t   WSGIHandler(   t	   testcases(   t   Client(   t   RequestFactory(   t   ClientHandler(   t   six(   t   force_bytes(   t	   urlencode(   t   coreapit   requests(   t   api_settingsc         C  s   | |  _  | |  _ d  S(   N(   t   _force_auth_usert   _force_auth_token(   t   requestt   usert   token(    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   force_authenticate   s    	t
   HeaderDictc           B  s   e  Z d  „  Z RS(   c         C  s   |  j  | ƒ S(   N(   t
   getheaders(   t   selft   keyt   default(    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   get_all   s    (   t   __name__t
   __module__R   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR      s   t   MockOriginalResponsec           B  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C  s   t  | ƒ |  _ t |  _ d  S(   N(   R   t   msgt   Falset   closed(   R   t   headers(    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   __init__#   s    c         C  s   |  j  S(   N(   R   (   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   isclosed'   s    c         C  s   t  |  _ d  S(   N(   t   TrueR   (   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   close*   s    (   R   R   R!   R"   R$   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR   "   s   		t   DjangoTestAdapterc           B  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   u¤   
        A transport adapter for `requests`, that makes requests via the
        Django WSGI app, rather than making actual HTTP requests over the network.
        c         C  s   t  ƒ  |  _ t ƒ  |  _ d  S(   N(   R   t   appt   DjangoRequestFactoryt   factory(   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR!   2   s    c         C  só   | j  } | j } i  } | j d k	 r_ t | j d ƒ rO | j j ƒ  | d <q_ | j | d <n  d | j k r‚ | j d | d <n  xU | j j ƒ  D]D \ } } | j ƒ  } | d k r¼ q’ n  | | d | j	 d	 d
 ƒ <q’ W|  j
 j | | |  j S(   ub   
            Given a `requests.PreparedRequest` instance, return a WSGI environ dict.
            u   readu   datau   content-typeu   content_typeu
   CONNECTIONu   CONTENT-LENGTHu   CONTENT-TYPEu   HTTP_%su   -u   _N(   u
   CONNECTIONu   CONTENT-LENGTHu   CONTENT-TYPE(   t   methodt   urlt   bodyt   Nonet   hasattrt   readR    t   itemst   uppert   replaceR(   t   generict   environ(   R   R   R)   R*   t   kwargsR   t   value(    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   get_environ6   s    		c           sw   i  ‰  ‡  f d †  } |  j  | ƒ } |  j | | ƒ } t j d j | ƒ ƒ ˆ  d <t j j j ˆ    } |  j	 | | ƒ S(   uR   
            Make an outgoing request to the Django WSGI application.
            c           sd   |  j  d ƒ \ } } } t | ƒ ˆ  d <| ˆ  d <| ˆ  d <d ˆ  d <t ˆ  d <t | ƒ ˆ  d <d  S(	   Nu    u   statusu   reasonu   headersi   u   versionu   preload_contentu   original_response(   t	   partitiont   intR   R   (   t   wsgi_statust   wsgi_headerst   statust   _t   reason(   t
   raw_kwargs(    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   start_responseV   s    



t    u   body(
   R6   R&   t   iot   BytesIOt   joinR   t   packagest   urllib3t   HTTPResponset   build_response(   R   R   t   argsR4   R?   R3   t   wsgi_responset   raw(    (   R>   s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   sendP   s    
c         C  s   d  S(   N(    (   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR$   j   s    (   R   R   t   __doc__R!   R6   RK   R$   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR%   -   s
   			t   RequestsClientc           B  s   e  Z d  „  Z d „  Z RS(   c         O  sF   t  t |  ƒ j | | Ž  t ƒ  } |  j d | ƒ |  j d | ƒ d  S(   Nu   http://u   https://(   t   superRM   R!   R%   t   mount(   R   RH   R4   t   adapter(    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR!   n   s    	c         O  s>   d | k r t  d | ƒ ‚ n  t t |  ƒ j | | | | Ž S(   Nu   :uP   Missing "http:" or "https:". Use a fully qualified URL, eg "http://testserver%s"(   t
   ValueErrorRN   RM   R   (   R   R)   R*   RH   R4   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR   t   s    (   R   R   R!   R   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRM   m   s   	c          O  s   t  d ƒ ‚ d  S(   Nu:   requests must be installed in order to use RequestsClient.(   R   (   RH   R4   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRM   z   s    t   CoreAPIClientc           B  s    e  Z d  „  Z e d „  ƒ Z RS(   c         O  sD   t  ƒ  |  _ t j j d |  j ƒ g | d <t t |  ƒ j | | Ž  S(   Nt   sessionu
   transports(	   RM   t   _sessionR   t
   transportst   HTTPTransportRS   RN   RR   R!   (   R   RH   R4   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR!   €   s    c         C  s   |  j  S(   N(   RT   (   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRS   …   s    (   R   R   R!   t   propertyRS   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRR      s   	c          O  s   t  d ƒ ‚ d  S(   Nu8   coreapi must be installed in order to use CoreAPIClient.(   R   (   RH   R4   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRR   Š   s    t   APIRequestFactoryc           B  s¤   e  Z e j Z e j Z e d  „ Z d	 d	 d „ Z
 d	 d „ Z d	 d	 d	 d „ Z d	 d	 d	 d „ Z d	 d	 d	 d „ Z d	 d	 d	 d „ Z d	 d	 d	 d „ Z d „  Z RS(
   c         K  sP   | |  _  i  |  _ x! |  j D] } | |  j | j <q Wt t |  ƒ j |   d  S(   N(   t   enforce_csrf_checkst   renderer_classest   renderer_classes_listt   formatRN   RX   R!   (   R   RY   t   defaultst   cls(    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR!   ’   s
    		c         C  s&  | d k r d | f S| d k s: | d k s: t d ƒ ‚ | rU t | t j ƒ } nÇ | pa |  j } | |  j k s¸ t d j | d j g  |  j j	 ƒ  D] } d | d ^ q• ƒ ƒ ƒ ‚ |  j | ƒ  } | j
 | ƒ } d j | j | j ƒ } t | t j ƒ rt | j | j ƒ ƒ } n  | | f S(   uP   
        Encode the data returning a two tuple of (bytes, content_type)
        u    u1   You may not set both `format` and `content_type`.us   Invalid format '{0}'. Available formats are {1}. Set TEST_REQUEST_RENDERER_CLASSES to enable extra request formats.u   , u   'u   {0}; charset={1}N(   R,   t   AssertionErrorR	   R   t   DEFAULT_CHARSETt   default_formatRZ   R\   RC   t   keyst   rendert
   media_typet   charsett
   isinstanceR   t	   text_typet   bytest   encode(   R   t   dataR\   t   content_typet   rett   fmtt   renderer(    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   _encode_data™   s$    
	9c         K  s“   i t  | p i  d t ƒd 6} | rs d | k rs t | j d ƒ d ƒ } t j rf | j d ƒ } n  | | d <n  | j | ƒ |  j d | |  S(   Nt   dosequ   QUERY_STRINGu   ?i   u
   iso-8859-1u   GET(	   R
   R#   R	   t   splitR   t   PY3t   decodet   updateR2   (   R   t   pathRj   t   extrat   rt   query_string(    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   getÄ   s    	c         K  s4   |  j  | | | ƒ \ } } |  j d | | | |  S(   Nu   POST(   Ro   R2   (   R   Ru   Rj   R\   Rk   Rv   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   postÒ   s    c         K  s4   |  j  | | | ƒ \ } } |  j d | | | |  S(   Nu   PUT(   Ro   R2   (   R   Ru   Rj   R\   Rk   Rv   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   putÖ   s    c         K  s4   |  j  | | | ƒ \ } } |  j d | | | |  S(   Nu   PATCH(   Ro   R2   (   R   Ru   Rj   R\   Rk   Rv   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   patchÚ   s    c         K  s4   |  j  | | | ƒ \ } } |  j d | | | |  S(   Nu   DELETE(   Ro   R2   (   R   Ru   Rj   R\   Rk   Rv   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   deleteÞ   s    c         K  s4   |  j  | | | ƒ \ } } |  j d | | | |  S(   Nu   OPTIONS(   Ro   R2   (   R   Ru   Rj   R\   Rk   Rv   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   optionsâ   s    c         K  s)   t  t |  ƒ j |   } |  j | _ | S(   N(   RN   RX   R   RY   t   _dont_enforce_csrf_checks(   R   R4   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR   æ   s    N(   R   R   R   t   TEST_REQUEST_RENDERER_CLASSESR[   t   TEST_REQUEST_DEFAULT_FORMATRa   R   R!   R,   Ro   Ry   Rz   R{   R|   R}   R~   R   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRX   Ž   s   		+t   ForceAuthClientHandlerc           B  s    e  Z d  Z d „  Z d „  Z RS(   uj   
    A patched version of ClientHandler that can enforce authentication
    on the outgoing requests.
    c         O  s/   d  |  _ d  |  _ t t |  ƒ j | | Ž  d  S(   N(   R,   t   _force_usert   _force_tokenRN   R‚   R!   (   R   RH   R4   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR!   ò   s    		c         C  s,   t  | |  j |  j ƒ t t |  ƒ j | ƒ S(   N(   R   Rƒ   R„   RN   R‚   t   get_response(   R   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR…   ÷   s    (   R   R   RL   R!   R…   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR‚   ì   s   	t	   APIClientc           B  s¶   e  Z e d  „ Z d „  Z d d d „ Z d „  Z d e d „ Z d d d e d „ Z	 d d d e d „ Z
 d d d e d „ Z d d d e d „ Z d d d e d	 „ Z d
 „  Z RS(   c         K  s2   t  t |  ƒ j |   t | ƒ |  _ i  |  _ d  S(   N(   RN   R†   R!   R‚   t   handlert   _credentials(   R   RY   R]   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR!   ÿ   s    c         K  s   | |  _  d S(   uK   
        Sets headers that will be used on every outgoing request.
        N(   Rˆ   (   R   R4   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   credentials  s    c         C  s5   | |  j  _ | |  j  _ | d k r1 |  j ƒ  n  d S(   ud   
        Forcibly authenticates outgoing requests with the given
        user and/or token.
        N(   R‡   Rƒ   R„   R,   t   logout(   R   R   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR   
  s    c         K  s&   | j  |  j ƒ t t |  ƒ j |   S(   N(   Rt   Rˆ   RN   R†   R   (   R   R4   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR     s    c         K  s@   t  t |  ƒ j | d | | } | r< |  j | |  } n  | S(   NRj   (   RN   R†   Ry   t   _handle_redirects(   R   Ru   Rj   t   followRv   t   response(    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRy     s    !c      	   K  sL   t  t |  ƒ j | d | d | d | | } | rH |  j | |  } n  | S(   NRj   R\   Rk   (   RN   R†   Rz   R‹   (   R   Ru   Rj   R\   Rk   RŒ   Rv   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRz     s
    c      	   K  sL   t  t |  ƒ j | d | d | d | | } | rH |  j | |  } n  | S(   NRj   R\   Rk   (   RN   R†   R{   R‹   (   R   Ru   Rj   R\   Rk   RŒ   Rv   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR{   '  s
    c      	   K  sL   t  t |  ƒ j | d | d | d | | } | rH |  j | |  } n  | S(   NRj   R\   Rk   (   RN   R†   R|   R‹   (   R   Ru   Rj   R\   Rk   RŒ   Rv   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR|   /  s
    c      	   K  sL   t  t |  ƒ j | d | d | d | | } | rH |  j | |  } n  | S(   NRj   R\   Rk   (   RN   R†   R}   R‹   (   R   Ru   Rj   R\   Rk   RŒ   Rv   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR}   7  s
    c      	   K  sL   t  t |  ƒ j | d | d | d | | } | rH |  j | |  } n  | S(   NRj   R\   Rk   (   RN   R†   R~   R‹   (   R   Ru   Rj   R\   Rk   RŒ   Rv   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR~   ?  s
    c         C  sD   i  |  _  d  |  j _ d  |  j _ |  j r@ t t |  ƒ j ƒ  n  d  S(   N(	   Rˆ   R,   R‡   Rƒ   R„   RS   RN   R†   RŠ   (   R   (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRŠ   G  s
    		N(   R   R   R   R!   R‰   R,   R   R   Ry   Rz   R{   R|   R}   R~   RŠ   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR†   þ   s    	
						t   APITransactionTestCasec           B  s   e  Z e Z RS(    (   R   R   R†   t   client_class(    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyRŽ   R  s   t   APITestCasec           B  s   e  Z e Z RS(    (   R   R   R†   R   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR   V  s   t   APISimpleTestCasec           B  s   e  Z e Z RS(    (   R   R   R†   R   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR‘   Z  s   t   APILiveServerTestCasec           B  s   e  Z e Z RS(    (   R   R   R†   R   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyR’   ^  s   (6   t
   __future__R    RA   t   django.confR   t   django.core.exceptionsR   t   django.core.handlers.wsgiR   t   django.testR   t   django.test.clientR   t   DjangoClientR   R'   R   t   django.utilsR   t   django.utils.encodingR	   t   django.utils.httpR
   t   rest_framework.compatR   R   t   rest_framework.settingsR   R,   R   RD   RE   t   _collectionst   HTTPHeaderDictR   t   objectR   t   adapterst   HTTPAdapterR%   t   SessionRM   RR   RX   R‚   R†   t   TransactionTestCaseRŽ   t   TestCaseR   t   SimpleTestCaseR‘   t   LiveServerTestCaseR’   (    (    (    s5   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/test.pyt   <module>   s<   "@		^T