
    TL,h                         d dl Z d dlmZmZ d dlmZ d dlmZmZ d dl	m
Z
mZ  G d dej                        Z G d d	e      Zy)
    N)	MagicMockpatch)forms)TestCaseoverride_settings)clientfieldsc                   .    e Zd Z ej                         Zy)DefaultFormN)__name__
__module____qualname__r	   ReCaptchaFieldcaptcha     a/var/www/paragaon_website/venv/lib/python3.12/site-packages/django_recaptcha/tests/test_client.pyr   r   
   s    #f##%Gr   r   c                       e Zd Z ed      d        Z ed      d        Z ed       ed      d               Z ed       ed       ed       edd	i
      d                             Zy)
TestClientz)django_recaptcha.client.recaptcha_requestc                    t               }d|j                  _        ||_        t        j                         j
                  }t        j                  |dd      }| j                  d|j                  j                                | j                  d|z  |j                  j                                | j                  d|j                  j                                | j                  |j                         y )NsZ   {"success": true, "challenge_ts":"2019-01-11T13:57:23Z", "hostname": "testkey.google.com"}somekey0.0.0.0secret=somekeyresponse=%sremoteip=0.0.0.0)r   readreturn_valueuuiduuid4hexr   submitassertIn	call_args__str__
assertTrueis_validselfmocked_response	read_mockuuid_hexresponses        r   test_client_successzTestClient.test_client_success   s    K	I 	# (1$::<##==
 	&(A(A(I(I(KLmh.0I0I0Q0Q0ST(/*C*C*K*K*MN))*r   c                 ^   t               }d|j                  _        ||_        t        j                         j
                  }t        j                  |dd      }| j                  d|j                  j                                | j                  d|z  |j                  j                                | j                  d|j                  j                                | j                  |j                         | j                  |j                  j                         ddgj                                y )	NT   {"success": false, "error-codes":["invalid-input-response", "invalid-input-secret"]}r   r   r   r   r   zinvalid-input-responsezinvalid-input-secret)r   r   r   r   r   r    r   r!   r"   r#   r$   assertFalser&   assertEqualerror_codessortr'   s        r   test_client_failurezTestClient.test_client_failure%   s    K	C 	# (1$::<##==
 	&(A(A(I(I(KLmh.0I0I0Q0Q0ST(/*C*C*K*K*MN**+  %%'%'=>CCE	
r   zdjango_recaptcha.client.Requestz$django_recaptcha.client.build_openerc                    t               }d|j                  _        t               }||j                  _        ||_        ddi}t	        |      }|j                          | j                  d|j                  j                                | j                  d|j                  j                                | j                  d|j                  j                                | j                  d|j                  j                                | j                  d|j                  j                                | j                  d	|j                  j                                | j                  d
|j                  j                                | j                  d|j                  j                                |j                  j                   |       d       |j                          y )Nr/   g-recaptcha-responsePASSEDdata=remoteip=Noneresponse=PASSEDsecret=privkeyheaders=3'Content-type': 'application/x-www-form-urlencoded' 'User-agent': 'reCAPTCHA Django'5url='https://www.google.com/recaptcha/api/siteverify'
   timeout
r   r   r   openr   r&   r"   r#   r$   assert_called_with)r(   mocked_buildermocked_request	mock_readmock_openerform_paramsforms          r   test_client_requestzTestClient.test_client_request?   s~    K	C 	#  k(1%&1#-x8;' 	g~77??ABo~'?'?'G'G'IJ')A)A)I)I)KL&(@(@(H(H(JKj.":":"B"B"DEA$$,,.	
 	.0H0H0P0P0R	
 	C$$,,.	
 	++N,<b+I))+r   z$django_recaptcha.client.ProxyHandlerhttpaaaa.com)RECAPTCHA_PROXYc                    t               }d|j                  _        t               }||j                  _        ||_        ddi}t	        |      }|j                          | j                  d|j                  j                                | j                  d|j                  j                                | j                  d|j                  j                                | j                  d|j                  j                                | j                  d|j                  j                                | j                  d	|j                  j                                | j                  d
|j                  j                                | j                  d|j                  j                                |j                  j                   |       d       |j                  ddi       |j                   |              y )Nr/   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rM   rN   rC   )r(   rF   rG   mocked_handlerrH   rI   rJ   rK   s           r   &test_client_request_with_proxy_builderz1TestClient.test_client_request_with_proxy_builderc   s    K	C 	#  k(1%&1#-x8;' 	g~77??ABo~'?'?'G'G'IJ')A)A)I)I)KL&(@(@(H(H(JKj.":":"B"B"DEA$$,,.	
 	.0H0H0P0P0R	
 	C$$,,.	
 	++N,<b+I))6:*>?)).*:;r   N)	r   r   r   r   r-   r4   rL   r   rR   r   r   r   r   r      s    
67+ 8+* 67
 8
2 ,-
12 , 3 . ,D 12
,-
12
';<#< = 3 . 3#<r   r   )r   unittest.mockr   r   djangor   django.testr   r   django_recaptchar   r	   Formr   r   r   r   r   <module>rX      s2     *  3 +&%** &|< |<r   