
    g                    4   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dl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 d dlmZ d d	lmZ d d
lmZmZmZmZmZmZ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*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9 d dl:m;Z; d dl<m=Z=m>Z>m?Z?m@Z@ d dlAmBZBmCZC d dlDmEZE d dlFmGZG d dlHmIZImJZJ d dlKmLZLmMZM d dlNmOZOmPZP d dlQmRZR d d lSmTZTmUZUmVZVmWZWmXZX d d!lYmZZZ d d"l[m\Z\ d d#l]m^Z^  ej                  d$      Z`d%Zae\sd& Zbd' Zcd( Zdd) Ze G d* d+eT      Zf G d, d-      Zg G d. d/eg      Zh G d0 d1ei      Zj G d2 d3      Zk G d4 d5ej                        Zm G d6 d7em      ZndRd8ZodRd9Zp G d: d;      Zq G d< d=en      Zl G d> d?      Zrd@ ZsdA ZtdB ZudC Zv G dD dEe9      Zw G dF dGe/      Zx G dH dIex      Zy G dJ dKex      Zz G dL dMej                        Z| G dN dOen      Z} G dP dQ      Z~y)S    N)Counter)contextmanager)copydeepcopy)get_close_matches)wraps)mock)_DebugResult)	safe_repr)	parse_qslunquote	urlencodeurljoinurlparseurlsplit
urlunparse)url2pathname)async_to_synciscoroutinefunction)apps)settings)mail)ImproperlyConfiguredValidationError)locks)WSGIHandlerget_path_info)call_command)no_style)emit_post_migrate_signal)ThreadedWSGIServerWSGIRequestHandler)setting_changed)DEFAULT_DB_ALIAS
connectionconnectionstransaction)NO_DB_ALIASBaseDatabaseWrapper)	CharField)	QueryDict)split_domain_portvalidate_host)AsyncClientClient)HTMLParseError
parse_html)template_rendered)CaptureQueriesContextContextListcompare_xmlmodify_settingsoverride_settings)classproperty)PY311)servezdjango.test)TestCaseTransactionTestCaseSimpleTestCaseskipIfDBFeatureskipUnlessDBFeaturec                     t        |       }	 |j                  }|j                  } ||       } ||| d d d        |S # t        $ r( t	        d|j
                   d|j                   d      d w xY w)N'.z6' object does not support the context manager protocol)type	__enter____exit__AttributeError	TypeError
__module____qualname__)cm
addcleanupclsenterexitresults         m/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/test/testcases.py_enter_contextrQ   I   s    2h	MME<<D r4T4.  	CNN#1S%5%5$6 7+ , 	s	   ; 1A,c                 ,    t        | t              s| g} | S )z.Put value into a list if it's not already one.)
isinstancelist)values    rP   to_listrV   Y   s    eT"L    c                     	 t        j                  t        j                  |              y# t        t        t         j
                  f$ r Y yw xY w)z\
    Returns true if the object can be dumped and loaded through the pickle
    module.
    FT)pickleloadsdumpsrF   rG   PickleError)objs    rP   is_pickabler^   `   sB    
V\\#&'  Iv'9'9: s   (+ AAc                     	 t        |      }|S # t        $ r3}|d|}| j                  | j                  ||             Y d }~S d }~ww xY w)N
)r1   r0   fail_formatMessage)selfhtmluser_msgmsgdomestandardMsgs          rP   assert_and_parse_htmlrj   l   sU    > J  >"%q)		$%%h<==J>s    	A(AAc                   (     e Zd Z fdZ fdZ xZS )_AssertNumQueriesContextc                 @    || _         || _        t        |   |       y N)	test_casenumsuper__init__)rc   ro   rp   r%   	__class__s       rP   rr   z!_AssertNumQueriesContext.__init__v   s    "$rW   c                    t         |   |||       |y t        |       }| j                  j	                  || j
                  d|| j
                  dj                  d t        | j                  d      D              fz         y )Nz:%d queries executed, %d expected
Captured queries were:
%sr`   c              3   6   K   | ]  \  }}d ||d   fz    yw)z%d. %ssqlN ).0iquerys      rP   	<genexpr>z4_AssertNumQueriesContext.__exit__.<locals>.<genexpr>   s*      $M5 5<00$M      )start)	rq   rE   lenro   assertEqualrp   join	enumeratecaptured_queries)rc   exc_type	exc_value	tracebackexecutedrs   s        rP   rE   z!_AssertNumQueriesContext.__exit__{   s    9i8t9""HHJ		 $-d.C.C1$M 	
rW   )__name__rH   rI   rr   rE   __classcell__rs   s   @rP   rl   rl   u   s    %

 
rW   rl   c                   ,    e Zd ZddZd Zd Zd Zd Zy)_AssertTemplateUsedContextNc                 h    || _         || _        || _        || _        g | _        t               | _        y rn   )ro   template_name
msg_prefixcountrendered_templatesr4   context)rc   ro   r   r   r   s        rP   rr   z#_AssertTemplateUsedContext.__init__   s0    "*$
"$"}rW   c                     | j                   j                  |       | j                  j                  t        |             y rn   )r   appendr   r   )rc   sendersignaltemplater   kwargss         rP   on_template_renderz-_AssertTemplateUsedContext.on_template_render   s,    &&x0DM*rW   c                     | j                   j                  | j                  | j                  D cg c]  }|j                  |j                   c}| j
                  | j                         y c c}w rn   )ro   _assert_template_usedr   r   namer   r   )rc   ts     rP   testz_AssertTemplateUsedContext.test   sU    ,,!44K48JQVV4KOOJJ		
Ks   A-
A-
c                 D    t        j                  | j                         | S rn   )r2   connectr   rc   s    rP   rD   z$_AssertTemplateUsedContext.__enter__   s    !!$"9"9:rW   c                 h    t        j                  | j                         |y | j                          y rn   )r2   
disconnectr   r   )rc   r   r   r   s       rP   rE   z#_AssertTemplateUsedContext.__exit__   s(    $$T%<%<=		rW   ) N)r   rH   rI   rr   r   r   rD   rE   rw   rW   rP   r   r      s    %+
rW   r   c                       e Zd Zd Zy)_AssertTemplateNotUsedContextc                     | j                   D cg c]  }|j                  |j                   }}| j                  j                  | j                  |v | j
                   d| j                   d       y c c}w )N
