ó
P'—^c           @   s  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 m Z d  d l m Z m Z d  d l m Z m Z m Z m Z 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 e ƒ  Z  d e	 j! f d „  ƒ  YZ" d e	 j! f d „  ƒ  YZ# d e	 j! f d „  ƒ  YZ$ d e j% f d „  ƒ  YZ& d e j% f d „  ƒ  YZ' d e f d „  ƒ  YZ( d e( f d „  ƒ  YZ) d e( f d „  ƒ  YZ* d e f d „  ƒ  YZ+ d  e( f d! „  ƒ  YZ, d" e( f d# „  ƒ  YZ- d$ e- f d% „  ƒ  YZ. d& e- f d' „  ƒ  YZ/ d( e- f d) „  ƒ  YZ0 d* e- f d+ „  ƒ  YZ1 d, e f d- „  ƒ  YZ2 d. e f d/ „  ƒ  YZ3 d0 e f d1 „  ƒ  YZ4 d2 e f d3 „  ƒ  YZ5 d4 e j6 f d5 „  ƒ  YZ7 d6 e- f d7 „  ƒ  YZ8 d8 e j9 f d9 „  ƒ  YZ: d: e- f d; „  ƒ  YZ; d< e- f d= „  ƒ  YZ< d> „  Z= d? e f d@ „  ƒ  YZ> dA e( f dB „  ƒ  YZ? dC e f dD „  ƒ  YZ@ e jA ƒ  ZB eB jC dE e@ dF dE ƒeB jD ZE eE e dG e) jF ƒ  ƒ e dH e< jF ƒ  ƒ g 7ZE e dI eG ƒ dJ e f dK „  ƒ  Yƒ ZH e dI eG ƒ dL e f dM „  ƒ  Yƒ ZI d S(N   iÿÿÿÿ(   t   OrderedDictN(   t   url(   t   cache(   t   models(   t   TemplateDoesNotExistt   Template(   t   TestCaset   override_settings(   t   serializerst   statust	   rendererst
   paginationt   filterst   routers(   t	   APIClient(   t   APIRequestFactory(   t   Query(   t   MultipleModelAPIView(   t   MultipleModelAPIViewSett   RestTestModelsc           B   s!   e  Z d  Z d d d „  ƒ  YZ RS(   so   
    Taking idea from Rest Framework's own tests
    Base for test models that creates a unified app label
    t   Metac           B   s   e  Z d  Z e Z RS(   t   mm_tests(   t   __name__t
   __module__t	   app_labelt   Truet   abstract(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR      s   (    (   R   R   t   __doc__R   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR      s   t   Playc           B   s>   e  Z e j d  d ƒ Z e j d  d ƒ Z e j d  d ƒ Z RS(   t
   max_lengthid   iÈ   i   (   R   R   R   t	   CharFieldt   genret   titlet   IntegerFieldt   year(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR   "   s   t   Poemc           B   s,   e  Z e j d  d ƒ Z e j d  d ƒ Z RS(   R   iÈ   id   (   R   R   R   R   R    t   style(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR#   (   s   t   PlaySerializerc           B   s   e  Z d  d d „  ƒ  YZ RS(   R   c           B   s   e  Z e Z d Z RS(   R   R    R"   (   R   R    R"   (   R   R   R   t   modelt   fields(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR   1   s   (    (   R   R   R   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR%   /   s   t   PoemSerializerc           B   s   e  Z d  d d „  ƒ  YZ RS(   R   c           B   s   e  Z e Z d Z RS(   R    R$   (   R    R$   (   R   R   R#   R&   R'   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR   8   s   (    (   R   R   R   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR(   6   s   t   BasicTestViewc           B   s8   e  Z e j j ƒ  e f e j j d  d ƒ e f f Z	 RS(   R$   t   Sonnet(
   R   R   R   t   objectst   allR%   R#   t   filterR(   t	   queryList(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR)   @   s   t   TestBrowsableAPIViewc           B   s   e  Z e j f Z RS(    (   R   R   R
   t   BrowsableAPIRenderert   renderer_classes(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR/   E   s   t   AsObjectViewc           B   s   e  Z e Z RS(    (   R   R   R   t	   objectify(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR2   K   s   t   LabelTestViewc           B   s>   e  Z e j j ƒ  e d  f e j j d d ƒ e d f f Z	 RS(   s	   The PlaysR$   R*   s   The Sonnets(
   R   R   R   R+   R,   R%   R#   R-   R(   R.   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR4   P   s   t   BasicNoLabelViewc           B   s   e  Z e Z RS(    (   R   R   t   Falset   add_model_type(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR5   V   s   t   BasicFlatViewc           B   s   e  Z e Z RS(    (   R   R   R   t   flat(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR8   [   s   t   OrderedFlatViewc           B   s   e  Z d  Z RS(   R    (   R   R   t   sorting_field(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR:   `   s   t   ReversedFlatViewc           B   s   e  Z d  Z RS(   s   -title(   R   R   R;   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR<   e   s   t   OrderedWrongViewc           B   s   e  Z d  Z RS(   R"   (   R   R   R;   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR=   j   s   t   FlatNoLabelViewc           B   s   e  Z e Z RS(    (   R   R   R6   R7   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR>   o   s   t   FlatLabelViewc           B   sD   e  Z e Z e j j ƒ  e d  f e j j	 d d ƒ e
 d f f Z RS(   t   DramaR$   R*   t   Poetry(   R   R   R   R9   R   R+   R,   R%   R#   R-   R(   R.   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR?   t   s   t
   BrokenViewc           B   s   e  Z RS(    (   R   R   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRB   {   s   t   DynamicQueryViewc           B   s   e  Z d  „  Z RS(   c         C   sS   |  j  d j d d ƒ } t j j d | ƒ t f t j j d d ƒ t f f } | S(   Nt   playt   -t    R    R$   R*   (   t   kwargst   replaceR   R+   R-   R%   R#   R(   (   t   selfR    R.   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   get_queryList‚   s    (   R   R   RJ   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRC   €   s   t   CachedQueryViewc           B   s   e  Z d  „  Z RS(   c         C   s{   t  j d ƒ } | sw |  j d j d d ƒ } t j j d | ƒ t f t j j d d ƒ t	 f f } t  j
 d | ƒ n  | S(   Nt   cachedquerylistRD   RE   RF   R    R$   R*   (   R   t   getRG   RH   R   R+   R-   R%   R#   R(   t   set(   RI   R.   R    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRJ      s    (   R   R   RJ   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRK   ‹   s   t   BasicPaginationc           B   s   e  Z d  Z d Z d Z RS(   i   t	   page_sizei
   (   R   R   RP   t   page_size_query_paramt   max_page_size(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRO   ˜   s   t   PageNumberPaginationViewc           B   s   e  Z e Z RS(    (   R   R   RO   t   pagination_class(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRS   ž   s   t   LimitPaginationc           B   s   e  Z d  Z d Z RS(   i   i   (   R   R   t   default_limitt	   max_limit(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRU   £   s   t   LimitOffsetPaginationViewc           B   s   e  Z e Z RS(    (   R   R   RU   RT   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRX   ¨   s   t   HTMLRendererViewc           B   s    e  Z e j e j f Z d  Z RS(   s	   test.html(   R   R   R
   t   JSONRenderert   TemplateHTMLRendererR1   t   template_name(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRY   ­   s   c         O   s   | j  d } |  j d | ƒ S(   Nt   lettert   title__icontains(   t   query_paramst   exclude(   t   querysett   requestt   argsRG   t   letter_to_exclude(    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   title_without_letter³   s    t   FilterFnViewc           B   s;   e  Z e e j j ƒ  e d  e ƒe j j ƒ  e	 f f Z
 RS(   t	   filter_fn(   R   R   R   R   R+   R,   R%   Re   R#   R(   R.   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRf   ¸   s   t   SearchFilterViewc           B   s   e  Z e j f Z d Z RS(   R    (   R    (   R   R   R   t   SearchFiltert   filter_backendst   search_fields(    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRh   ¾   s   t   BasicTestViewSetc           B   s8   e  Z e j j ƒ  e f e j j d  d ƒ e f f Z	 RS(   R$   R*   (
   R   R   R   R+   R,   R%   R#   R-   R(   R.   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRl   Ä   s   t   viewsett	   base_names   ^$s
   ^template$t   ROOT_URLCONFt   TestMMViewsc           B   s×   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 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sº   t  j j t  d d d d d d ƒ t  d d d d d d	 ƒ t  d d
 d d d d ƒ t  d d d d d d ƒ g ƒ t j j t d d d d ƒ t d d d d ƒ t d d d d ƒ g ƒ d  S(   NR    s   Romeo And JulietR   t   TragedyR"   i=  s   A Midsummer Night's Dreamt   Comedyi@  s   Julius CaesariW  s   As You Like Its'   Shall I compare thee to a summer's day?R$   R*   s"   As a decrepit father takes delights   A Lover's Complaintt	   Narrative(   R   R+   t   bulk_createR#   (   RI   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   setUpÚ   s(    		c      
   C   s  t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j t
 | j ƒ d ƒ |  j | j i i d d 6d d 6d d	 6i d
 d 6d d 6d d	 6i d d 6d d 6d d	 6i d d 6d d 6d d	 6g d 6i i d d 6d d 6i d d 6d d 6g d 6g ƒ d S(   sÑ   
        Tests the default case for the MultipleModelAPIView, which should be:
            flat = False
            sorting_field = None
            add_model_type = True
            objectify = False
        t   /i   Ns   Romeo And JulietR    Rq   R   i=  R"   s   A Midsummer Night's DreamRr   i@  s   Julius CaesariW  s   As You Like ItRD   s'   Shall I compare thee to a summer's day?R*   R$   s"   As a decrepit father takes delightt   poem(   R)   t   as_viewt   factoryRM   t   assertNumQueriest   rendert   assertEqualt   status_codeR	   t   HTTP_200_OKt   lent   data(   RI   t   viewRb   t   response(    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_defaultsó   s    	c         C   s   t  j ƒ  } i d d 6} t j d | d d ƒ} |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j | j
 i d d	 6ƒ d S(
   s8   
        POST requests should throw a 405 Error
        R€   t   fakeRv   t   formatt   jsoni    Ns   Method "POST" not allowed.t   detail(   R)   Rx   Ry   t   postRz   R{   R|   R}   R	   t   HTTP_405_METHOD_NOT_ALLOWEDR€   (   RI   R   R€   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt	   test_post  s    c         C   s   t  j ƒ  } i d d 6} t j d | d d ƒ} |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j | j
 i d d	 6ƒ d S(
   s7   
        PUT requests should throw a 405 Error
        R€   R„   Rv   R…   R†   i    Ns   Method "PUT" not allowed.R‡   (   R)   Rx   Ry   t   putRz   R{   R|   R}   R	   R‰   R€   (   RI   R   R€   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_put!  s    c         C   sw   t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j | j
 i d d 6ƒ d S(   s:   
        DELETE requests should throw a 405 Error
        Rv   i    Ns   Method "DELETE" not allowed.R‡   (   R)   Rx   Ry   t   deleteRz   R{   R|   R}   R	   R‰   R€   (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_delete0  s    c      
   C   s   t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j | j
 i i d d 6d d 6d d	 6i d
 d 6d d 6d d	 6i d d 6d d 6d d	 6i d d 6d d 6d d	 6g d 6i d d 6d d 6i d d 6d d 6g d 6ƒ d S(   sw   
        Tests the 'objectify' property, which allows returning an object/dict
        instead of a list/array
        Rv   i   Ns   Romeo And JulietR    Rq   R   i=  R"   s   A Midsummer Night's DreamRr   i@  s   Julius CaesariW  s   As You Like ItRD   s'   Shall I compare thee to a summer's day?R*   R$   s"   As a decrepit father takes delightRw   (   R2   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R€   (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_objectify>  s    c      	   C   s  t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j t
 | j ƒ d ƒ |  j | j i d d 6d d 6d d	 6i d
 d 6d d 6d d	 6i d d 6d d 6d d	 6i d d 6d d 6d d	 6g i d d 6d d 6i d d 6d d 6g g ƒ d S(   sV   
        Tests that no label (aka add_model_type = False) just gives the data
        Rv   i   Ns   Romeo And JulietR    Rq   R   i=  R"   s   A Midsummer Night's DreamRr   i@  s   Julius CaesariW  s   As You Like Its'   Shall I compare thee to a summer's day?R*   R$   s"   As a decrepit father takes delight(   R5   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R   R€   (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_no_labelX  s    c         C   s°   t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j t
 | j ƒ d ƒ |  j d | j d j ƒ  ƒ |  j d | j d j ƒ  ƒ d S(   s‡   
        Adding labels as a third element in the queryList elements should use those labels
        instead of the model names
        Rv   i   Ns	   The Playsi    s   The Sonnetsi   (   R4   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R   R€   t   assertInt   keys(   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_new_labelss  s    c         C   s  t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j t
 | j ƒ d ƒ |  j | j t d d d d g ƒ t d d d d g ƒ t d  d! d" d# g ƒ t d$ d% d& d' g ƒ t d( d) d* g ƒ t d+ d, d- g ƒ g ƒ d S(.   sX   
        Putting flat=True should flatten the data to a single list of elements
        Rv   i   Ni   R   Rq   R    s   Romeo And JulietR"   i=  t   typeRD   Rr   s   A Midsummer Night's Dreami@  s   Julius CaesariW  s   As You Like Its'   Shall I compare thee to a summer's day?R$   R*   Rw   s"   As a decrepit father takes delight(   R   Rq   (   R    s   Romeo And Juliet(   R"   i=  (   R”   RD   (   R   Rr   (   R    s   A Midsummer Night's Dream(   R"   i@  (   R”   RD   (   R   Rq   (   R    s   Julius Caesar(   R"   iW  (   R”   RD   (   R   Rr   (   R    s   As You Like It(   R"   iW  (   R”   RD   (   R    s'   Shall I compare thee to a summer's day?(   R$   R*   (   R”   Rw   (   R    s"   As a decrepit father takes delight(   R$   R*   (   R”   Rw   (   R8   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R   R€   R    (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_simple_flat…  s    c         C   së   t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j t | j ƒ d ƒ |  j | j t	 d d d d g ƒ t	 d d d d g ƒ t	 d  d! d" g ƒ t	 d# d$ d% d& g ƒ t	 d' d( d) d* g ƒ t	 d+ d, d- g ƒ g ƒ d S(.   sl   
        Adding the sorting_field attribute should order the flat items according to whatever field
        Rv   i   Ni   R   Rr   R    s   A Midsummer Night's DreamR"   i@  R”   RD   s   As You Like ItiW  s"   As a decrepit father takes delightR$   R*   Rw   Rq   s   Julius Caesars   Romeo And Julieti=  s'   Shall I compare thee to a summer's day?(   R   Rr   (   R    s   A Midsummer Night's Dream(   R"   i@  (   R”   RD   (   R   Rr   (   R    s   As You Like It(   R"   iW  (   R”   RD   (   R    s"   As a decrepit father takes delight(   R$   R*   (   R”   Rw   (   R   Rq   (   R    s   Julius Caesar(   R"   iW  (   R”   RD   (   R   Rq   (   R    s   Romeo And Juliet(   R"   i=  (   R”   RD   (   R    s'   Shall I compare thee to a summer's day?(   R$   R*   (   R”   Rw   (
   R:   Rx   Ry   RM   Rz   R{   R|   R   R€   R    (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_ordered_flatœ  s    c         C   së   t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j t | j ƒ d ƒ |  j | j t	 d d d g ƒ t	 d d d d g ƒ t	 d d  d! d" g ƒ t	 d# d$ d% g ƒ t	 d& d' d( d) g ƒ t	 d* d+ d, d- g ƒ g ƒ d S(.   sl   
        Adding the sorting_field attribute should order the flat items according to whatever field
        Rv   i   Ni   R    s'   Shall I compare thee to a summer's day?R$   R*   R”   Rw   R   Rq   s   Romeo And JulietR"   i=  RD   s   Julius CaesariW  s"   As a decrepit father takes delightRr   s   As You Like Its   A Midsummer Night's Dreami@  (   R    s'   Shall I compare thee to a summer's day?(   R$   R*   (   R”   Rw   (   R   Rq   (   R    s   Romeo And Juliet(   R"   i=  (   R”   RD   (   R   Rq   (   R    s   Julius Caesar(   R"   iW  (   R”   RD   (   R    s"   As a decrepit father takes delight(   R$   R*   (   R”   Rw   (   R   Rr   (   R    s   As You Like It(   R"   iW  (   R”   RD   (   R   Rr   (   R    s   A Midsummer Night's Dream(   R"   i@  (   R”   RD   (
   R<   Rx   Ry   RM   Rz   R{   R|   R   R€   R    (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_reversed_ordered±  s    c         C   s2   t  j ƒ  } t j d ƒ } |  j t | | ƒ d S(   sG   
        Sorting by a non-shared field should throw a KeyError
        Rv   N(   R=   Rx   Ry   RM   t   assertRaisest   KeyError(   RI   R   Rb   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_ordered_wrong_sortingÆ  s    c         C   sï   t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j t
 | j ƒ d ƒ |  j | j t d d d g ƒ t d d d g ƒ t d d d g ƒ t d d d  g ƒ t d! d" g ƒ t d# d$ g ƒ g ƒ d S(%   sX   
        Putting flat=True should flatten the data to a single list of elements
        Rv   i   Ni   R   Rq   R    s   Romeo And JulietR"   i=  Rr   s   A Midsummer Night's Dreami@  s   Julius CaesariW  s   As You Like Its'   Shall I compare thee to a summer's day?R$   R*   s"   As a decrepit father takes delight(   R   Rq   (   R    s   Romeo And Juliet(   R"   i=  (   R   Rr   (   R    s   A Midsummer Night's Dream(   R"   i@  (   R   Rq   (   R    s   Julius Caesar(   R"   iW  (   R   Rr   (   R    s   As You Like It(   R"   iW  (   R    s'   Shall I compare thee to a summer's day?(   R$   R*   (   R    s"   As a decrepit father takes delight(   R$   R*   (   R>   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R   R€   R    (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_flat_no_labelÐ  s    c         C   s  t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j t
 | j ƒ d ƒ |  j | j t d d d d g ƒ t d d d d g ƒ t d  d! d" d# g ƒ t d$ d% d& d' g ƒ t d( d) d* g ƒ t d+ d, d- g ƒ g ƒ d S(.   sX   
        Putting flat=True should flatten the data to a single list of elements
        Rv   i   Ni   R   Rq   R    s   Romeo And JulietR"   i=  R”   R@   Rr   s   A Midsummer Night's Dreami@  s   Julius CaesariW  s   As You Like Its'   Shall I compare thee to a summer's day?R$   R*   RA   s"   As a decrepit father takes delight(   R   Rq   (   R    s   Romeo And Juliet(   R"   i=  (   R”   R@   (   R   Rr   (   R    s   A Midsummer Night's Dream(   R"   i@  (   R”   R@   (   R   Rq   (   R    s   Julius Caesar(   R"   iW  (   R”   R@   (   R   Rr   (   R    s   As You Like It(   R"   iW  (   R”   R@   (   R    s'   Shall I compare thee to a summer's day?(   R$   R*   (   R”   RA   (   R    s"   As a decrepit father takes delight(   R$   R*   (   R”   RA   (   R?   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R   R€   R    (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_flat_custom_labelsç  s    c         C   s2   t  j ƒ  } t j d ƒ } |  j t | | ƒ d S(   s^   
        not specifying a queryList or a get_queryList should raise an AssertionError
        Rv   N(   RB   Rx   Ry   RM   R˜   t   AssertionError(   RI   R   Rb   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_missing_queryListþ  s    c      	   C   s×   t  j ƒ  } t j d ƒ } |  j d ƒ  | | d d ƒ} Wd QX|  j | j t j ƒ |  j t	 | j
 ƒ d ƒ |  j | j
 i i d d 6d d	 6d
 d 6g d 6i i d d 6d d 6i d d 6d d 6g d 6g ƒ d S(   sS   
        using get_QueryList allows the construction of dynamic queryLists
        s   /Julius-Caesari   RD   s   Julius-CaesarNs   Julius CaesarR    Rq   R   iW  R"   s'   Shall I compare thee to a summer's day?R*   R$   s"   As a decrepit father takes delightRw   (   RC   Rx   Ry   RM   Rz   R|   R}   R	   R~   R   R€   (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_dynamic_queryList	  s    c      
   C   sÿ   t  j ƒ  } t j d ƒ } |  j d ƒ  | | d d ƒ} Wd  QX|  j d ƒ  | | d d ƒ} Wd  QX|  j | j t j ƒ |  j t	 | j
 ƒ d ƒ |  j | j
 i i d d 6d d	 6d
 d 6g d 6i i d d 6d d 6i d d 6d d 6g d 6g ƒ d  S(   Ns   /Julius-Caesari   RD   s   Julius-Caesari    s   Julius CaesarR    Rq   R   iW  R"   s'   Shall I compare thee to a summer's day?R*   R$   s"   As a decrepit father takes delightRw   (   RK   Rx   Ry   RM   Rz   R|   R}   R	   R~   R   R€   (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_cached_queryList"  s    c         C   s8   t  ƒ  } | j d d d ƒ} |  j | j t j ƒ d S(   s   
        DRF 3.3 broke the MultipleModelAPIView with a get_queryset call
        This test is to replicate (and then fix) that problem
        Rv   R…   t   apiN(   R   RM   R|   R}   R	   R~   (   RI   t   clientR‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_url_endpoint9  s    	c         C   s{  t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j | j
 d d ƒ |  j | j
 d d ƒ |  j | j
 d d ƒ |  j t | j
 d	 ƒ d
 ƒ t j d i d d 6ƒ } | | ƒ j ƒ  } |  j | j t j	 ƒ |  j t | j
 d	 ƒ d ƒ t j d i d d 6ƒ } | | ƒ j ƒ  } |  j | j t j	 ƒ |  j t | j
 d	 ƒ d ƒ d S(   st   
        When flat is True, PageNumberPagination should work as in
        a normal DRF generic ListAPIView
        Rv   i   Nt   counti   t   previoust   nexts   http://testserver/?page=2t   resultsi   t   pagei   i   RP   (   RS   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R€   t   NoneR   (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_page_number_paginationC  s"    c         C   sÀ  t  j ƒ  } t j d ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j | j
 d d ƒ |  j | j
 d d ƒ |  j | j
 d d ƒ |  j t | j
 d	 ƒ d
 ƒ t j d i d
 d 6ƒ } | | ƒ j ƒ  } |  j | j t j	 ƒ |  j | j
 d d ƒ |  j | j
 d d ƒ |  j | j
 d d ƒ |  j t | j
 d	 ƒ d ƒ t j d i d d 6ƒ } | | ƒ j ƒ  } |  j | j t j	 ƒ |  j t | j
 d	 ƒ d ƒ d S(   sm   
        When Flat is True, LimitOffsetPagination should work
        as in a normal DRF ListAPIView
        Rv   i   NR¥   R¦   s#   http://testserver/?limit=5&offset=5R¤   i   R§   i   t   offsets   http://testserver/?limit=5i   i   t   limit(   RX   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R€   R©   R   (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_limit_offset_paginatione  s(    c      
   C   sñ   t  j ƒ  } t j d i d d 6ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j | j
 i i d d 6d d	 6d
 d 6i d d 6d d	 6d d 6g d 6i i d d 6d d 6i d d 6d d 6i d d 6d d 6g d 6g ƒ d S(   sU  
        The filter function is useful if you want to apply filtering to one query
        but not another (unlike adding view level filtering, which will filter all the
        querysets), but that filtering can't be provided at the beginning (for example, it
        needs to access a query_param).  This is testing the filter_fn.
        Rv   t   oR]   i   Ns   A Midsummer Night's DreamR    Rr   R   i@  R"   s   Julius CaesarRq   iW  RD   s'   Shall I compare thee to a summer's day?R*   R$   s"   As a decrepit father takes delights   A Lover's ComplaintRs   Rw   (   Rf   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R€   (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_filter_fn_viewŠ  s    c         C   s·   t  j ƒ  } t j d i d d 6ƒ } |  j d ƒ  | | ƒ j ƒ  } Wd QX|  j | j t j	 ƒ |  j | j
 i i d d 6d d	 6d
 d 6g d 6i i d d 6d d 6g d 6g ƒ d S(   sO   
        Tests use of built in DRF filtering with MultipleModelAPIView
        Rv   t   ast   searchi   Ns   As You Like ItR    Rr   R   iW  R"   RD   s"   As a decrepit father takes delightR*   R$   Rw   (   Rh   Rx   Ry   RM   Rz   R{   R|   R}   R	   R~   R€   (   RI   R   Rb   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_search_filter_view¬  s    c      	   C   sú   t  ƒ  } | j d d d ƒ} |  j | j t j ƒ |  j t | j ƒ d ƒ |  j | j i i d d 6d d 6d	 d
 6i d d 6d d 6d d
 6i d d 6d d 6d d
 6i d d 6d d 6d d
 6g d 6i i d d 6d d 6i d d 6d d 6g d 6g ƒ d S(   sR   
        Tests the Base MutlipleModelAPIViewSet with the default settings
        s	   /viewset/R…   R¡   i   s   Romeo And JulietR    Rq   R   i=  R"   s   A Midsummer Night's DreamRr   i@  s   Julius CaesariW  s   As You Like ItRD   s'   Shall I compare thee to a summer's day?R*   R$   s"   As a decrepit father takes delightRw   N(   R   RM   R|   R}   R	   R~   R   R€   (   RI   R¢   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_base_viewsetÇ  s    	(   R   R   Ru   Rƒ   RŠ   RŒ   RŽ   R   R   R“   R•   R–   R—   Rš   R›   Rœ   Rž   RŸ   R    R£   Rª   R­   R¯   R²   R³   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRp   ×   s.   												
						
	"	%	"	t   TestMMVHTMLRendererc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s  t  j j t  d d d d d d ƒ t  d d d d d d	 ƒ t  d d
 d d d d ƒ t  d d d d d d ƒ g ƒ t j j t d d d d ƒ t d d d d ƒ t d d d d ƒ g ƒ t j j j |  _ d  d „ } d  d  d „ } | t j j _ | t j j _	 d  S(   NR    s   Romeo And JulietR   Rq   R"   i=  s   A Midsummer Night's DreamRr   i@  s   Julius CaesariW  s   As You Like Its'   Shall I compare thee to a summer's day?R$   R*   s"   As a decrepit father takes delights   A Lover's ComplaintRs   c         S   s&   |  d k r t  d ƒ St |  ƒ ‚ d  S(   Ns	   test.htmls   <html>test: {{ data }}</html>(   R   R   (   R\   t   dirs(    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   get_template  s    
c         S   s-   |  d g k r t  d ƒ St |  d ƒ ‚ d  S(   Ns	   test.htmls   <html>test: {{ data }}</html>i    (   R   R   (   t   template_name_listRµ   t   using(    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   select_template  s    
(
   R   R+   Rt   R#   t   djangot   templatet   loaderR¶   R©   R¹   (   RI   R¶   R¹   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyRu   â  s2    		c         C   sÇ   t  ƒ  } | j d i d d 6ƒ } |  j | j t j ƒ |  j d | j ƒ |  j | d ƒ |  j | d ƒ |  j | d ƒ | j d ƒ } |  j | j t j ƒ |  j	 d | j ƒ |  j	 d | ƒ d	 S(
   s]   
        Testing bug in which results dict failed to be passed into template context
        s	   /templatet   htmlR…   R€   Rq   s   <html>t   decrepits   /template?format=jsonN(
   R   RM   R|   R}   R	   R~   R‘   R€   t   assertContainst   assertNotIn(   RI   R¢   R‚   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   test_html_renderer  s    	c         C   s   |  j  t j j _  d S(   s'   
        Revert monkeypatching
        N(   R¶   Rº   R»   R¼   (   RI   (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   tearDown%  s    (   R   R   Ru   RÁ   RÂ   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyR´   ß  s   	,	(J   t   collectionsR    t   django.template.loaderRº   t   django.conf.urlsR   t   django.core.cacheR   t	   django.dbR   t   django.templateR   R   t   django.testR   R   t   rest_frameworkR   R	   R
   R   R   R   t   rest_framework.testR   R   t   drf_multiple_model.mixinsR   t   drf_multiple_model.viewsR   t   drf_multiple_model.viewsetsR   Ry   t   ModelR   R   R#   t   ModelSerializerR%   R(   R)   R/   R2   R4   R5   R8   R:   R<   R=   R>   R?   RB   RC   RK   t   PageNumberPaginationRO   RS   t   LimitOffsetPaginationRU   RX   RY   Re   Rf   Rh   Rl   t   SimpleRoutert   routert   registert   urlst   urlpatternsRx   R   Rp   R´   (    (    (    s:   /tmp/pip-unpacked-wheel-65l7tp/drf_multiple_model/tests.pyt   <module>   sj   .	
		ÿ ÿ 	