
    h                    B   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	  S SK
Jr  S SKJrJr  S SK Jr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJrJrJrJrJrJrJr  S SKJr  S SK J!r!J"r"  S SK#J$r$  S SK%J&r&  S SK'J(r(  S SK)J*r*J+r+  S SK,J-r-  S SK.J/r/J0r0  S SK1J2r2  S SK3J4r4  S SK5J6r6  S SK7J8r8J9r9  S SK:J;r;  S SK<J=r=J>r>J?r?J@r@  S SKAJBrBJCrC  S SKDJErE  S SKFJGrG  S SKHJIrIJJrJ  S SKKJLrLJMrM  S SKNJOrOJPrP  S SKQJRrR  S S KSJTrTJUrUJVrVJWrWJXrX  S S!KYJZrZ  S S"K[J\r\  S S#K]J^r^  \R                  " S$5      r`S%ra\\(       d  S& rbS' rcS( rdS) re " S* S+\T5      rf " S, S-5      rg " S. S/\g5      rh " S0 S1\i5      rj " S2 S35      rk " S4 S5\R                  5      rm " S6 S7\m5      rnSRS8 jroSRS9 jrp " S: S;5      rq " S< S=\n5      rl " S> S?5      rrS@ rsSA rtSB ruSC rv " SD SE\95      rw " SF SG\/5      rx " SH SI\x5      ry " SJ SK\x5      rz " SL SM\R                  5      r| " SN SO\n5      r} " SP SQ5      r~g)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                     [        U 5      n UR                  nUR                  nU" U 5      nU" X@S S S 5        U$ ! [         a(    [	        SUR
                   SUR                   S35      S ef = f)N'.z6' object does not support the context manager protocol)type	__enter____exit__AttributeError	TypeError
__module____qualname__)cm
addcleanupclsenterexitresults         G/var/www/html/env/lib/python3.13/site-packages/django/test/testcases.py_enter_contextrQ   I   s    2h	MME<<D r4T4.  	CNN#1S%5%5$6 7+ , 	s	   : 2A,c                 6    [        U [        5      (       d  U /n U $ )z.Put value into a list if it's not already one.)
isinstancelist)values    rP   to_listrV   Y   s    eT""L    c                      [         R                  " [         R                  " U 5      5        g! [        [        [         R
                  4 a     gf = f)zP
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                      [        U5      nU$ ! [         a4  nU< SU< 3nU R                  U R                  X&5      5         S nAW$ S nAff = f)N
)r1   r0   fail_formatMessage)selfhtmluser_msgmsgdomestandardMsgs          rP   assert_and_parse_htmlrj   l   sS    > J  >"%q)		$%%h<==J>s    
A)AAc                   4   ^  \ rS rSrU 4S jrU 4S jrSrU =r$ )_AssertNumQueriesContextu   c                 <   > Xl         X l        [        TU ]  U5        g N)	test_casenumsuper__init__)rc   rp   rq   r%   	__class__s       rP   rs   !_AssertNumQueriesContext.__init__v   s    "$rW   c                   > [         TU ]  XU5        Ub  g [        U 5      nU R                  R	                  UU R
                  SUU R
                  SR                  S [        U R                  SS9 5       5      4-  5        g )Nz:%d queries executed, %d expected
Captured queries were:
%sr`   c              3   8   #    U  H  u  pS XS   4-  v   M     g7f)z%d. %ssqlN ).0iquerys      rP   	<genexpr>4_AssertNumQueriesContext.__exit__.<locals>.<genexpr>   s%      $M <00$Ms      )start)	rr   rE   lenrp   assertEqualrq   join	enumeratecaptured_queries)rc   exc_type	exc_value	tracebackexecutedrt   s        rP   rE   !_AssertNumQueriesContext.__exit__{   s}    i8t9""HHJ		 $-d.C.C1$M 	
rW   )rq   rp   )__name__rH   rI   __firstlineno__rs   rE   __static_attributes____classcell__rt   s   @rP   rl   rl   u   s    %

 
rW   rl   c                   6    \ rS rSrS	S jrS rS rS rS rSr	g)
_AssertTemplateUsedContext   Nc                 `    Xl         X l        X0l        X@l        / U l        [        5       U l        g ro   )rp   template_name
msg_prefixcountrendered_templatesr4   context)rc   rp   r   r   r   s        rP   rs   #_AssertTemplateUsedContext.__init__   s(    "*$
"$"}rW   c                     U R                   R                  U5        U R                  R                  [        U5      5        g ro   )r   appendr   r   )rc   sendersignaltemplater   kwargss         rP   on_template_render-_AssertTemplateUsedContext.on_template_render   s,    &&x0DM*rW   c                     U R                   R                  U R                  U R                   Vs/ s H  oR                  c  M  UR                  PM     snU R
                  U R                  5        g s  snf ro   )rp   _assert_template_usedr   r   namer   r   )rc   ts     rP   test_AssertTemplateUsedContext.test   sR    ,,!44K4VQVV4KOOJJ		
Ks   A1
A1
c                 F    [         R                  " U R                  5        U $ ro   )r2   connectr   rc   s    rP   rD   $_AssertTemplateUsedContext.__enter__   s    !!$"9"9:rW   c                 l    [         R                  " U R                  5        Ub  g U R                  5         g ro   )r2   
disconnectr   r   )rc   r   r   r   s       rP   rE   #_AssertTemplateUsedContext.__exit__   s(    $$T%<%<=		rW   )r   r   r   r   r   rp   ) N)
r   rH   rI   r   rs   r   r   rD   rE   r   ry   rW   rP   r   r      s    %+
rW   r   c                       \ rS rSrS rSrg)_AssertTemplateNotUsedContext   c                     U R                    Vs/ s H  oR                  c  M  UR                  PM     nnU R                  R                  U R                  U;   U R
                   SU R                   S35        g s  snf )N
