o
    ˷er                     @   s\   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m	Z	 d dl
mZ G dd deZdS )    N)forms)TestCase)PayPalEncryptedPaymentsFormPayPalPaymentsForm'PayPalSharedSecretEncryptedPaymentsForm)PayPalIPNFormc                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )PaymentsFormTestc                 C   s   d}t ddd|dd}| }| d| | d| | d	| | d
| | d| | d| d | t ddd|dd}| }| d| | d| | d	| | d
| | d| | d| d | d S )Nzhttps://example.com/return_urlme@mybusiness.com10.502.00)businessamountshipping
return_urlinitialz6action="https://www.sandbox.paypal.com/cgi-bin/webscr"zvalue="me@mybusiness.com"zvalue="2.00"zvalue="10.50"buynowCCzvalue="")r   r   r   returnr   renderassertIn)selfr   frendered r   [/var/www/ideatree/venv/lib/python3.10/site-packages/paypal/standard/ipn/tests/test_forms.pytest_form_render   s:   z!PaymentsFormTest.test_form_renderc                 C   sN   G dd dt }|ddid}| }| d| | d| | d| d S )	Nc                   @   s    e Zd ZdZejejjdZdS )zQPaymentsFormTest.test_custom_subclass_form_render.<locals>.CustomAmountPayPalFormzL
            PayPal form that lets user choose their own amount
            )widgetN)	__name__
__module____qualname____doc__r   IntegerFieldwidgetsNumberInputr   r   r   r   r   CustomAmountPayPalForm4   s    r&   r   r	   r   z&<label for="id_amount">Amount:</label>z;<input type="number" name="amount" required id="id_amount">zvalue="me@mybusiness.comr   )r   r&   r   r   r   r   r    test_custom_subclass_form_render3   s   z1PaymentsFormTest.test_custom_subclass_form_renderc                 C   sL   | j dd ti d}| d|  W d    d S 1 sw   Y  d S )NF)PAYPAL_TESTr   sandbox)settingsr   assertNotInr   )r   r   r   r   r   test_form_endpontA   s   
"z"PaymentsFormTest.test_form_endpontc                 C   s@   ddi}t |}| |  | |jddgiddgig d S )Npayment_datez2015-10-25 01:21:32zJInvalid date format 2015-10-25 01:21:32: need more than 2 values to unpackzXInvalid date format 2015-10-25 01:21:32: not enough values to unpack (expected 5, got 2))r   assertFalseis_validr   errors)r   dataformr   r   r   test_invalid_date_formatF   s   z)PaymentsFormTest.test_invalid_date_formatc           
      C   s   ddd}t jt jt}t j|d}t j|d}t j|d}d}t|||||d}| }| d	| | d
| t	
d}	| j|	|dd d S )Nr
   r   )r   r   "test_cert__do_not_use__private.pem!test_cert__do_not_use__public.pem%test_cert_from_paypal__do_not_use.pemanother-paypal-idr   private_certpublic_certpaypal_certcert_idname="cmd" value="_s-xclick"-name="encrypted" value="-----BEGIN PKCS7-----{.*name="encrypted" value="-----BEGIN PKCS7-----\n([A-Za-z0-9/\+]{64}\n)*[A-Za-z0-9/\+]{1,64}={0,2}\n-----END PKCS7-----\n.*AButton encryption has wrong form - expected a block of PKCS7 datamsg)ospathdirnameabspath__file__joinr   r   r   recompile
assertTruesearch
r   r1   herepaypal_private_certpaypal_public_certr;   paypal_cert_idr2   r   expected_regexr   r   r   test_encrypted_buttonY   s2   
z&PaymentsFormTest.test_encrypted_buttonc           
      C   s   dddd}t jt jt}t j|d}t j|d}t j|d}d}t|||||d	}| }| d
| | d| t	
d}	| j|	|dd d S )Nzhttps://example.com/notify_urlr
   r   )
notify_urlr   r   r4   r5   r6   r7   r8   r=   r>   r?   r@   rA   )rC   rD   rE   rF   rG   rH   r   r   r   rI   rJ   rK   rL   rM   r   r   r   #test_shared_secret_encrypted_button|   s4   
z4PaymentsFormTest.test_shared_secret_encrypted_buttonN)	r   r    r!   r   r'   r,   r3   rS   rU   r   r   r   r   r      s    ##r   )rC   rI   djangor   django.testr   paypal.standard.formsr   r   r   paypal.standard.ipn.formsr   r   r   r   r   r   <module>   s    