o
    HOU\  ã                   @   sˆ   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Zd dlmZ G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZdS )é    )ÚTestCase)Úmail)Úsettings)ÚSendgridEmailMessageÚSendgridEmailMultiAlternatives)ÚEmailN)Úcopyc                   @   sT   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚUtilTestCasec                 C   s   dddddœ| _ d S )NzTest SubjectzHi, I am a test bodyzemail@example.com)zother_email@example.com)ÚsubjectÚbodyÚ
from_emailÚto)Ú
email_data©Úself© r   úK/var/www/html/env/lib/python3.10/site-packages/sendgrid/tests/test_utils.pyÚsetUp   s
   ýzUtilTestCase.setUpc                 C   ó^   t jdi | j¤Ž}| ¡  |  tt jƒd¡ |  t jd j| jd ¡ |  dt jd j	¡ dS ©z8 Test if we break default django email sending.
        é   r   r
   ú	X-SMTPAPINr   )
r   ÚEmailMessager   ÚsendÚassertEqualÚlenÚoutboxr
   ÚassertNotInÚextra_headers©r   Úmessager   r   r   Útest_django_email   ó
   zUtilTestCase.test_django_emailc                 C   r   r   )
r   ÚEmailMultiAlternativesr   r   r   r   r   r
   r   r   r   r   r   r   Útest_django_multipart   r"   z"UtilTestCase.test_django_multipartc                 C   óš   t d	i | j¤Ž}| ¡  |  ttjƒd¡ |  tjd j| jd ¡ |  dtjd j	¡ t
 tjd j	d ¡}|  d|d ¡ |  t|d d ƒd¡ dS ©
z9 Test if we can send emails using our own class.
        r   r   r
   r   ÚuuidÚunique_argsé$   Nr   )r   r   r   r   r   r   r   r
   ÚassertInr   ÚjsonÚloads©r   r    Úcontentr   r   r   Útest_sendgrid_email'   ó   z UtilTestCase.test_sendgrid_emailc                 C   r%   r&   )r   r   r   r   r   r   r   r
   r*   r   r+   r,   r-   r   r   r   Útest_sendgrid_multipart4   r0   z$UtilTestCase.test_sendgrid_multipartc                 C   ó€   t di | j¤Ž}| ¡  tjj|jd�}|  |jd¡ t	| jƒ}||d< t di |¤Ž}| ¡  tjj|jd�}|  |j|¡ dS ©z7 Test attaching a related object to the email.
        )r'   NÚobjr   )
r   r   r   r   ÚobjectsÚgetr'   r   Úcontent_objectÚdict©r   r    Úmail_event_1ÚdataÚ
mail_eventr   r   r   Ú%test_sendgrid_email_object_attachmentA   ó   
z2UtilTestCase.test_sendgrid_email_object_attachmentc                 C   r2   r3   )
r   r   r   r   r5   r6   r'   r   r7   r8   r9   r   r   r   Ú)test_sendgrid_multipart_object_attachmentR   r>   z6UtilTestCase.test_sendgrid_multipart_object_attachmentc                 C   s²   t | jƒ}| dddii¡ tdi |¤Ž}| ¡  |  ttjƒd¡ |  	dtjd j
¡ t tjd j
d ¡}|  	d|d ¡ |  t|d d ƒd	¡ |  tjd j
d d¡ d
S )z5 Test if we handle custom headers correctly.
        Úheadersú	X-AWESOMEé*   r   r   r   r'   r(   r)   Nr   )r   r   Úupdater   r   r   r   r   r   r*   r   r+   r,   ©r   Ú	mail_datar    r.   r   r   r   Útest_email_headersc   s   
zUtilTestCase.test_email_headersc                 C   sÎ   t | jƒ}| ddt ddi¡dœi¡ tdi |¤Ž}| ¡  |  tt	j
ƒd¡ |  dt	j
d j¡ t t	j
d jd ¡}|  d	|d
 ¡ |  t|d
 d	 ƒd¡ |  |d d¡ |  t	j
d jd d¡ dS )z? Test if we handle existing SMTPAPI headers correctly.
        r@   rB   ÚamazingÚstuff)rA   r   r   r   r   r'   r(   r)   rA   Nr   )r   r   rC   r+   Údumpsr   r   r   r   r   r   r*   r   r,   rD   r   r   r   Útest_smtpapi_headersv   s   

þz!UtilTestCase.test_smtpapi_headersN)Ú__name__Ú
__module__Ú__qualname__r   r!   r$   r/   r1   r=   r?   rF   rJ   r   r   r   r   r	      s    

r	   c                       ó(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚUtilTZTestCasez) Test explicitly with USE_TZ enabled
    c                    ó    t j| _dt _tt| ƒ ¡  d S )NT)r   ÚUSE_TZÚ_old_use_tzÚsuperrO   r   r   ©Ú	__class__r   r   r   �   ó   zUtilTZTestCase.setUpc                 C   ó   | j t_d S ©N©rR   r   rQ   r   r   r   r   ÚtearDown”   ó   zUtilTZTestCase.tearDown©rK   rL   rM   Ú__doc__r   rZ   Ú__classcell__r   r   rT   r   rO   Œ   ó    rO   c                       rN   )ÚUtilNoTZTestCasez* Test explicitly with USE_TZ disabled
    c                    rP   )NF)r   rQ   rR   rS   r`   r   r   rT   r   r   r   ›   rV   zUtilNoTZTestCase.setUpc                 C   rW   rX   rY   r   r   r   r   rZ       r[   zUtilNoTZTestCase.tearDownr\   r   r   rT   r   r`   ˜   r_   r`   )Údjango.testr   Údjango.corer   Údjango.confr   Úsendgrid.utilsr   r   Úsendgrid.modelsr   r+   r   r	   rO   r`   r   r   r   r   Ú<module>   s     