Template 'z1' was used unexpectedly in rendering the response)r   r   rp   assertFalser   r   )rc   r   rendered_template_namess      rP   r   "_AssertTemplateNotUsedContext.test   sx     33#
3qvvFAFF3 	  #
 	"""99z$*<*<)= >5 6	
#
s
   A9A9ry   N)r   rH   rI   r   r   r   ry   rW   rP   r   r      s    
rW   r   c                       \ rS rSrSrg)DatabaseOperationForbidden   ry   N)r   rH   rI   r   r   ry   rW   rP   r   r      s    rW   r   c                        \ rS rSrS rS rSrg)_DatabaseFailure   c                     Xl         X l        g ro   )wrappedmessage)rc   r   r   s      rP   rs   _DatabaseFailure.__init__   s    rW   c                 ,    [        U R                  5      ero   )r   r   r   s    rP   __call___DatabaseFailure.__call__   s    (66rW   )r   r   N)r   rH   rI   r   rs   r   r   ry   rW   rP   r   r      s    7rW   r   c                     ^  \ rS rSr\r\rSrSr	\
" 5       rSr/ SQr\U 4S j5       r\S 5       r\S 5       r\S 5       r\S	 5       rS.S
 jrU 4S jrS rS/U 4S jjrS rS r\(       d  \S 5       rS rS r    S0S jrS1S jrS r  S2S jr! S3S jr"S r#S r$S1S jr%S1S jr&S r'S r( S4S jr)S5S jr*\+S  5       r,S! r-S" r.S# r/   S5S$ jr0S.S% jr1S.S& jr2S6S' jr3S1S( jr4S.S) jr5S.S* jr6S.S+ jr7S.S, jr8S-r9U =r:$ )7r=      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                 L  > [         TU ]  5         U R                  (       a$  U R                  [	        S0 U R                  D65        U R
                  (       a$  U R                  [        U R
                  5      5        U R                  5         U R                  U R                  5        g )Nry   )
rr   
setUpClass_overridden_settingsenterClassContextr7   _modified_settingsr6   _add_databases_failuresaddClassCleanup_remove_databases_failuresrL   rt   s    rP   r   SimpleTestCase.setUpClass   sv    ##!!"3"Oc6N6N"OP!!!!/#2H2H"IJ##%C::;rW   c                 T   U R                   S:X  a  [        [        5      $ U R                    He  nU[        ;  d  M  U R                  < SU R                  < SU< S3n[        U[        [        5      5      nU(       a  USUS   -  -  n[        U5      e   [        U R                   5      $ )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_databases"SimpleTestCase._validate_databases   s    ==I%[))]]EK'
 ((  !2%k9J K 2]15EEEG*733 # ''rW   c           
         U R                  5       U l        [         H  nXR                  ;   a  M  [        U   nU R                   HS  u  p4U R                  U R
                  < SU R                  < 3UUS.-  n[        X#5      n[        X#[        Xe5      5        MU     M     U R                  [        R                  R                  [        SU R                  5       S95        g )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   &SimpleTestCase._add_databases_failures   s    //1 E%$U+J#&#E#E66'*~~s7G7GH"!*: 
 !2
*:6*KL $F	 ! 	JJ##668  	
rW   c                     [          HS  nXR                  ;   a  M  [         U   nU R                   H&  u  p4[        X#5      n[	        X#UR
                  5        M(     MU     g ro   )r&   r   r   r   r   r   )rL   r   r%   r   _r   s         rP   r   )SimpleTestCase._remove_databases_failures  sM     E%$U+J== 2
&..9 >	 !rW   c                 8   ^ ^ [         R                  mU U4S jnU$ )Nc                 ^  > U R                   c  U R                  TR                  ;  ay  U R                  [        :w  ae  U R                  [        ;   aQ  TR
                  TR                   STR                   3U R                  SS.-  n[        U R                  U5      " 5       $ T" U /UQ70 UD6  g )NrB   zthreaded connectionsr   )
r%   r   r   r(   r&   r   rH   rI   r   r   )rc   argsr   r   rL   real_ensure_connections       rP   patched_ensure_connectionPSimpleTestCase.ensure_connection_patch_method.<locals>.patched_ensure_connection#  s    'JJcmm3JJ+-JJ+- 66"~~.a0@0@/AB!ZZ!7: 
 ((>(>HJJ"49$9&9rW   )r)   r   )rL   r   r   s   ` @rP   r   -SimpleTestCase.ensure_connection_patch_method  s    !4!F!F	:$ )(rW   c                 &    U R                  U5        g)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   SimpleTestCase.__call__7  s     	V$rW   c                    > [         TU ]  nUS   (       a;  SSS.nUR                  5        H   u  p4X2;   d  [        U5      (       d  M  XBU'   M"     U$ U$ )zB
Make SimpleTestCase picklable for parallel tests using subtests.
_outcomeN)r   _subtest)rr   __dict__itemsr^   )rc   statepickable_statekeyrU   rt   s        rP   __getstate__SimpleTestCase.__getstate__?  s]       *.DAN#kkm
(E0B0B&+s# , "!rW   c                 8    [        5       nU R                  USS9  g)z?Perform the same as __call__(), without catching the exception.T)debugN)r
   r   )rc   debug_results     rP   r  SimpleTestCase.debugP  s    #~\6rW   c                   > [        X R                  5      n[        U R                  SS5      =(       d    [        USS5      n[        U5      (       a  [	        X R                  [        U5      5        U(       d   U R                  5         U(       a  [        TU ]1  5         O[        TU ]5  U5        U(       d   U R                  5         gg! [         a0    U(       a  e UR                  U [        R                  " 5       5         gf = f! [         a0    U(       a  e UR                  U [        R                  " 5       5         gf = f)z
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   _testMethodNamert   r   r   r   
_pre_setup	ExceptionaddErrorsysexc_inforr   r  r   _post_teardown)rc   rO   r  
testMethodskippedrt   s        rP   r   SimpleTestCase._setup_and_callU  s     T#7#78
$..*=uE 
+UJ

 z**D..j0IJ! GMOGV$##%   clln5	  clln5	s$   9C 6D 7DD7D?>D?c                 n    U R                  5       U l        U R                  5       U l        / [        l        g)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	  SimpleTestCase._pre_setup{  s,     '') 335rW   c                     g)zPerform post-test things.Nry   r   s    rP   r  SimpleTestCase._post_teardown  s    rW   c                 ,    [        XR                  5      $ ro   )rQ   r   )rL   rJ   s     rP   r    SimpleTestCase.enterClassContext  s    !"&9&9::rW   c                     [        S0 UD6$ )zo
A context manager that temporarily sets a setting and reverts to the
original value when exiting the context.
ry   )r7   rc   r   s     rP   r   SimpleTestCase.settings  s    
 !*6**rW   c                     [        S0 UD6$ )z
A context manager that temporarily applies changes a list setting and
reverts back to the original value when exiting the context.
ry   )r6   r  s     rP   r6   SimpleTestCase.modify_settings  s    
 (((rW   c           
         U(       a  US-  n[        US5      (       a  U R                  UR                  USUR                  U4-  -   5        U R	                  UR                  S   S   UUSUR                  S   S   U4-  -   5        UR                  S   u  psU R	                  UR                  UUSUR                  U4-  -   5        GO{U R	                  UR                  UUSUR                  U4-  -   5        UR
                  n[        U5      u  ppnU
R                  S	5      (       d2  [        UR                  S
   U5      n[        UR                  S
   U
5      n
U(       a  [        U	5      u  pU(       a3  [        U[        R                  5      (       d  [        SU< SU< S35      eUR                  R                   =(       d    0 nUR                  R"                  =(       d    0 nUR                  R$                  " U
['        U5      4US:H  US.UD6nU R	                  UR                  UUSU
UR                  U4-  -   5        U R)                  UUUSU< SU< S3-   5        g)z
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pathr|   fragmentdomainportr3  r*  redirect_responses                     rP   assertRedirectsSimpleTestCase.assertRedirects  s   " $J8-..OO''$ ''5	66 ''*1-' **1-a0+>	??	  (66r:C$$"$ '');<	==	 $$$ ''5	66	 ,,C4<SM1FD ??3''h..{;SAx//<dC&  18-8N8N"O"O$
 	(  !--3"//117R$,OO$7$7e$% #g-#	%
 %!   %11&( .::<NO	PP	 	>A<PQ	
rW   c           
      x    S nU(       a  US-  nU R                  U" U5      U" U5      USU< SU< S3-   5        g)z
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           	          [        U 5      n [        U 5      u  pp4pV[        [        U5      5      n[	        XX4[        U5      U45      $ )z'Sort the URL's query string parameters.)strr   sortedr   r   r   )r.  r:  r;  r<  paramsr|   r=  query_partss           rP   	normalize0SimpleTestCase.assertURLEqual.<locals>.normalize  sH    c(C<DSM9FD% 5!12Ky/ExP rW   r#  z
Expected 'z' to equal 'z'.N)r   )rc   url1url2r   rI  s        rP   r5  SimpleTestCase.assertURLEqual  s?    	 $JdOdO4FF	
rW   c                    [        US5      (       a;  [        UR                  5      (       a!  UR                  (       d  UR                  5         U(       a  US-  nU R	                  UR
                  UUSUR
                  U4-  -   5        UR                  (       a  SR                  UR                  5      nOUR                  n[        U5      n[        U[        5      (       a  U(       a,  [        U5      nUR                  UR                  5      nSU-  nO[!        U5      nU(       a  [#        XS S5      n[#        XS S5      nUR%                  U5      n	XXG4$ )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+  callablerO  is_renderedr   r-  	streamingr   streaming_contentcontentr   rS   bytesrE  decodecharsetreprrj   r   )
rc   r6  textr-  r   rd   rU  content_repr	text_repr
real_counts
             rP   _assert_containsSimpleTestCase._assert_contains.  s2    Hh''))((OO$J    ( 4 4kBC C	
 hhx99:G&&G )$&&$t9DnnX%5%56GIT
I+t%LG )D"FD ]]4(
j>>rW   c                     U R                  XXEU5      u  pxpYUb"  U R                  UUU SU SU SU SU	 3	5        gU R                  US:g  U SU SU	 35        g)	a?  
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   r6  rZ  r   r-  r   rd   r\  r]  r[  s
             rP   assertContainsSimpleTestCase.assertContainsW  s     ;?:O:OKT;
7	z !l&N9+ N!!&'D\NT	 OOa!l.;W#n&rW   c                 d    U R                  XX4U5      u  pgpHU R                  USU U SU 35        g)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   r6  rZ  r-  r   rd   r\  r]  r[  s	            rP   assertNotContains SimpleTestCase.assertNotContainsw  sN     ;?:O:OKT;
7	z 	,yk *!N$		
rW   c                 @    [        X5      (       d  [        U S35      eg)zO
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+  r2  )rc   r6  	attributemethod_names       rP   _check_test_client_response*SimpleTestCase._check_test_client_response  s0    
 x++-  * *  ,rW   c                 V   UR                   (       d  U R                  U SU S35        Ub*  X!R                  ;  a  U R                  U SU SU< S35        Uc  UR                  5       nSU S3nO&UR                  R                  U/ 5      nSU< SU S3nU R                  XcXG-   5        g )	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errorsr4  r   )rc   formfieldrx  r   	form_reprfield_errorsfailure_messages           rP   _assert_form_error!SimpleTestCase._assert_form_error  s    }}II,d9+ . 
 kk!9II,d9+-I%RST =002L 8=QO;;??5"5L&uitI;mL  	z/KLrW   c                 `    U(       a  US-  n[        U5      nU R                  XX4SU< 35        g)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   r~  )rc   ry  rz  rx  r   s        rP   assertFormErrorSimpleTestCase.assertFormError  s3     $JV5AQRrW   c           
         Uc  Ub  [        S5      eU(       a  US-  n[        U5      nUR                  (       d  U R                  U SU< S35        UbK  X!R	                  5       :  a8  UR	                  5       nUS:  a  SOSnU R                  U SU< S	U S
U S35        Ub*  SU SU< 3nU R                  UR                  U   X4XX5        gSU< S3n	U R                  UR                  5       XEU	-   5        g)a  
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 rs  r   formsry  z
 only has  rB   r  z of formset zThe non-form errors of formset rt  )	r2  rV   ru  ra   total_form_countr~  r  r   non_form_errors)
rc   formset
form_indexrz  rx  r   
form_countform_or_formsr{  r}  s
             rP   assertFormSetError!SimpleTestCase.assertFormSetError  s!    %"3LMM$JII,l7+ 6  !j4L4L4N&N 113J'1A~G6MII,l7+Z
|1 /$ !
|<{CI##j)5* !@{-XO'')63OrW   c                 >   Uc  Uc  [        S5      eU(       a  US-  nUb  Ub  U R                  USU5        [        US5      (       a
  Uc  U(       a  U(       a  UnS nUS U4$ UR                   Vs/ s H  oUR                  c  M  UR                  PM     nnS Xc4$ s  snf )Nz7response and/or template_name argument must be providedr#  	templates)rG   rp  r+  r  r   )rc   r6  r   r   ro  r   template_namess          rP   _get_template_used!SimpleTestCase._get_template_used  s     5UVV$J$)=,,X{KPx--(2B} ( $
22*2*<*<S*<Q&!&&*<S^// Ts   0BBc                    U(       d  U R                  US-   5        U R                  X;   USU< SSR                  U5      < 3-   5        Ub:  U R                  UR	                  U5      UUSXUR	                  U5      4-  -   5        g g )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   r  r   r   s        rP   r   $SimpleTestCase._assert_template_used  s    IIj#MMN+dii79 9	
 $$]3 @ )=)=m)LMN N rW   c                 |    U R                  UUUS5      u  pVnU(       a  [        XX45      $ U R                  X&X45        g)zu
Assert that the template with the provided name was used in rendering
the response. Also usable as context manager.
assertTemplateUsedN)r  r   r   )rc   r6  r   r   r   context_mgr_templater  s          rP   r  !SimpleTestCase.assertTemplateUsed  sP     <@;R;R 	<
8j  -J  	""=*TrW   c                     U R                  UUUS5      u  pEnU(       a  [        XU5      $ U R                  X%;   USU-  -   5        g)zy
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)r  r   r   )rc   r6  r   r   r  r  s         rP   r  $SimpleTestCase.assertTemplateNotUsed   s`    
 <@;R;R#	<
8j  0ZXX+M	
rW   c           	   #      #    U" U5       nUv   S S S 5        U R                  U[        [        WU5      5      5        g ! , (       d  f       N4= f7fro   )assertInrE  r   )rc   funccm_attrexpected_exceptionexpected_messagerJ   s         rP   _assert_raises_or_warns_cm)SimpleTestCase._assert_raises_or_warns_cm6  s?      $%H &&GB,@(AB &%s   	A>.A
AAc                     S nU(       a  UtpuU R                  XX45      nUc  U$ U   U" U0 UD6  S S S 5        g ! , (       d  f       g = fro   )r  )	rc   r  r  r  r  r   r   callable_objrJ   s	            rP   _assertFooMessage SimpleTestCase._assertFooMessage>  sQ     "&L,,-
 I$)&) RRs	   	8
Ac                 H    U R                   " U R                  SUU/UQ70 UD6$ )a#  
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)r  assertRaises)rc   r  r  r   r   s        rP   assertRaisesMessage"SimpleTestCase.assertRaisesMessageN  s=     %%	

 
 
 	
rW   c                 H    U R                   " U R                  SUU/UQ70 UD6$ )zN
Same as assertRaisesMessage but for assertWarns() instead of
assertRaises().
warning)r  assertWarns)rc   expected_warningr  r   r   s        rP   assertWarnsMessage!SimpleTestCase.assertWarnsMessaged  s=    
 %%	

 
 
 	
rW   c                    Uc  / nUc  0 nU" U0 UD6nU" U0 0 UESS0ED6nUR                  5        HG  u  pU R                  UR                  U	5      U
5        U R                  UR                  U	5      U
5        MI     UR                  5        H  u  pU R                  [        5       nUR                  U	5        SSS5        U R                  WR
                  R                  U5        U R                  [        5       nUR                  U	5        SSS5        U R                  UR
                  R                  U5        M     UR                  S   /nUR                   Hy  nU R                  [        5       nUR                  U5        SSS5        U R                  WR
                  R                  U5        U R                  UR                  U5      U5        M{     [        U[        5      (       a-  UR                  SSS.5        U R                  U" U0 UD6U5        gg! , (       d  f       GNj= f! , (       d  f       GN'= f! , (       d  f       N= f)a  
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   r  messageserror_messagesempty_values
issubclassr*   updateassertIsInstance)rc   
fieldclassvalidinvalid
field_argsfield_kwargsempty_valuer  optionalinputoutputrx  context_managererror_requiredrh   s                  rP   assertFieldOutput SimpleTestCase.assertFieldOutputr  s   , JLz:\:zQ-P-Pj%-PQ"[[]MEX^^E2F;X^^E2F; + %]]_ME""?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;H-3H?
H*	-
H<	?
I	c           	         [        XUS5      n[        XUS5      nXE:w  a  [        US5      < S[        US5      < 3nSSR                  [        R                  " [        U5      R                  5       [        U5      R                  5       5      5      -   nU R                  Xg5      nU R                  U R                  X65      5        gg)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:rP  T != r`   N)
rj   r   r   difflibndiffrE  
splitlines_truncateMessagera   rb   )rc   html1html2rf   dom1dom2ri   diffs           rP   assertHTMLEqualSimpleTestCase.assertHTMLEqual  s     %A
 %B
 <(1$(=yt?TUK$))I((*I((* D //BKIId))#;< rW   c                     [        XUS5      n[        XUS5      nXE:X  a>  [        US5      < S[        US5      < 3nU R                  U R                  X65      5        gg)z>Assert that two HTML snippets are not semantically equivalent.r  rP  T == N)rj   r   ra   rb   )rc   r  r  rf   r  r  ri   s          rP   assertHTMLNotEqual!SimpleTestCase.assertHTMLNotEqual  sc    $A
 %B
 <(1$(=yt?TUKIId))#;< rW   c                 4   [        XS S5      n[        XS S5      nUR                  U5      nU(       a  US-  n[        U5      nUb5  US:X  a	  U< SU 3n	OSU SU< SU S	U 3n	U R                  XsU U	 35        g U R	                  US:g  U S
U< SU 35        g )Nr  rP  r#  r   rj  ra  rb  rc  rd  re  rf  )rj   r   r   r   r,  )
rc   needlehaystackr   r   parsed_needleparsed_haystackr]  haystack_reprrf   s
             rP   assertInHTML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                 &    U R                  XSUS9  g )Nr   )r   r   )r  )rc   r  r  r   s       rP   assertNotInHTMLSimpleTestCase.assertNotInHTML  s    &!
KrW   c                 N    [         R                  " U5      n[	        U[
        5      (       a   [         R                  " U5      nU R                  WX#S9  g! [         R                   a    U R                  SU-  5         Ngf = f! [         a    U R                  SU-  5         N_f = f)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   rE  r2  r   rc   rawexpected_datarf   datas        rP   assertJSONEqualSimpleTestCase.assertJSONEqual  s    	D::c?D mS))S $

= 9 	}6 ## 	DII<sBC	D
  S		AMQRSs"   A B (B ?B B$#B$c                 b    [         R                  " U5      n[	        U[
        5      (       a   [         R                  " U5      nU R                  WX#S9  g! [         R                   a    U R                  SU-  5         Ngf = f! [         R                   a    U R                  SU-  5         Nif = f)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   rE  assertNotEqualr  s        rP   assertJSONNotEqual!SimpleTestCase.assertJSONNotEqual   s    	D::c?D mS))S $

= 9 	D-9 ## 	DII<sBC	D
 '' S		AMQRSs"   A B (B ?B (B.-B.c                     [        X5      nU(       d  [        US5      < S[        US5      < 3nSSR                  [        R                  " UR                  5       UR                  5       5      5      -   nU R                  XV5      nU R                  U R                  X55      5        gg! [         a/  nSU-  nU R                  U R                  X55      5         SnAgSnAff = f)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   assertXMLEqualSimpleTestCase.assertXMLEqual  s    	A ,F
 dD)dD) diiMM$//"3T__5FG  #33KF		$--c?@ 	  	=IAMKIId))#;<<	=s   B) )
C"3%CC"c                     [        X5      nU(       a>  [        US5      < S[        US5      < 3nU R                  U R                  X55      5        gg! [         a/  nSU-  nU R                  U R                  X55      5         SnAgSnAff = f)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   assertXMLNotEqual SimpleTestCase.assertXMLNotEqual(  s    	A ,F
 dD)dD) 		$--c?@ 	  	=IAMKIId))#;<<	=s   A 
B%BB)r  r  ro   )F)i.     r   T)r   )Nr  r   F)r  r   F)NNr   N)NNr   )Nr   );r   rH   rI   r   r/   r  r.   r  r   r   setr   r   r   classmethodr   r   r   r   r   r   r   r  r   r	  r  r9   r   r   r6   rA  r5  r^  rg  rk  rp  r~  r  r  r  r   r  r  r   r  r  r  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 ArW   r=   c                      ^  \ rS rSrSrSrSr\1rSr	Sr
U 4S jr\SS j5       rS rS rS	 rU 4S
 jrS rSS jrS\S.S jjrSrU =r$ )r<   i<  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U ]  5         U R                  bz  [        R                  " U R                  5        [
        R                  " [        R                  R                  SU R                  SS9  U R                  SS9 H  n[        SSUS9  M      U R                  5         U R                  SS9 H$  n[         U   R"                  R%                  5         M&     g! [         aa    U R                  bR  [        R                  " 5         [
        R                  " [        R                  R                  S[        R                  SS9  e f = f)	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)rr   r	  available_appsr   set_available_appsr#   sendr   _wrappedrt   _databases_namesr    _fixture_setupr
  unset_available_appsr
  r&   queries_logclearrc   db_namert   s     rP   r	  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                     [          Vs/ s H=  nX R                  ;   d  M  U(       d   [         U   R                  S   S   (       a  M;  UPM?     sn$ s  snf )NTESTMIRROR)r&   r   settings_dict)rL   r  r   s      rP   r  $TransactionTestCase._databases_namesy  sU    
 %
$%   "5)77?I $
 	
 
s   A#AAc                    [         U   nUR                  R                  (       a  UR                  R	                  [        5       UR                  R                  5       5      nU(       aQ  [        R                  " US9   UR                  5        nU H  nUR                  U5        M     S S S 5        S S S 5        g g g ! , (       d  f       N= f! , (       d  f       g = f)Nusing)r&   featuressupports_sequence_resetopssequence_reset_by_name_sqlr   introspectionsequence_listr'   atomicr   execute)rc   r  connsql_listr   rx   s         rP   _reset_sequences$TransactionTestCase._reset_sequences  s    7#==00xx::
D..<<>H  ''g6&#+C"NN3/ $, ' 76 	 1 ' 76s$   <CB;(C;
C		C
Cc                 $   U R                  SS9 H  nU R                  (       a  U R                  U5        U R                  (       a  [	        [
        U   S5      (       a  U R                  b  [        R                  " 5         [
        U   R                  R                  [
        U   R                  5        U R                  b   [        R                  " U R                  5        U R                  (       d  M  [        S/U R                  Q7SUS.6  M     g )NFr  _test_serialized_contentsloaddatar   r  database)r  reset_sequencesr0  serialized_rollbackr+  r&   r  r   r  creationdeserialize_db_from_stringr3  r  fixturesr   )rc   r  s     rP   r  "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                     gNTry   r   s    rP   _should_reload_connections.TransactionTestCase._should_reload_connections  s    rW   c           	      N  >  U R                  5         [        TU ]	  5         U R                  5       (       a+  [        R
                  " SS9 H  nUR                  5         M     U R                  bS  [        R                  " 5         [        R                  " [        R                  R                  S[        R                  SS9  gg! U R                  bS  [        R                  " 5         [        R                  " [        R                  R                  S[        R                  SS9  f f = f)z
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_teardownrr   r  r?  r&   allcloser  r   r  r#   r  r   r  rt   r
  )rc   r.  rt   s     rP   r  "TransactionTestCase._post_teardown  s    	""$G"$..00 (OOTBDJJL C "".))+$$#,,66,"11	 /t"".))+$$#,,66,"11	 /s   AC A"D$c                     U R                  SS9 HY  nU R                  S L=(       d&    U R                  =(       a    [        [        U   S5      n[        SSSUSU R                  S LUS9  M[     g )NFr  r3  flushr   )r  r  r6  r7  allow_cascadeinhibit_post_migrate)r  r  r8  r+  r&   r   )rc   r  rK  s      rP   rD  %TransactionTestCase._fixture_teardown  s     ,,U,CG ##4/  ,, SG 46QR ! !  %"11=%9 DrW   c                 6   [        U5      nUnUb  [        X65      nU(       d#  U R                  [        U5      [        U5      US9$ [	        U5      S:  a-  [        US5      (       a  UR                  (       d  [        S5      eU R                  [        U5      X%S9$ )Nr  r   orderedzKTrying to compare non-ordered queryset against more than one ordered value.)	rT   mapassertDictEqualr   r   r+  rN  r2  r   )rc   qsvalues	transformrN  rf   r   s          rP   assertQuerySetEqual'TransactionTestCase.assertQuerySetEqual  s    f 	)E''S'QQ v;?wr955bjj!  UV==rW   r$  c                    [         U   n[        XU5      nUc  U$ U   U" U0 UD6  S S S 5        g ! , (       d  f       g = fro   )r&   rl   )rc   rq   r  r%  r   r   r.  r   s           rP   assertNumQueries$TransactionTestCase.assertNumQueries  s<    5!*4d;<N$!&! WWs   	/
=ry   )T)NTNro   )r   rH   rI   r   r7  r  r;  r$   r   r   r8  r	  r  r  r0  r  r?  r  rD  rT  rW  r   r   r   s   @rP   r<   r<   <  s}     O N H!"I	$   #5J 

 


0X*:.> "<L " "rW   r<   c                 h    U c  [         R                  " 5       OS U  5       n[        S U 5       5      $ )zL
Return whether or not all (or specified) connections support
transactions.
c              3   4   #    U  H  n[         U   v   M     g 7fro   r&   rz   r   s     rP   r}   3connections_support_transactions.<locals>.<genexpr>       6gUk% g   c              3   L   #    U  H  oR                   R                  v   M     g 7fro   )r&  supports_transactionsrz   r.  s     rP   r}   r]    s     Eut}}22u   "$r&   rE  aliasesconnss     rP    connections_support_transactionsrh    s5     ? 	6g6 

 EuEEErW   c                 h    U c  [         R                  " 5       OS U  5       n[        S U 5       5      $ )zJ
Return whether or not all (or specified) connections support savepoints.
c              3   4   #    U  H  n[         U   v   M     g 7fro   r[  r\  s     rP   r}   1connections_support_savepoints.<locals>.<genexpr>  r^  r_  c              3   L   #    U  H  oR                   R                  v   M     g 7fro   )r&  uses_savepointsrb  s     rP   r}   rk    s     ?}},,rc  rd  re  s     rP   connections_support_savepointsrn    s5     ? 	6g6 

 ????rW   c                   4    \ rS rSrSrSrS rS rS rS r	Sr
g	)
TestDatai  al  
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                     Xl         X l        g ro   r   r  )rc   r   r  s      rP   rs   TestData.__init__   s    		rW   c                      [        XR                  5      nU$ ! [         a    0 n[        XR                  U5         U$ f = fro   )r   	memo_attrrF   r   )rc   testcasememos      rP   get_memoTestData.get_memo$  sE    	48^^4D   	4DHnnd3	4s    "??c                     Uc  U R                   $ U R                  U5      n[        U R                   U5      n[        XR                  U5        U$ ro   )r  ry  r   r   r   )rc   instanceownerrx  r  s        rP   __get__TestData.__get__,  sC    99}}X&		4())T*rW   c                 @    SU R                   < SU R                  < S3$ )Nz<TestData: name=z, data=>rs  r   s    rP   __repr__TestData.__repr__4  s    15DIIFFrW   )r  r   N)r   rH   rI   r   __doc__rv  rs   ry  r~  r  r   ry   rW   rP   rp  rp    s#    	 !IGrW   rp  c                      ^  \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\U 4S j5       r
\U 4S j5       r\S	 5       rU 4S
 jrU 4S jrU 4S jrS r\\\SS.S j5       5       rSrU =r$ )r;   i8  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                     0 nU R                  5        H2  n[        R                  " US9nSUl        UR	                  5         X1U'   M4     U$ )z*Open atomic blocks for multiple databases.r$  T)r  r'   r,  _from_testcaserD   )rL   atomicsr  r,  s       rP   _enter_atomicsTestCase._enter_atomicsF  sO     ++-G ''g6F$(F!%G	 .
 rW   c                     [        U R                  5       5       H-  n[        R                  " SUS9  X   R	                  SSS5        M/     g)z5Rollback atomic blocks opened by the previous method.Tr$  N)reversedr  r'   set_rollbackrE   )rL   r  r  s      rP   _rollback_atomicsTestCase._rollback_atomicsQ  sA       4 4 67G$$T9%%dD$7 8rW   c                 ,    [        U R                  5      $ ro   )rh  r   rL   s    rP   _databases_support_transactions(TestCase._databases_support_transactionsX  s    />>rW   c                 ,    [        U R                  5      $ ro   )rn  r   r  s    rP   _databases_support_savepoints&TestCase._databases_support_savepoints\  s    -cmm<<rW   c           	        > [         TU ]  5         U R                  5       (       a  U R                  5       (       d  g U R	                  5       U l        U R                  (       a1  U R                  SS9 H  n [        S/U R                  Q7SUS.6  M      U R                  R                  5       n U R                  5         U R                  R                  5        H/  u  p4XBR                  U5      Ld  M  [!        X[#        X45      5        M1     g ! [         a    U R                  U R
                  5        e f = f! [         a    U R                  U R
                  5        e f = f)NFr  r4  r   r5  )rr   r   r  r  r  cls_atomicsr;  r  r   r
  r  r   r   setUpTestDatar   r4  r   rp  )rL   r  	pre_attrsr   rU   rt   s        rP   r   TestCase.setUpClass`  s1   //111133,,.<<///F	 " #$!(	 G LL%%'		 <<--/KDMM$//8D#89 0 ! ))#//:  	!!#//2	s   4D-D5 'D25'Ec                   > U R                  5       (       a[  U R                  5       (       aF  U R                  U R                  5        [        R
                  " SS9 H  nUR                  5         M     [        TU ]!  5         g )NTrB  )	r  r  r  r  r&   rE  rF  rr   tearDownClass)rL   r.  rt   s     rP   r  TestCase.tearDownClass  s\     //111133!!#//2#>

 ?rW   c                     g)z#Load initial data for the TestCase.Nry   r  s    rP   r  TestCase.setUpTestData  s     	rW   c                 L   > U R                  5       (       a  g[        TU ]	  5       $ )NF)r  rr   r?  )rc   rt   s    rP   r?  #TestCase._should_reload_connections  s#    //11w133rW   c                   > U R                  5       (       d  U R                  5         [        TU ]  5       $ U R                  (       a  [        S5      eU R                  5       U l        U R                  5       (       dT  U R                  (       a2  U R                  SS9 H  n[        S/U R                  Q70 SUS.D6  M!     U R                  5         g g )Nz4reset_sequences cannot be used on TestCase instancesFr  r4  r   r5  )r  r  rr   r  r7  rG   r  r  r  r;  r  r   r  s     rP   r  TestCase._fixture_setup  s    3355  7)++RSS**,1133}}#44U4KG " )*w?  L   4rW   c                 p  > U R                  5       (       d  [        TU ]	  5       $  [        U R	                  5       5       H9  nU R                  [        U   5      (       d  M"  [        U   R                  5         M;     U R                  U R                  5        g ! U R                  U R                  5        f = fro   )
r  rr   rD  r  r  _should_check_constraintsr&   check_constraintsr  r  r  s     rP   rD  TestCase._fixture_teardown  s    33557,..	1#D$9$9$;<11+g2FGG(::< = ""4<<0D""4<<0s   7B !B B5c                     UR                   R                  =(       a)    UR                  (       + =(       a    UR                  " 5       $ ro   )r&  can_defer_constraint_checksneeds_rollback	is_usable)rc   r%   s     rP   r  "TestCase._should_check_constraints  s8    ;; '---'$$&	
rW   F)r%  r-  c          
   #     #    / n[        [        U   R                  5      n Uv    [        [        U   R                  5      n[        U   R                  US  H8  u  pgnUR                  U5        U(       d  M   U(       a
   U" 5         M1  U" 5         M:     U[        [        U   R                  5      :X  a  gUnM  ! [         a.  n	[
        R                  SUR                   S3U	SS9   Sn	A	M  Sn	A	ff = f!  [        [        U   R                  5      n[        U   R                  US  Hs  u  pgnUR                  U5        U(       d  M   U(       aE   U" 5         M1  ! [         a.  n	[
        R                  SUR                   S3U	SS9   Sn	A	Md  Sn	A	ff = fU" 5         Mu     U[        [        U   R                  5      :X  a  f UnM  = f7f)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   captureOnCommitCallbacks!TestCase.captureOnCommitCallbacks  s     	+e,::;	-O!$[%7%E%E!F+6u+=+K+KL,'A $$X.w!" (
 %J!,$ "SU);)I)I%JJ,-  $- " &&4X5J5J4K L8 %9$%-1	 !- !"" !$[%7%E%E!F+6u+=+K+KL,'A $$X.w!" (
#, " &&4X5J5J4K L8 %9$%-1	 !- !"" %J!,$ "SU);)I)I%JJ,- s}   GC5 AG9GB:2G:
C2#C-'G-C22G5AG	GEG
F	$#F	GF	3GG)r  )r   rH   rI   r   r  r  r  r  r  r  r   r  r  r?  r  rD  r  r   r$   r  r   r   r   s   @rP   r;   r;   8  s       8 8 ? ? = = : :>      4
!(1
 /? -  -rW   r;   c                   .    \ rS rSrSrS rS rSS jrSrg)	CheckConditioni  z1Descriptor class for deferred condition checking.c                     Xl         g ro   
conditions)rc   r  s     rP   rs   CheckCondition.__init__  s    $rW   c                 @    U R                   " / U R                  QX4P76 $ ro   )rt   r  )rc   	conditionreasons      rP   add_conditionCheckCondition.add_condition  s     ~~DtD0CDDrW   Nc                     [        S UR                   5       5      (       a  gU R                   H   u  p4U" 5       (       d  M  SUl        XBl          g   g)Nc              3   <   #    U  H  n[        US S5      v   M     g7f)r  FN)r   )rz   bases     rP   r}   )CheckCondition.__get__.<locals>.<genexpr>  s     S]Twt0%88]s   TF)any	__bases__r  r  __unittest_skip_why__)rc   r|  rL   r  r  s        rP   r~  CheckCondition.__get__  sH    SS]]SSS!%I{{(,%,2) "1 rW   r  ro   )	r   rH   rI   r   r  rs   r  r~  r   ry   rW   rP   r  r    s    ;%E
rW   r  c                    ^ ^^ U UU4S jnU$ )Nc                   >^ ^ [        T [        5      (       a  [        T [        R                  5      (       d  [        T 5      UUUU 4S j5       nUmT$ T m[        TSS 5      nU(       a  [        R                  U;  a  UU4S jmT R                  R                  S5      n[        U[        5      (       a  UR                  TT5      Tl        T$ USLa  [        TT45      Tl        T$ )Nc            
      t  > U (       a  [        U S   [        R                  5      (       ae  [        R                  [        U S   S0 5      ;  aC  [        T< SU S   < SU S   R                  R                  < S[        R                  < S35      eT" 5       (       a  [        R                  " T5      eT" U 0 UD6$ )Nr   r    cannot be used on z as z# doesn't allow queries against the z
 database.)
rS   unittestr;   r%   r   r   r2  rt   rI   SkipTest)r   r   r  r   r  	test_funcs     rP   skip_wrapper6_deferredSkip.<locals>.decorator.<locals>.skip_wrapper  s     "47H,=,=>>"((Qb0QQ$ ! G G--::&,,	 	 ;;"++F33 $1&11rW   r   c                  N   > [        T < ST< S[        R                  < S35      e)Nr  z* as it doesn't allow queries against the 'z' database.)r2  r%   r   )r   	test_items   rP   r  3_deferredSkip.<locals>.decorator.<locals>.condition  s&    $ !%&,, rW   r  T)rS   rC   r  r  r;   r   r   r%   r   r   r4  r  r  r  )r  r  r   skipr  r  r   r  s   `   @rP   	decorator _deferredSkip.<locals>.decorator  s     y$''Jy(BSBS,T,T 92 2( %I2 - "I	;=I
 0 0	 A	 %%))*=>D$//.2.@.@F.S	+  T!.<i=P.Q	+rW   ry   )r  r  r   r  s   ``` rP   _deferredSkipr    s    4l rW   c                  J   ^  [        U 4S jSSR                  T 5      -  S5      $ )zASkip a test if a database has at least one of the named features.c                  (   > [        S T  5       5      $ )Nc              3   X   #    U  H   n[        [        R                  US 5      v   M"     g7fFNr   r%   r&  rz   features     rP   r}   4skipIfDBFeature.<locals>.<lambda>.<locals>.<genexpr>/  s%      
HPWGJ''%88   (*r  r&  s   rP   <lambda>!skipIfDBFeature.<locals>.<lambda>/  s     
HP
 
rW   zDatabase has feature(s) %sr  r>   r  r   r  s   `rP   r>   r>   ,  s+    	
 	%tyy':: rW   c                  J   ^  [        U 4S jSSR                  T 5      -  S5      $ )z9Skip a test unless a database has all the named features.c                  2   > [        S T  5       5      (       + $ )Nc              3   X   #    U  H   n[        [        R                  US 5      v   M"     g7fr  r  r  s     rP   r}   8skipUnlessDBFeature.<locals>.<lambda>.<locals>.<genexpr>:  %      
HPWGJ''%88r  )rE  r  s   rP   r  %skipUnlessDBFeature.<locals>.<lambda>:      C 
HP
 
 
rW   z'Database doesn't support feature(s): %sr  r?   r  r  s   `rP   r?   r?   7  s+    	
 	2DIIh4GG rW   c                  J   ^  [        U 4S jSSR                  T 5      -  S5      $ )z<Skip a test unless a database has any of the named features.c                  2   > [        S T  5       5      (       + $ )Nc              3   X   #    U  H   n[        [        R                  US 5      v   M"     g7fr  r  r  s     rP   r}   ;skipUnlessAnyDBFeature.<locals>.<lambda>.<locals>.<genexpr>E  r  r  r  r  s   rP   r  (skipUnlessAnyDBFeature.<locals>.<lambda>E  r  rW   z2Database doesn't support any of the feature(s): %sr  skipUnlessAnyDBFeaturer  r  s   `rP   r  r  B  s+    	
 	=tyy?RR  rW   c                       \ rS rSrSrS rSrg)QuietWSGIRequestHandleriM  z
A WSGIRequestHandler that doesn't log to standard output any of the
requests received, so as to not clutter the test result output.
c                      g ro   ry   )r   s    rP   log_message#QuietWSGIRequestHandler.log_messageS  s    rW   ry   N)r   rH   rI   r   r  r  r   ry   rW   rP   r  r  M  s    
rW   r  c                   V   ^  \ rS rSrSrU 4S jrS rS rU 4S jrS r	U 4S jr
S	rU =r$ )
FSFilesHandleriW  z
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                 j   > Xl         [        U R                  5       5      U l        [        TU ]  5         g ro   )applicationr   get_base_urlbase_urlrr   rs   )rc   r  rt   s     rP   rs   FSFilesHandler.__init__]  s)    & !2!2!45rW   c                 t    UR                  U R                  S   5      =(       a    U R                  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_handleFSFilesHandler._should_handleb  s-     t}}Q/0Iq9I5IIrW   c                 T    UR                  U R                  S   5      n[        U5      $ )z?Return the relative path to the file on disk for the given URL.r  )removeprefixr  r   )rc   r.  relative_urls      rP   	file_pathFSFilesHandler.file_pathj  s&    ''a(89L))rW   c                    > SSK Jn  U R                  UR                  5      (       a   U R	                  U5      $ [
        TU ]  U5      $ ! U a     Nf = f)Nr   )Http404)django.httpr  r  r<  r:   rr   get_response)rc   r0  r  rt   s      rP   r  FSFilesHandler.get_responseo  sU    'w||,,zz'** w#G,,  s   A	 	AAc                     U R                  UR                  5      n[        R                  " [	        U5      5      nUR                  SS5      R                  S5      n[        XU R                  5       S9$ )N\r&  )document_root)	r	  r<  	posixpathnormpathr   replacelstripr:   get_base_dir)rc   r0  os_rel_pathfinal_rel_paths       rP   r:   FSFilesHandler.servey  s^    nnW\\2(()=> %,,T37>>sCWD<M<M<OPPrW   c                    > U R                  [        U5      5      (       d  U R                  X5      $ [        TU ]  X5      $ ro   )r  r   r  rr   r   )rc   environstart_responsert   s      rP   r   FSFilesHandler.__call__  s:    ""=#9::##G<<w88rW   )r  r  )r   rH   rI   r   r  rs   r  r	  r  r:   r   r   r   r   s   @rP   r  r  W  s-    

J*
-Q9 9rW   r  c                   $    \ rS rSrSrS rS rSrg)_StaticFilesHandleri  zy
Handler for serving static files. A private class that is meant to be used
solely as a convenience by LiveServerThread.
c                 "    [         R                  $ ro   )r   STATIC_ROOTr   s    rP   r   _StaticFilesHandler.get_base_dir  s    ###rW   c                 "    [         R                  $ ro   )r   
STATIC_URLr   s    rP   r    _StaticFilesHandler.get_base_url      """rW   ry   Nr   rH   rI   r   r  r  r   r   ry   rW   rP   r   r     s    
$#rW   r   c                   $    \ rS rSrSrS rS rSrg)_MediaFilesHandleri  z|
Handler for serving the media files. A private class that is meant to be
used solely as a convenience by LiveServerThread.
c                 "    [         R                  $ ro   )r   
MEDIA_ROOTr   s    rP   r  _MediaFilesHandler.get_base_dir  r'  rW   c                 "    [         R                  $ ro   )r   	MEDIA_URLr   s    rP   r   _MediaFilesHandler.get_base_url  s    !!!rW   ry   Nr(  ry   rW   rP   r*  r*    s    
#"rW   r*  c                   J   ^  \ rS rSrSr\rSU 4S jjrS rS	S jr	S r
SrU =r$ )
LiveServerThreadi  zBThread for running a live HTTP server while the tests are running.c                    > Xl         X@l        [        R                  " 5       U l        S U l        X l        X0l        [        TU ]%  5         g ro   )
hostr?  	threadingEventis_readyr  static_handlerconnections_overriderr   rs   )rc   r4  r8  r9  r?  rt   s        rP   rs   LiveServerThread.__init__  s9    		!)
,$8!rW   c                    U R                   (       a,  U R                   R                  5        H  u  pU[        U'   M      U R                  [	        [        5       5      5      nU R                  U R                   S9U l        U R                  S:X  a  U R                  R                  S   U l        U R                  R                  U5        U R                  R                  5         U R                  R                  5         [        R                   " 5         g! [         a*  nX@l        U R                  R                  5          SnANESnAff = f! [        R                   " 5         f = f)zR
Set up the live server and databases, and then loop over handling
HTTP requests.
)r9  r   r   N)r9  r   r&   r8  r*  r   _create_serverhttpdr?  server_addressset_appr7  r  serve_foreverr
  r  	close_all)rc   r   r.  handlerrh   s        rP   runLiveServerThread.run  s   
 $$  $88>>@%)E"  A	$))*<[]*KLG,,%)%>%> - DJ yyA~ JJ55a8	JJw'MMJJ$$&
 !!#	  	 JMM	  !!#s*   B=D 