Template 'z1' was used unexpectedly in rendering the response)r   r   ro   assertFalser   r   )rc   r   rendered_template_namess      rP   r   z"_AssertTemplateNotUsedContext.test   s{     33#
3qqvv7IAFF3 	  #
 	"""99z$*<*<)= >5 6	
#
s
   A4A4N)r   rH   rI   r   rw   rW   rP   r   r      s    
rW   r   c                       e Zd Zy)DatabaseOperationForbiddenN)r   rH   rI   rw   rW   rP   r   r      s    rW   r   c                       e Zd Zd Zd Zy)_DatabaseFailurec                      || _         || _        y rn   )wrappedmessage)rc   r   r   s      rP   rr   z_DatabaseFailure.__init__   s    rW   c                 ,    t        | j                        rn   )r   r   r   s    rP   __call__z_DatabaseFailure.__call__   s    (66rW   N)r   rH   rI   rr   r   rw   rW   rP   r   r      s    7rW   r   c                       e Zd ZeZeZdZdZ e	       Z
dZg dZe fd       Zed        Zed        Zed        Zed        Zd,d	Z fd
Zd Zd- fd	Zd Zd Zesed        Zd Zd Z	 	 	 	 d.dZd/dZd Z	 d0dZ 	 d1dZ!d Z"d Z#d/dZ$d/dZ%d Z&d Z'	 d2dZ(d3dZ)e*d        Z+d  Z,d! Z-d" Z.	 	 	 d3d#Z/d,d$Z0d,d%Z1d4d&Z2d/d'Z3d,d(Z4d,d)Z5d,d*Z6d,d+Z7 xZ8S )5r=   NzDatabase %(operation)s to %(alias)r are not allowed in SimpleTestCase subclasses. Either subclass TestCase or TransactionTestCase to ensure proper test isolation or add %(alias)r to %(test)s.databases to silence this failure.))r   r&   )temporary_connectionr&   )cursorqueries)chunked_cursorr   c                 8   t         |           | j                  r$| j                  t	        di | j                         | j
                  r$| j                  t        | j
                               | j                          | j                  | j                         y )Nrw   )
rq   
setUpClass_overridden_settingsenterClassContextr7   _modified_settingsr6   _add_databases_failuresaddClassCleanup_remove_databases_failuresrL   rs   s    rP   r   zSimpleTestCase.setUpClass   sv    ##!!"3"Oc6N6N"OP!!!!/#2H2H"IJ##%C::;rW   c                 :   | j                   dk(  rt        t              S | j                   D ]Z  }|t        vs| j                  d| j                  d|d}t        |t        t                    }|r|d|d   z  z  }t        |       t        | j                         S )N__all__rB   z.databases refers to z, which is not defined in settings.DATABASES.z Did you mean %r?r   )	databases	frozensetr&   rH   rI   r   rT   r   )rL   aliasr   close_matchess       rP   _validate_databasesz"SimpleTestCase._validate_databases   s    ==I%[))]]EK'
 ((  !2%k9J K 2]15EEEG*733 # ''rW   c           
         | j                         | _        t        D ]}  }|| j                  v rt        |   }| j                  D ]T  \  }}| j                  | j
                  d| j                  ||dz  }t        ||      }t        ||t        ||             V  | j                  t        j                  j                  t        d| j                                      y )NrB   r   r   	operationensure_connection)new)r   r   r&   _disallowed_connection_methods_disallowed_database_msgrH   rI   getattrsetattrr   r   r	   patchobjectr)   ensure_connection_patch_method)rL   r   r%   r   r   r   methods          rP   r   z&SimpleTestCase._add_databases_failures   s    //1 E%$U+J#&#E#Ei66'*~~s7G7GH"!*: 
 !T2
D*:67*KL $F	 ! 	JJ##668  	
rW   c                     t         D ]Q  }|| j                  v rt         |   }| j                  D ](  \  }}t        ||      }t	        |||j
                         * S y rn   )r&   r   r   r   r   r   )rL   r   r%   r   _r   s         rP   r   z)SimpleTestCase._remove_databases_failures  sU     E%$U+J==a T2
D&..9 >	 !rW   c                 6     t         j                   fd}|S )Nc                 R   | j                   | j                  j                  vrv| j                  t        k7  rc| j                  t        v rQj
                  j                   dj                   | j                  ddz  } t        | j                  |             S  | g|i | y )NrB   zthreaded connectionsr   )
r%   r   r   r(   r&   r   rH   rI   r   r   )rc   argsr   r   rL   real_ensure_connections       rP   patched_ensure_connectionzPSimpleTestCase.ensure_connection_patch_method.<locals>.patched_ensure_connection#  s    'JJcmm3JJ+-JJ+- 66"~~.a0@0@/AB!ZZ!7: 
 I'(>(>HJJ"49$9&9rW   )r)   r   )rL   r   r   s   ` @rP   r   z-SimpleTestCase.ensure_connection_patch_method  s    !4!F!F	:$ )(rW   c                 &    | j                  |       y)z
        Wrapper around default __call__ method to perform common Django test
        set up. This means that user-defined TestCases aren't required to
        include a call to super().setUp().
        N)_setup_and_call)rc   rO   s     rP   r   zSimpleTestCase.__call__7  s     	V$rW   c                     t         |   }|d   r4ddd}|j                         D ]  \  }}||v st        |      s|||<    |S |S )zR
        Make SimpleTestCase picklable for parallel tests using subtests.
        _outcomeN)r   _subtest)rq   __dict__itemsr^   )rc   statepickable_statekeyrU   rs   s        rP   __getstate__zSimpleTestCase.__getstate__?  s`       *.DAN#kkm
U.(E0B&+s# , "!rW   c                 >    t               }| j                  |d       y)z?Perform the same as __call__(), without catching the exception.T)debugN)r
   r   )rc   debug_results     rP   r   zSimpleTestCase.debugP  s    #~\6rW   c                 :   t        | | j                        }t        | j                  dd      xs t        |dd      }t        |      r t	        | | j                  t        |             |s	 | j                          |rt        | 1          nt        | 5  |       |s	 | j                          yy# t        $ r* |r |j                  | t        j                                Y yw xY w# t        $ r* |r |j                  | t        j                                Y yw xY w)a  
        Perform the following in order: pre-setup, run test, post-teardown,
        skipping pre/post hooks if test is set to be skipped.

        If debug=True, reraise any errors in setup and use super().debug()
        instead of __call__() to run the test.
        __unittest_skip__FN)r   _testMethodNamers   r   r   r   
_pre_setup	ExceptionaddErrorsysexc_inforq   r   r   _post_teardown)rc   rO   r   
testMethodskippedrs   s        rP   r   zSimpleTestCase._setup_and_callU  s    T4#7#78
$..*=uE 
+UJ

 z*D$..j0IJ! GMOGV$##%   clln5	  clln5	s$   ,B1 C' 10C$#C$'0DDc                 n    | j                         | _        | j                         | _        g t        _        y)zo
        Perform pre-test setup:
        * Create a test client.
        * Clear the mail test outbox.
        N)client_classclientasync_client_classasync_clientr   outboxr   s    rP   r   zSimpleTestCase._pre_setup{  s,     '') 335rW   c                      y)zPerform post-test things.Nrw   r   s    rP   r   zSimpleTestCase._post_teardown  s    rW   c                 .    t        || j                        S rn   )rQ   r   )rL   rJ   s     rP   r   z SimpleTestCase.enterClassContext  s    !"c&9&9::rW   c                     t        di |S )z
        A context manager that temporarily sets a setting and reverts to the
        original value when exiting the context.
        rw   )r7   rc   r   s     rP   r   zSimpleTestCase.settings  s    
 !*6**rW   c                     t        di |S )z
        A context manager that temporarily applies changes a list setting and
        reverts back to the original value when exiting the context.
        rw   )r6   r   s     rP   r6   zSimpleTestCase.modify_settings  s    
 (((rW   c           
      x   |r|dz  }t        |d      r| j                  |j                  |d|j                  |fz  z          | j	                  |j                  d   d   ||d|j                  d   d   |fz  z          |j                  d   \  }}| j	                  |j                  ||d|j                  |fz  z          n^| j	                  |j                  ||d|j                  |fz  z          |j
                  }t        |      \  }}	}
}}|
j                  d	      s2t        |j                  d
   |      }t        |j                  d
   |
      }
|rt        |	      \  }}|r,t        |t        j                        st        d|d|d      |j                  j                   xs i }|j                  j"                  xs i } |j                  j$                  |
t'        |      f|dk(  |d|}| j	                  |j                  ||d|
|j                  |fz  z          | j)                  |||d|d|dz          y)a*  
        Assert that a response redirected to a specific URL and that the
        redirect URL can be loaded.

        Won't work for external links since it uses the test client to do a
        request (use fetch_redirect_response=False to check such links without
        fetching them).
        : redirect_chainzHResponse didn't redirect as expected: Response code was %d (expected %d)r   r}   zPInitial response didn't redirect as expected: Response code was %d (expected %d)zNResponse didn't redirect as expected: Final Response code was %d (expected %d)/	PATH_INFOz4The test client is unable to fetch remote URLs (got z)). If the host is served by Django, add 'zW' to ALLOWED_HOSTS. Otherwise, use assertRedirects(..., fetch_redirect_response=False).https)secureheaderszKCouldn't retrieve redirection page '%s': response code was %d (expected %d)zResponse redirected to 'z', expected 'rA   N)hasattr
assertTruer  status_coder   urlr   
startswithr   requestr,   r-   r   ALLOWED_HOSTS
ValueErrorr   extrar	  getr+   assertURLEqual)rc   responseexpected_urlr  target_status_coder   fetch_redirect_responser  schemenetlocpathrz   fragmentdomainportr  r	  redirect_responses                     rP   assertRedirectszSimpleTestCase.assertRedirects  s   " $J8-.OO''$ ''5	66 ''*1-' **1-a0+>	??	  (66r:C$$"$ '');<	==	 $$$ ''5	66	 ,,C4<SM1FFD% ??3'h..{;SAx//<dC&  18-8N8N"O$
 	(  !--3"//117R$7HOO$7$7e$% #g-#	%
 %!   %11&( .::<NO	PP	 	>A<PQ	
rW   c           
      j    d }|r|dz  }| j                   ||       ||      |d|d|dz          y)a  
        Assert that two URLs are the same, ignoring the order of query string
        parameters except for parameters with the same name.

        For example, /path/?x=1&y=2 is equal to /path/?y=2&x=1, but
        /path/?a=1&a=2 isn't equal to /path/?a=2&a=1.
        c           	          t        |       } t        |       \  }}}}}}t        t        |            }t	        ||||t        |      |f      S )z'Sort the URL's query string parameters.)strr   sortedr   r   r   )r  r  r  r  paramsrz   r  query_partss           rP   	normalizez0SimpleTestCase.assertURLEqual.<locals>.normalize  sR    c(C<DSM9FFD&% 5!12Kvy/ExP rW   r  z
Expected 'z' to equal 'z'.N)r   )rc   url1url2r   r'  s        rP   r  zSimpleTestCase.assertURLEqual  s?    	 $JdOdO4FF	
rW   c                 b   t        |d      r1t        |j                        r|j                  s|j                          |r|dz  }| j	                  |j
                  ||d|j
                  |fz  z          |j                  rdj                  |j                        }n|j                  }t        |      }t        |t              r|r,t        |      }|j                  |j                        }d|z  }nt!        |      }|rt#        | |d d      }t#        | |d d      }|j%                  |      }	||	||fS )Nrenderr  z=Couldn't retrieve content: Response code was %d (expected %d)rW   z'%s'z%Response's content is not valid HTML:"Second argument is not valid HTML:)r
  callabler+  is_renderedr   r  	streamingr   streaming_contentcontentr   rS   bytesr#  decodecharsetreprrj   r   )
rc   r  textr  r   rd   r1  content_repr	text_repr
real_counts
             rP   _assert_containszSimpleTestCase._assert_contains.  s1    Hh')((OO$J    ( 4 4kBC C	
 hhx99:G&&G )$&$t9DnnX%5%56GIT
I+gt%LG )dD"FD ]]4(
*j,>>rW   c                     | j                  |||||      \  }}}}	|"| j                  ||| d| d| d| d|	 	       y| j                  |dk7  | d| d|	        y)	ao  
        Assert that a response indicates that some content was retrieved
        successfully, (i.e., the HTTP status code was as expected) and that
        ``text`` occurs ``count`` times in the content of the response.
        If ``count`` is None, the count doesn't matter - the assertion is true
        if the text occurs at least once in the response.
        NFound  instances of  (expected ) in the following response
r   Couldn't find  in the following response
)r:  r   r  )
rc   r  r6  r   r  r   rd   r8  r9  r7  s
             rP   assertContainszSimpleTestCase.assertContainsW  s     ;?:O:OdKT;
7	:z< !l&N9+ N!!&'D\NT	 OOa!l.;W#n&rW   c                 l    | j                  |||||      \  }}}}| j                  |d| | d|        y)z
        Assert that a response indicates that some content was retrieved
        successfully, (i.e., the HTTP status code was as expected) and that
        ``text`` doesn't occur in the content of the response.
        r   . unexpectedly found in the following response
N)r:  r   )	rc   r  r6  r  r   rd   r8  r9  r7  s	            rP   assertNotContainsz SimpleTestCase.assertNotContainsw  sV     ;?:O:OdKT;
7	:z< 	,yk *!N$		
rW   c                 8    t        ||      st        | d      y)zg
        Raise a ValueError if the given response doesn't have the required
        attribute.
        zD() is only usable on responses fetched using the Django test Client.N)r
  r  )rc   r  	attributemethod_names       rP   _check_test_client_responsez*SimpleTestCase._check_test_client_response  s/    
 x+-  * *  ,rW   c                 F   |j                   s| j                  | d| d       |(||j                  vr| j                  | d| d|d       ||j                         }d| d}n%|j                  j                  |g       }d|d| d}| j                  ||||z          y )	NzThe - is not bound, it will never have any errors.z does not contain the field rB   zThe non-field errors of  don't match.zThe errors of field z on )is_boundra   fieldsnon_field_errorserrorsr  r   )rc   formfieldrP  r   	form_reprfield_errorsfailure_messages           rP   _assert_form_errorz!SimpleTestCase._assert_form_error  s    }}II,d9+ . 
 dkk!9II,d9+-I%RST =002L 8=QO;;??5"5L&uitI;mL  	vzO/KLrW   c                 X    |r|dz  }t        |      }| j                  ||||d|       y)a>  
        Assert that a field named "field" on the given form object has specific
        errors.

        errors can be either a single error message or a list of errors
        messages. Using errors=[] test that the field has no errors.

        You can pass field=None to check the form's non-field errors.
        r  form N)rV   rV  )rc   rQ  rR  rP  r   s        rP   assertFormErrorzSimpleTestCase.assertFormError  s7     $JeVZ5AQRrW   c           
         ||t        d      |r|dz  }t        |      }|j                  s| j                  | d|d       |I||j	                         k\  r6|j	                         }|dkD  rdnd}| j                  | d|d	| d
| d       |+d| d|}| j                  |j                  |   ||||       yd|d}	| j                  |j                         |||	z          y)aE  
        Similar to assertFormError() but for formsets.

        Use form_index=None to check the formset's non-form errors (in that
        case, you must also use field=None).
        Otherwise use an integer to check the formset's n-th form for errors.

        Other parameters are the same as assertFormError().
        Nz-You must use field=None with form_index=None.r  zThe formset rK  r}   formsrQ  z
 only has  rB   rX  z of formset zThe non-form errors of formset rL  )	r  rV   rM  ra   total_form_countrV  r[  r   non_form_errors)
rc   formset
form_indexrR  rP  r   
form_countform_or_formsrS  rU  s
             rP   assertFormSetErrorz!SimpleTestCase.assertFormSetError  s)    %"3LMM$JII,l7+ 6  !jG4L4L4N&N 113J'1A~G6MII,l7+Z
|1 /$ !
|<{CI##j)5&*i !@{-XO'')6:3OrW   c                    ||t        d      |r|dz  }||| j                  |d|       t        |d      r||r|r|}d }|d |fS |j                  D cg c]  }|j                  |j                   }}d ||fS c c}w )Nz7response and/or template_name argument must be providedr  	templates)rG   rI  r
  re  r   )rc   r  r   r   rH  r   template_namess          rP   _get_template_usedz!SimpleTestCase._get_template_used  s     5UVV$J$)=,,X{KPx-(2B} ( $
22*2*<*<S*<Q@R!&&*<S^Z// Ts   A>)A>c                    |s| j                  |dz          | j                  ||v |d|ddj                  |      z          |;| j                  |j	                  |      ||d|||j	                  |      fz  z          y y )Nz(No templates used to render the responser   zK' was not a template used to render the response. Actual template(s) used: , zZTemplate '%s' was expected to be rendered %d time(s) but was actually rendered %d time(s).)ra   r  r   r   r   )rc   r   rf  r   r   s        rP   r   z$SimpleTestCase._assert_template_used  s    IIj#MMN^+dii79 9	
 $$]3 @ %)=)=m)LMN N rW   c                 |    | j                  |||d      \  }}}|rt        | |||      S | j                  ||||       y)z
        Assert that the template with the provided name was used in rendering
        the response. Also usable as context manager.
        assertTemplateUsedN)rg  r   r   )rc   r  r   r   r   context_mgr_templaterf  s          rP   rk  z!SimpleTestCase.assertTemplateUsed  s[     <@;R;R 	<
8nj  -*J  	""=.*eTrW   c                     | j                  |||d      \  }}}|rt        | ||      S | j                  ||v |d|z  z          y)z
        Assert that the template with the provided name was NOT used in
        rendering the response. Also usable as context manager.
        assertTemplateNotUsedz=Template '%s' was used unexpectedly in rendering the responseN)rg  r   r   )rc   r  r   r   rl  rf  s         rP   rn  z$SimpleTestCase.assertTemplateNotUsed   sg    
 <@;R;R#	<
8nj  07KZXX^+M	
rW   c           	   #      K    ||      5 }| d d d        | j                  |t        t        |                   y # 1 sw Y   /xY wwrn   )assertInr#  r   )rc   funccm_attrexpected_exceptionexpected_messagerJ   s         rP   _assert_raises_or_warns_cmz)SimpleTestCase._assert_raises_or_warns_cm6  s@      $%H &&GB,@(AB &%s   	A
>.A
AA
c                     d }|r|^}}| j                  ||||      }||S |5   ||i | d d d        y # 1 sw Y   y xY wrn   )ru  )	rc   rq  rr  rs  rt  r   r   callable_objrJ   s	            rP   _assertFooMessagez SimpleTestCase._assertFooMessage>  sX     "&L4,,'-/?
 I$)&) RRs   	5>c                 H     | j                   | j                  d||g|i |S )ac  
        Assert that expected_message is found in the message of a raised
        exception.

        Args:
            expected_exception: Exception class expected to be raised.
            expected_message: expected error message string value.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
        	exception)rx  assertRaises)rc   rs  rt  r   r   s        rP   assertRaisesMessagez"SimpleTestCase.assertRaisesMessageN  s?     &t%%	

 
 
 	
rW   c                 H     | j                   | j                  d||g|i |S )zf
        Same as assertRaisesMessage but for assertWarns() instead of
        assertRaises().
        warning)rx  assertWarns)rc   expected_warningrt  r   r   s        rP   assertWarnsMessagez!SimpleTestCase.assertWarnsMessaged  s?    
 &t%%	

 
 
 	
rW   c                 l   |g }|i } ||i |} ||i i |ddi}|j                         D ]G  \  }	}
| j                  |j                  |	      |
       | j                  |j                  |	      |
       I |j                         D ]  \  }	}| j                  t              5 }|j                  |	       ddd       | j                  j
                  j                  |       | j                  t              5 }|j                  |	       ddd       | j                  |j
                  j                  |        |j                  d   g}|j                  D ]x  }| j                  t              5 }|j                  |       ddd       | j                  j
                  j                  |       | j                  |j                  |      |       z t        |t              r-|j                  ddd       | j                   ||i ||       yy# 1 sw Y   \xY w# 1 sw Y   xY w# 1 sw Y   xY w)aO  
        Assert that a form field behaves correctly with various inputs.

        Args:
            fieldclass: the class of the field to be tested.
            valid: a dictionary mapping valid inputs to their expected
                    cleaned values.
            invalid: a dictionary mapping invalid inputs to one or more
                    raised error messages.
            field_args: the args passed to instantiate the field
            field_kwargs: the kwargs passed to instantiate the field
            empty_value: the expected clean output for inputs in empty_values
        NrequiredF      )
min_length
max_length)r   r   cleanr{  r   rz  messageserror_messagesempty_values
issubclassr*   updateassertIsInstance)rc   
fieldclassvalidinvalid
field_argsfield_kwargsempty_valuer  optionalinputoutputrP  context_managererror_requiredrh   s                  rP   assertFieldOutputz SimpleTestCase.assertFieldOutputr  s   , JLz:\:zQ-P-Pj%-PQ"[[]ME6X^^E2F;X^^E2F; + %]]_ME6""?3u% 4_66??H""?3u% 4_66??H - #11*=>&&A""?3q! 4_66??PX^^A.<	 ' j),q CD!!*j"IL"I:V - 43 43 43s$   $H9H/H*H	H'	*H3	c           	         t        | ||d      }t        | ||d      }||k7  rt        |d      dt        |d      }ddj                  t        j                  t        |      j                         t        |      j                                     z   }| j                  ||      }| j                  | j                  ||             yy)z
        Assert that two HTML snippets are semantically the same.
        Whitespace in most cases is ignored, and attribute ordering is not
        significant. The arguments must be valid HTML.
        !First argument is not valid HTML:r,  T != r`   N)
rj   r   r   difflibndiffr#  
splitlines_truncateMessagera   rb   )rc   html1html2rf   dom1dom2ri   diffs           rP   assertHTMLEqualzSimpleTestCase.assertHTMLEqual  s     %%A
 %%B
 4<(1$(=yt?TUK$))I((*I((* D //TBKIId))#{;< rW   c                     t        | ||d      }t        | ||d      }||k(  r=t        |d      dt        |d      }| j                  | j                  ||             yy)z>Assert that two HTML snippets are not semantically equivalent.r  r,  T == N)rj   r   ra   rb   )rc   r  r  rf   r  r  ri   s          rP   assertHTMLNotEqualz!SimpleTestCase.assertHTMLNotEqual  sk    $%A
 %%B
 4<(1$(=yt?TUKIId))#{;< rW   c                 &   t        | |d d      }t        | |d d      }|j                  |      }|r|dz  }t        |      }|3|dk(  r|d| }	nd| d|d| d	| }	| j                  ||| |	        y | j	                  |dk7  | d
|d|        y )Nr  r,  r  r   rD  r<  r=  r>  r?  r@  rA  )rj   r   r   r   r  )
rc   needlehaystackr   r   parsed_needleparsed_haystackr9  haystack_reprrf   s
             rP   assertInHTMLzSimpleTestCase.assertInHTML  s    -&$ C
 0(D"F
 %**=9
$J!(+zj O$o'  ZLvjE7 S//<o?  Z:,se0DEOOa!l.
:V$o'rW   c                 .    | j                  ||d|       y )Nr   )r   r   )r  )rc   r  r  r   s       rP   assertNotInHTMLzSimpleTestCase.assertNotInHTML  s    &(!
KrW   c                 D   	 t        j                  |      }t	        |t
              r	 t        j                  |      }| j                  ||       y# t         j                  $ r | j                  d|z         Y dw xY w# t        $ r | j                  d|z         Y aw xY w)z
        Assert that the JSON fragments raw and expected_data are equal.
        Usual JSON non-significant whitespace rules apply as the heavyweight
        is delegated to the json library.
        $First argument is not valid JSON: %r%Second argument is not valid JSON: %rrf   N)jsonrZ   JSONDecodeErrorra   rS   r#  r  r   rc   rawexpected_datarf   datas        rP   assertJSONEqualzSimpleTestCase.assertJSONEqual  s    	D::c?D mS)S $

= 9 	}#6 ## 	DII<sBC	D
  S		AMQRSs"   A A? 'A<;A<?BBc                 X   	 t        j                  |      }t	        |t
              r	 t        j                  |      }| j                  ||       y# t         j                  $ r | j                  d|z         Y dw xY w# t         j                  $ r | j                  d|z         Y kw xY w)z
        Assert that the JSON fragments raw and expected_data are not equal.
        Usual JSON non-significant whitespace rules apply as the heavyweight
        is delegated to the json library.
        r  r  r  N)r  rZ   r  ra   rS   r#  assertNotEqualr  s        rP   assertJSONNotEqualz!SimpleTestCase.assertJSONNotEqual   s    	D::c?D mS)S $

= 9 	D-S9 ## 	DII<sBC	D
 '' S		AMQRSs"   A A? 'A<;A<?'B)(B)c                    	 t        ||      }|st        |d      dt        |d      }ddj                  t        j                  |j                         |j                                     z   }| j                  ||      }| j                  | j                  ||             yy# t        $ r0}d|z  }| j                  | j                  ||             Y d}~yd}~ww xY w)z
        Assert that two XML snippets are semantically the same.
        Whitespace in most cases is ignored and attribute ordering is not
        significant. The arguments must be valid XML.
        Tr  r`   ,First or second argument is not valid XML
%sN)
r5   r   r   r  r  r  r  ra   rb   r   )rc   xml1xml2rf   rO   ri   r  rh   s           rP   assertXMLEqualzSimpleTestCase.assertXMLEqual  s    	A t,F
 dD)dD) diiMM$//"3T__5FG  #33KF		$--c;?@ 	  	=IAMKIId))#{;<<	=s   B$ $	C-&CCc                    	 t        ||      }|r=t        |d      dt        |d      }| j                  | j                  ||             yy# t        $ r0}d|z  }| j                  | j                  ||             Y d}~yd}~ww xY w)z
        Assert that two XML snippets are not semantically equivalent.
        Whitespace in most cases is ignored and attribute ordering is not
        significant. The arguments must be valid XML.
        Tr  r  N)r5   r   ra   rb   r   )rc   r  r  rf   rO   ri   rh   s          rP   assertXMLNotEqualz SimpleTestCase.assertXMLNotEqual(  s    	A t,F
 dD)dD) 		$--c;?@ 	  	=IAMKIId))#{;<<	=s   A 	B&BBrn   )F)i.     r   T)r   )Nr  r   F)r  r   F)NNr   N)NNr   )Nr   )9r   rH   rI   r/   r   r.   r   r   r   setr   r   r   classmethodr   r   r   r   r   r   r   r   r   r   r   r9   r   r   r6   r   r  r:  rB  rE  rI  rV  rY  rc  rg  r   rk  rn  r   ru  rx  r|  r  r  r  r  r  r  r  r  r  r  r   r   s   @rP   r=   r=      s    L$I	 &" < < ( (( 
 
, : : ) ).%"7
$L 		; 
	;+)  $u
n
4'?T PUB DI
*	M,S&P0(( GKU*
, C C* 
,
& 3Wj=0=@L7":"A.ArW   r=   c                        e Zd ZdZdZdZehZdZdZ	 fdZ
edd       Zd Zd Zd Z fd	Zd
 ZddZdeddZ xZS )r<   FNzDatabase %(operation)s to %(alias)r are not allowed in this test. Add %(alias)r to %(test)s.databases to ensure proper test isolation and silence this failure.c                    t         |           | j                  t        j                  | j                         t        j                  t        j                  j                  d| j                  d       | j                  d      D ]  }t        dd|        	 | j                          | j                  d      D ]#  }t         |   j"                  j%                          % y# t        $ ra | j                  St        j                          t        j                  t        j                  j                  dt        j                  d        w xY w)	a\  
        Perform pre-test setup:
        * If the class has an 'available_apps' attribute, restrict the app
          registry to these applications, then fire the post_migrate signal --
          it must run with the correct set of applications for the test case.
        * If the class has a 'fixtures' attribute, install those fixtures.
        NINSTALLED_APPSTr   settingrU   rM   Finclude_mirrorsr   )	verbosityinteractivedb)rq   r   available_appsr   set_available_appsr#   sendr   _wrappedrs   _databases_namesr    _fixture_setupr   unset_available_appsr  r&   queries_logclearrc   db_namers   s     rP   r   zTransactionTestCase._pre_setupT  s     	*##D$7$78  ((22())	  000G(1%GT H	! ,,U,CG ,,224 D  		"".))+$$#,,66,"11	 		s   C% %A*Ec                     t         D cg c]-  }|| j                  v r|st         |   j                  d   d   s|/ c}S c c}w )NTESTMIRROR)r&   r   settings_dict)rL   r  r   s      rP   r  z$TransactionTestCase._databases_namesy  sP    
 %
$%"5)77?I $
 	
 
s   2>c                    t         |   }|j                  j                  r|j                  j	                  t               |j                  j                               }|rRt        j                  |      5  |j                         5 }|D ]  }|j                  |        	 d d d        d d d        y y y # 1 sw Y   xY w# 1 sw Y   y xY w)Nusing)r&   featuressupports_sequence_resetopssequence_reset_by_name_sqlr   introspectionsequence_listr'   atomicr   execute)rc   r  connsql_listr   rv   s         rP   _reset_sequencesz$TransactionTestCase._reset_sequences  s    7#==00xx::
D..<<>H  ''g6&#+C"NN3/ $, ' 76 	 1 ' 76s$   4B>B2B>2B;	7B>>Cc                    | j                  d      D ]  }| j                  r| j                  |       | j                  rt	        t
        |   d      r~| j                  t        j                          t
        |   j                  j                  t
        |   j                         | j                  t        j                  | j                         | j                  st        dg| j                  d|d  y )NFr  _test_serialized_contentsloaddatar   r  database)r  reset_sequencesr  serialized_rollbackr
  r&   r  r   r  creationdeserialize_db_from_stringr  r  fixturesr   )rc   r  s     rP   r  z"TransactionTestCase._fixture_setup  s    ,,U,CG##%%g. ''GG$&A- &&2--/G$--HH(BB &&2++D,?,?@}}ZW$--W1wW% DrW   c                      yNTrw   r   s    rP   _should_reload_connectionsz.TransactionTestCase._should_reload_connections  s    rW   c                 D   	 | j                          t        | 	          | j                         r+t	        j
                  d      D ]  }|j                           | j                  Tt        j                          t        j                  t        j                  j                  dt        j                  d       yy# | j                  Tt        j                          t        j                  t        j                  j                  dt        j                  d       w w xY w)a  
        Perform post-test things:
        * Flush the contents of the database to leave a clean slate. If the
          class has an 'available_apps' attribute, don't fire post_migrate.
        * Force-close the connection so the next test gets a clean cursor.
        Tinitialized_onlyNr  Fr  )_fixture_teardownrq   r   r  r&   allcloser  r   r  r#   r  r   r  rs   r  )rc   r  rs   s     rP   r   z"TransactionTestCase._post_teardown  s    	""$G"$..0 (OOTBDJJL C "".))+$$#,,66,"11	 /t"".))+$$#,,66,"11	 /s   AB= =A"Dc           
          | j                  d      D ]Q  }| j                  d uxs! | j                  xr t        t        |   d      }t        ddd|d| j                  d u|       S y )NFr  r  flushr   )r  r  r  r  allow_cascadeinhibit_post_migrate)r  r  r  r
  r&   r   )rc   r  r	  s      rP   r  z%TransactionTestCase._fixture_teardown  s     ,,U,CG ##4/  ,, SG 46QR ! !  %"11=%9 DrW   c                 $   t        |      }|}|t        ||      }|s&| j                  t        |      t        |      |      S t	        |      dkD  r#t        |d      r|j                  st        d      | j                  t        |      ||      S )Nr  r}   orderedzKTrying to compare non-ordered queryset against more than one ordered value.)	rT   mapassertDictEqualr   r   r
  r  r  r   )rc   qsvalues	transformr  rf   r   s          rP   assertQuerySetEqualz'TransactionTestCase.assertQuerySetEqual  s    f 	5)E''S'QQ v;?wr95bjj!  UV==rW   r  c                v    t         |   }t        | ||      }||S |5   ||i | d d d        y # 1 sw Y   y xY wrn   )r&   rl   )rc   rp   rq  r  r   r   r  r   s           rP   assertNumQueriesz$TransactionTestCase.assertNumQueries  s>    5!*4d;<N$!&! WWs   	/8)T)NTNrn   )r   rH   rI   r  r  r  r$   r   r   r  r   r  r  r  r  r  r   r  r  r  r   r   s   @rP   r<   r<   <  s}     O N H!"I	$   #5J 

 


0X*:.> "<L " "rW   r<   c                 d    | t        j                         nd | D        }t        d |D              S )zX
    Return whether or not all (or specified) connections support
    transactions.
    c              3   .   K   | ]  }t         |     y wrn   r&   rx   r   s     rP   r{   z3connections_support_transactions.<locals>.<genexpr>       6gUk% g   c              3   H   K   | ]  }|j                   j                    y wrn   )r  supports_transactionsrx   r  s     rP   r{   z3connections_support_transactions.<locals>.<genexpr>  s     Eutt}}22u    "r&   r  aliasesconnss     rP    connections_support_transactionsr"    s5     ? 	6g6 

 EuEEErW   c                 d    | t        j                         nd | D        }t        d |D              S )zR
    Return whether or not all (or specified) connections support savepoints.
    c              3   .   K   | ]  }t         |     y wrn   r  r  s     rP   r{   z1connections_support_savepoints.<locals>.<genexpr>  r  r  c              3   H   K   | ]  }|j                   j                    y wrn   )r  uses_savepointsr  s     rP   r{   z1connections_support_savepoints.<locals>.<genexpr>  s     ?t}},,r  r  r  s     rP   connections_support_savepointsr'    s5     ? 	6g6 

 ????rW   c                   ,    e Zd ZdZdZd Zd Zd Zd Zy)TestDataa  
    Descriptor to provide TestCase instance isolation for attributes assigned
    during the setUpTestData() phase.

    Allow safe alteration of objects assigned in setUpTestData() by test
    methods by exposing deep copies instead of the original objects.

    Objects are deep copied using a memo kept on the test case instance in
    order to maintain their original relationships.
    _testdata_memoc                      || _         || _        y rn   r   r  )rc   r   r  s      rP   rr   zTestData.__init__   s    		rW   c                     	 t        || j                        }|S # t        $ r i }t        || j                  |       Y |S w xY wrn   )r   	memo_attrrF   r   )rc   testcasememos      rP   get_memozTestData.get_memo$  sI    	48T^^4D   	4DHdnnd3	4s    "A A c                     || j                   S | j                  |      }t        | j                   |      }t        || j                  |       |S rn   )r  r1  r   r   r   )rc   instanceownerr0  r  s        rP   __get__zTestData.__get__,  sE    99}}X&		4($))T*rW   c                 <    d| j                   d| j                  dS )Nz<TestData: name=z, data=>r,  r   s    rP   __repr__zTestData.__repr__4  s    15DIIFFrW   N)	r   rH   rI   __doc__r.  rr   r1  r5  r8  rw   rW   rP   r)  r)    s#    	 !IGrW   r)  c                        e Zd ZdZed        Zed        Zed        Zed        Ze fd       Z	e fd       Z
ed        Z fd	Z fd
Z fdZd Zeeeddd              Z xZS )r;   a  
    Similar to TransactionTestCase, but use `transaction.atomic()` to achieve
    test isolation.

    In most situations, TestCase should be preferred to TransactionTestCase as
    it allows faster execution. However, there are some situations where using
    TransactionTestCase might be necessary (e.g. testing some transactional
    behavior).

    On database backends with no transaction support, TestCase behaves as
    TransactionTestCase.
    c                     i }| j                         D ]4  }t        j                  |      }d|_        |j	                          |||<   6 |S )z*Open atomic blocks for multiple databases.r  T)r  r'   r  _from_testcaserD   )rL   atomicsr  r  s       rP   _enter_atomicszTestCase._enter_atomicsF  sQ     ++-G ''g6F$(F!%GG	 .
 rW   c                     t        | j                               D ]/  }t        j                  d|       ||   j	                  ddd       1 y)z5Rollback atomic blocks opened by the previous method.Tr  N)reversedr  r'   set_rollbackrE   )rL   r=  r  s      rP   _rollback_atomicszTestCase._rollback_atomicsQ  sC       4 4 67G$$T9G%%dD$7 8rW   c                 ,    t        | j                        S rn   )r"  r   rL   s    rP   _databases_support_transactionsz(TestCase._databases_support_transactionsX  s    />>rW   c                 ,    t        | j                        S rn   )r'  r   rD  s    rP   _databases_support_savepointsz&TestCase._databases_support_savepoints\  s    -cmm<<rW   c           	         t         |           | j                         r| j                         sy | j	                         | _        | j                  r2| j                  d      D ]  }	 t        dg| j                  d|d  | j                  j                         }	 | j                          | j                  j                         D ]0  \  }}||j                  |      ust!        | |t#        ||             2 y # t        $ r | j                  | j
                          w xY w# t        $ r | j                  | j
                          w xY w)NFr  r  r   r  )rq   r   rE  rG  r>  cls_atomicsr  r  r   r   rB  r   r   setUpTestDatar   r  r   r)  )rL   r  	pre_attrsr   rU   rs   s        rP   r   zTestCase.setUpClass`  s3   //1113,,.<<///F	 " #$!(	 G LL%%'		 <<--/KD%IMM$//T8D%#89 0 ! ))#//:  	!!#//2	s   (C=D& =&D#&&Ec                     | j                         rV| j                         rF| j                  | j                         t	        j
                  d      D ]  }|j                           t        | !          y )NTr  )	rE  rG  rB  rI  r&   r  r  rq   tearDownClass)rL   r  rs   s     rP   rM  zTestCase.tearDownClass  sV     //1113!!#//2#>

 ?rW   c                      y)z#Load initial data for the TestCase.Nrw   rD  s    rP   rJ  zTestCase.setUpTestData  s     	rW   c                 B    | j                         ryt        | 	         S )NF)rE  rq   r  )rc   rs   s    rP   r  z#TestCase._should_reload_connections  s     //1w133rW   c                 z   | j                         s| j                          t        |          S | j                  rt        d      | j                         | _        | j                         sP| j                  r3| j                  d      D ]  }t        dg| j                  i d|d   | j                          y y )Nz4reset_sequences cannot be used on TestCase instancesFr  r  r   r  )rE  rJ  rq   r  r  rG   r>  r=  rG  r  r  r   r  s     rP   r  zTestCase._fixture_setup  s    335  7)++RSS**,113}}#44U4KG " )*w?  L   4rW   c                 X   | j                         st        | 	         S 	 t        | j	                               D ]2  }| j                  t        |         st        |   j                          4 	 | j                  | j                         y # | j                  | j                         w xY wrn   )
rE  rq   r  r@  r  _should_check_constraintsr&   check_constraintsrB  r=  r  s     rP   r  zTestCase._fixture_teardown  s    3357,..	1#D$9$9$;<11+g2FG(::< = ""4<<0D""4<<0s   4B B B)c                 r    |j                   j                  xr  |j                   xr  |j                         S rn   )r  can_defer_constraint_checksneeds_rollback	is_usable)rc   r%   s     rP   rR  z"TestCase._should_check_constraints  s:    ;; '---'$
$$&	
rW   F)r  r  c          	   #   \  K   g }t        t        |   j                        }	 | 	 t        t        |   j                        }t        |   j                  |d D ],  \  }}}|j                  |       |s|r		  |        & |        . |t        t        |   j                        k(  ry|}# t        $ r0}	t
        j                  d|j                   d|	d       Y d}	~	d}	~	ww xY w# 	 t        t        |   j                        }t        |   j                  |d D ]h  \  }}}|j                  |       |s|rE	  |        &# t        $ r0}	t
        j                  d|j                   d|	d       Y d}	~	Zd}	~	ww xY w |        j |t        t        |   j                        k(  rw |}xY ww)z=Context manager to capture transaction.on_commit() callbacks.TNzError calling z in on_commit() (%s).)r   )r   r&   run_on_commitr   r   loggererrorrI   )
rL   r  r  	callbacksstart_countcallback_countr   callbackrobustrh   s
             rP   captureOnCommitCallbacksz!TestCase.captureOnCommitCallbacks  s     	+e,::;	-O!$[%7%E%E!F+6u+=+K+KL,'Ax $$X.!" (
 %J!,$ "SU);)I)I%JJ,-  $- " &&4X5J5J4K L8 %9$%-1	 !- !" !"" !$[%7%E%E!F+6u+=+K+KL,'Ax $$X.!" (
#, " &&4X5J5J4K L8 %9$%-1	 !- !" !"" %J!,$ "SU);)I)I%JJ,- s}   F,C' AF,4F,7B+>-F,+	C$4&CF,C$$F,'AF)6F)9E F)	E:	
&E5	0F)5E:	:/F))F,)r   rH   rI   r9  r  r>  rB  rE  rG  r   rM  rJ  r  r  r  rR  r   r$   ra  r   r   s   @rP   r;   r;   8  s       8 8 ? ? = = : :>      4
!(1
 /? -  -rW   r;   c                   $    e Zd ZdZd Zd ZddZy)CheckConditionz1Descriptor class for deferred condition checking.c                     || _         y rn   )
conditions)rc   re  s     rP   rr   zCheckCondition.__init__  s	    $rW   c                 B     | j                   g | j                  ||f S rn   )rs   re  )rc   	conditionreasons      rP   add_conditionzCheckCondition.add_condition  s$    t~~DtDF0CDDrW   Nc                     t        d |j                  D              ry| j                  D ]  \  }} |       sd|_        ||_         y y)Nc              3   6   K   | ]  }t        |d d        yw)r   FN)r   )rx   bases     rP   r{   z)CheckCondition.__get__.<locals>.<genexpr>  s     S]Twt0%8]r|   TF)any	__bases__re  r   __unittest_skip_why__)rc   r3  rL   rg  rh  s        rP   r5  zCheckCondition.__get__  sG    SS]]SS!%Iv{(,%,2) "1 rW   rn   )r   rH   rI   r9  rr   ri  r5  rw   rW   rP   rc  rc    s    ;%E
rW   rc  c                       fd}|S )Nc                     t         t              rt         t        j                        st                fd       }|S  t        dd       }|rt        j                  |vrfd j                  j                  d      }t        |t              r|j                        _        S |durt        f      _        S )Nc            
      H   | r|t        | d   t        j                        r_t        j                  t        | d   di       vr?t        d| d   d| d   j                  j                  dt        j                  d              rt        j                         | i |S )Nr   r    cannot be used on z as z# doesn't allow queries against the z
 database.)
rS   unittestr;   r%   r   r   r  rs   rI   SkipTest)r   r   rg  r   rh  	test_funcs     rP   skip_wrapperz6_deferredSkip.<locals>.decorator.<locals>.skip_wrapper  s     "47H,=,=>"((Qb0QQ$ ! G G--::&,,	 	 ;"++F33 $1&11rW   r   c                  H    t         ddt        j                  d      )Nrs  z* as it doesn't allow queries against the 'z' database.)r  r%   r   )r   	test_items   rP   rg  z3_deferredSkip.<locals>.decorator.<locals>.condition  s&    $ !%&,, rW   r   T)rS   rC   r  rt  r;   r   r   r%   r   r   r  rc  ri  r   )rv  rw  r   skipry  rg  r   rh  s   `   @rP   	decoratorz _deferredSkip.<locals>.decorator  s     y$'Jy(BSBS,T 92 2( %I2 - "I	;=I
 0 0	 A	 %%))*=>D$/.2.@.@F.S	+  T!.<i=P.Q	+rW   rw   )rg  rh  r   r{  s   ``` rP   _deferredSkipr|    s    4l rW   c                  H     t         fdddj                         z  d      S )zASkip a test if a database has at least one of the named features.c                  (    t        d  D              S )Nc              3   R   K   | ]  }t        t        j                  |d        ! ywFNr   r%   r  rx   features     rP   r{   z4skipIfDBFeature.<locals>.<lambda>.<locals>.<genexpr>/  s#      
HPWGJ''%8   %'rm  r  s   rP   <lambda>z!skipIfDBFeature.<locals>.<lambda>/  s     
HP
 
rW   zDatabase has feature(s) %sri  r>   r|  r   r  s   `rP   r>   r>   ,  s+    	
 	%tyy':: rW   c                  H     t         fdddj                         z  d      S )z9Skip a test unless a database has all the named features.c                  *    t        d  D               S )Nc              3   R   K   | ]  }t        t        j                  |d        ! ywr  r  r  s     rP   r{   z8skipUnlessDBFeature.<locals>.<lambda>.<locals>.<genexpr>:  #      
HPWGJ''%8r  )r  r  s   rP   r  z%skipUnlessDBFeature.<locals>.<lambda>:      C 
HP
 
 
rW   z'Database doesn't support feature(s): %sri  r?   r  r  s   `rP   r?   r?   7  s+    	
 	2DIIh4GG rW   c                  H     t         fdddj                         z  d      S )z<Skip a test unless a database has any of the named features.c                  *    t        d  D               S )Nc              3   R   K   | ]  }t        t        j                  |d        ! ywr  r  r  s     rP   r{   z;skipUnlessAnyDBFeature.<locals>.<lambda>.<locals>.<genexpr>E  r  r  r  r  s   rP   r  z(skipUnlessAnyDBFeature.<locals>.<lambda>E  r  rW   z2Database doesn't support any of the feature(s): %sri  skipUnlessAnyDBFeaturer  r  s   `rP   r  r  B  s+    	
 	=tyy?RR  rW   c                       e Zd ZdZd Zy)QuietWSGIRequestHandlerz
    A WSGIRequestHandler that doesn't log to standard output any of the
    requests received, so as to not clutter the test result output.
    c                       y rn   rw   )r   s    rP   log_messagez#QuietWSGIRequestHandler.log_messageS  s    rW   N)r   rH   rI   r9  r  rw   rW   rP   r  r  M  s    
rW   r  c                   H     e Zd ZdZ fdZd Zd Z fdZd Z fdZ	 xZ
S )FSFilesHandlerz
    WSGI middleware that intercepts calls to a directory, as defined by one of
    the *_ROOT settings, and serves those files, publishing them under *_URL.
    c                 l    || _         t        | j                               | _        t        |           y rn   )applicationr   get_base_urlbase_urlrq   rr   )rc   r  rs   s     rP   rr   zFSFilesHandler.__init__]  s+    & !2!2!45rW   c                 b    |j                  | j                  d         xr | j                  d    S )z
        Check if the path should be handled. Ignore the path if:
        * the host is provided as part of the base_url
        * the request's path isn't under the media path (or equal)
        r  r}   )r  r  )rc   r  s     rP   _should_handlezFSFilesHandler._should_handleb  s-     t}}Q/0Iq9I5IIrW   c                 T    |j                  | j                  d         }t        |      S )z?Return the relative path to the file on disk for the given URL.r  )removeprefixr  r   )rc   r  relative_urls      rP   	file_pathzFSFilesHandler.file_pathj  s&    ''a(89L))rW   c                     ddl m} | j                  |j                        r	 | j	                  |      S t
        |   |      S # |$ r Y w xY w)Nr   )Http404)django.httpr  r  r  r:   rq   get_response)rc   r  r  rs   s      rP   r  zFSFilesHandler.get_responseo  sR    'w||,zz'** w#G,,  s   A AAc                     | j                  |j                        }t        j                  t	        |            }|j                  dd      j                  d      }t        ||| j                               S )N\r  )document_root)	r  r  	posixpathnormpathr   replacelstripr:   get_base_dir)rc   r  os_rel_pathfinal_rel_paths       rP   r:   zFSFilesHandler.servey  s`    nnW\\2(()=> %,,T37>>sCWnD<M<M<OPPrW   c                 |    | j                  t        |            s| j                  ||      S t        |   ||      S rn   )r  r   r  rq   r   )rc   environstart_responsers   s      rP   r   zFSFilesHandler.__call__  s;    ""=#9:##G^<<w88rW   )r   rH   rI   r9  rr   r  r  r  r:   r   r   r   s   @rP   r  r  W  s-    

J*
-Q9 9rW   r  c                       e Zd ZdZd Zd Zy)_StaticFilesHandlerz
    Handler for serving static files. A private class that is meant to be used
    solely as a convenience by LiveServerThread.
    c                 "    t         j                  S rn   )r   STATIC_ROOTr   s    rP   r  z _StaticFilesHandler.get_base_dir  s    ###rW   c                 "    t         j                  S rn   )r   
STATIC_URLr   s    rP   r  z _StaticFilesHandler.get_base_url      """rW   Nr   rH   rI   r9  r  r  rw   rW   rP   r  r    s    
$#rW   r  c                       e Zd ZdZd Zd Zy)_MediaFilesHandlerz
    Handler for serving the media files. A private class that is meant to be
    used solely as a convenience by LiveServerThread.
    c                 "    t         j                  S rn   )r   