E E<E	 EE	 	E c                 Z    U R                  U R                  U R                  4[        SUS9$ )NF)allow_reuse_addressr9  )server_classr4  r?  r  )rc   r9  s     rP   r<  LiveServerThread._create_server  s3      YY		"# %!5	 ! 
 	
rW   c                     [        U S5      (       a4  U R                  R                  5         U R                  R                  5         U R	                  5         g )Nr=  )r+  r=  shutdownserver_closer   r   s    rP   	terminateLiveServerThread.terminate  s8    4!!JJ!JJ##%		rW   )r9  r  r4  r=  r7  r?  r8  )Nr   ro   )r   rH   rI   r   r  r!   rG  rs   rC  r<  rL  r   r   r   s   @rP   r2  r2    s$    L%L$8
 rW   r2  c                      ^  \ rS rSrSrSrSr\r\	r
\S 5       r\S 5       r\S 5       r\U 4S j5       r\S	 5       r\S
 5       r\S 5       rSrU =r$ )LiveServerTestCasei  a  
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                 R    SU R                   < SU R                  R                  < 3$ )Nzhttp://:)r4  server_threadr?  r  s    rP   live_server_url"LiveServerTestCase.live_server_url  s    !$3+<+<+A+ABBrW   c                     U R                   $ ro   )r4  r  s    rP   allowed_hostLiveServerTestCase.allowed_host  s    xxrW   c                     0 n[         R                  " 5        H:  nUR                  S:X  d  M  UR                  5       (       d  M,  X!UR                  '   M<     U$ )Nsqlite)r&   rE  vendoris_in_memory_dbr   rL   r9  r.  s      rP   _make_connections_override-LiveServerTestCase._make_connections_override  sI    !OO%D {{h&4+?+?+A+A37TZZ0	 &
 $#rW   c                    > [         TU ]  5         U R                  [        SU R                  0S95        U R                  5         g )Nr   )r1  )rr   r   r   r6   rW  _start_server_threadr   s    rP   r   LiveServerTestCase.setUpClass  s=    8S5E5E*FG	
 	  "rW   c                    U R                  5       nUR                  5        H  nUR                  5         M     U R                  U5      U l        SU R                  l        U R                  R                  5         U R                  U R                  5        U R                  R                  R                  5         U R                  R                  (       a  U R                  R                  eg r>  )r^  rR  inc_thread_sharing_create_server_threadrS  daemonr   r   _terminate_threadr7  waitr  r]  s      rP   ra  'LiveServerTestCase._start_server_thread  s    "==?(//1D##% 2  556JK#' !C112 	""'')""##))) #rW   c                 b    U R                  U R                  U R                  UU R                  S9$ )N)r9  r?  )server_thread_classr4  r8  r?  )rL   r9  s     rP   re  (LiveServerTestCase._create_server_thread  s4    &&HH!5	 ' 
 	
rW   c                     U R                   R                  5         U R                   R                  R                  5        H  nUR	                  5         M     g ro   )rS  rL  r9  rR  dec_thread_sharing)rL   r.  s     rP   rg  $LiveServerTestCase._terminate_thread!  sB     	##%%%::AACD##% DrW   ry   )r   rH   rI   r   r  r4  r?  r2  rk  r   r8  r8   rT  rW  r  r^  r   ra  re  rg  r   r   r   s   @rP   rO  rO    s    	 DD*(NC C   $ $ # # * *  
 
 & &rW   rO  c                   F   ^  \ rS rSrSrSrU 4S jr\U 4S j5       rSr	U =r
$ )SerializeMixini*  z
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U ]  " S0 UD6  U R                  c$  [        SR	                  U R
                  5      5      eg )NzB{}.lockfile isn't set. Set it to a unique value in the base class.ry   )rr   __init_subclass__lockfiler2  formatr   )rL   r   rt   s     rP   rs   SerializeMixin.__init_subclass__6  sB    !+F+<<%%+VCLL%9   rW   c                    > [        U R                  5      U l        U R                  U R                  R                  5        [
        R                  " U R                  [
        R                  5        [        TU ]%  5         g ro   )
openrt  	_lockfiler   rF  r   lockLOCK_EXrr   r   r   s    rP   r   SerializeMixin.setUpClass>  sL    S\\*CMM//0

3==%--0rW   ry   )r   rH   rI   r   r  rt  rs  r  r   r   r   r   s   @rP   rq  rq  *  s(     H  rW   rq  ro   )r  r  loggingrY   r  r  r5  r  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:   	getLoggerr  r   rQ   rV   r^   rj   rl   r   r   AssertionErrorr   r   r;   r=   r<   rh  rn  rp  r  r  r>   r?   r  r  r  r   r*  Threadr2  rO  rq  ry   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   