MEDIA_ROOTr   s    rP   r  z_MediaFilesHandler.get_base_dir  r  rW   c                 "    t         j                  S rn   )r   	MEDIA_URLr   s    rP   r  z_MediaFilesHandler.get_base_url  s    !!!rW   Nr  rw   rW   rP   r  r    s    
#"rW   r  c                   <     e Zd ZdZeZd fd	Zd ZddZd Z	 xZ
S )LiveServerThreadzBThread for running a live HTTP server while the tests are running.c                     || _         || _        t        j                         | _        d | _        || _        || _        t        | %          y rn   )
hostr  	threadingEventis_readyr[  static_handlerconnections_overriderq   rr   )rc   r  r  r  r  rs   s        rP   rr   zLiveServerThread.__init__  sA    		!)
,$8!rW   c                    | j                   r+| j                   j                         D ]  \  }}|t        |<    	 | j                  t	        t                           }| j                  | j                         | _        | j                  dk(  r| j                  j                  d   | _        | j                  j                  |       | j                  j                          | j                  j                          t        j                           y# t        $ r+}|| _        | j                  j                          Y d}~Dd}~ww xY w# t        j                           w xY w)zj
        Set up the live server and databases, and then loop over handling
        HTTP requests.
        )r  r   r}   N)r  r   r&   r  r  r   _create_serverhttpdr  server_addressset_appr  r  serve_foreverr   r[  	close_all)rc   r   r  handlerrh   s        rP   runzLiveServerThread.run  s   
 $$  $88>>@t%)E"  A	$))*<[]*KLG,,%)%>%> - DJ yyA~ JJ55a8	JJw'MMJJ$$&
 !!#	  	 DJMM	  !!#s*   B?D 	E!D<7E <EE Ec                 `    | j                  | j                  | j                  ft        d|      S )NF)allow_reuse_addressr  )server_classr  r  r  )rc   r  s     rP   r  zLiveServerThread._create_server  s3      YY		"# %!5	 ! 
 	
rW   c                     t        | d      r4| j                  j                          | j                  j                          | j	                          y )Nr  )r
  r  shutdownserver_closer   r   s    rP   	terminatezLiveServerThread.terminate  s5    4!JJ!JJ##%		rW   )Nr   rn   )r   rH   rI   r9  r!   r  rr   r  r  r  r   r   s   @rP   r  r    s    L%L$8
rW   r  c                        e Zd ZdZdZdZeZeZ	e
d        Ze
d        Zed        Ze fd       Zed        Zed	        Zed
        Z xZS )LiveServerTestCasea  
    Do basically the same as TransactionTestCase but also launch a live HTTP
    server in a separate thread so that the tests may use another testing
    framework, such as Selenium for example, instead of the built-in dummy
    client.
    It inherits from TransactionTestCase instead of TestCase because the
    threads don't share the same transactions (unless if using in-memory sqlite)
    and each thread needs to commit all their transactions so that the other
    thread can see the changes.
    	localhostr   c                 N    d| j                   d| j                  j                  S )Nzhttp://:)r  server_threadr  rD  s    rP   live_server_urlz"LiveServerTestCase.live_server_url  s    !$3+<+<+A+ABBrW   c                     | j                   S rn   )r  rD  s    rP   allowed_hostzLiveServerTestCase.allowed_host  s    xxrW   c                     i }t        j                         D ]2  }|j                  dk(  s|j                         s$|||j                  <   4 |S )Nsqlite)r&   r  vendoris_in_memory_dbr   rL   r  r  s      rP   _make_connections_overridez-LiveServerTestCase._make_connections_override  sI    !OO%D {{h&4+?+?+A37$TZZ0	 &
 $#rW   c                     t         |           | j                  t        d| j                  i             | j                          y )Nr   )r  )rq   r   r   r6   r  _start_server_threadr   s    rP   r   zLiveServerTestCase.setUpClass  s=    8S5E5E*FG	
 	  "rW   c                    | j                         }|j                         D ]  }|j                           | j                  |      | _        d| j                  _        | j                  j                          | j                  | j                         | j                  j                  j                          | j                  j                  r| j                  j                  y r  )r  r  inc_thread_sharing_create_server_threadr  daemonr~   r   _terminate_threadr  waitr[  r  s      rP   r  z'LiveServerTestCase._start_server_thread  s    "==?(//1D##% 2  556JK#' !C112 	""'')""##))) #rW   c                 h    | j                  | j                  | j                  || j                        S )N)r  r  )server_thread_classr  r  r  )rL   r  s     rP   r  z(LiveServerTestCase._create_server_thread  s4    &&HH!5	 ' 
 	
rW   c                     | j                   j                          | j                   j                  j                         D ]  }|j	                           y rn   )r  r  r  r  dec_thread_sharing)rL   r  s     rP   r  z$LiveServerTestCase._terminate_thread!  sB     	##%%%::AACD##% DrW   )r   rH   rI   r9  r  r  r  r  r  r  r8   r  r  r  r  r   r  r  r  r   r   s   @rP   r  r    s    	 DD*(NC C   $ $ # # * *  
 
 & &rW   r  c                   :     e Zd ZdZdZ fdZe fd       Z xZS )SerializeMixina  
    Enforce serialization of TestCases that share a common resource.

    Define a common 'lockfile' for each set of TestCases to serialize. This
    file must exist on the filesystem.

    Place it early in the MRO in order to isolate setUpClass()/tearDownClass().
    Nc                    t        |   di | | j                  $t        dj	                  | j
                              y )NzB{}.lockfile isn't set. Set it to a unique value in the base class.rw   )rq   __init_subclass__lockfiler  formatr   )rL   r   rs   s     rP   r  z SerializeMixin.__init_subclass__6  sB    !+F+<<%%+VCLL%9   rW   c                     t        | j                        | _        | j                  | j                  j                         t        j                  | j                  t
        j                         t        | %          y rn   )
openr  	_lockfiler   r  r   lockLOCK_EXrq   r   r   s    rP   r   zSerializeMixin.setUpClass>  sL    S\\*CMM//0

3==%--0rW   )	r   rH   rI   r9  r  r  r  r   r   r   s   @rP   r  r  *  s(     H  rW   r  rn   )r  r  loggingrY   r  r   r  rt  collectionsr   
contextlibr   r   r   r   	functoolsr   r	   unittest.suiter
   unittest.utilr   urllib.parser   r   r   r   r   r   r   urllib.requestr   asgiref.syncr   r   django.appsr   django.confr   django.corer   django.core.exceptionsr   r   django.core.filesr   django.core.handlers.wsgir   r   django.core.managementr   django.core.management.colorr   django.core.management.sqlr    django.core.servers.basehttpr!   r"   django.core.signalsr#   	django.dbr$   r%   r&   r'   django.db.backends.base.baser(   r)   django.forms.fieldsr*   r  r+   django.http.requestr,   r-   django.test.clientr.   r/   django.test.htmlr0   r1   django.test.signalsr2   django.test.utilsr3   r4   r5   r6   r7   django.utils.functionalr8   django.utils.versionr9   django.views.staticr:   	getLoggerrZ  r   rQ   rV   r^   rj   rl   r   r   AssertionErrorr   r   r;   r=   r<   r"  r'  r)  rc  r|  r>   r?   r  r  r  r  r  Threadr  r  r  rw   rW   rP   <module>r"     s        
    %  %   ' #   ( ;     H # @ / 1 ? O / L L I ) ! @ 2 7 1  2 & %			=	)  	
4 
4 B	
$> 	
	 	7 7pAX&& pAfz". z"z
F	@#G #GLa-" a-H ,7t0 .9[ .9b
#. 
#
" 
"7y'' 7tK&, K&\ rW   