o
    .j!                     @   s^   d Z ddlmZ ddlZddlmZ ddlmZ G dd dZG dd	 d	ZG d
d dZ	dS )z<Tests for issue #870: Add new() method to vCalAddress class.    )datetimeN)Event)vCalAddressc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zej	
d
g ddd Zej	
dddgdd Zej	
dg ddd Zdd Zdd Zdd ZdS )TestVCalAddressNewz0Test the vCalAddress.new() method functionality.c                 C   s0   t d}t|dksJ t|jdksJ dS )z*Test creating vCalAddress with email only.test@test.commailto:test@test.comr   N)r   newstrlenparamsselfaddr r   c/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/test_issue_870_vcaladdress_new.pytest_new_with_email_only   s   
z+TestVCalAddressNew.test_new_with_email_onlyc                 C   s   t d}t|dksJ dS )z/Test that existing mailto: prefix is preserved.r   Nr   r   r	   r   r   r   r   test_new_with_mailto_prefix   s   
z.TestVCalAddressNew.test_new_with_mailto_prefixc                 C   s0   g d}|D ]}t |}t||ksJ qdS )z'Test case-insensitive mailto: handling.)zMAILTO:test@test.comzMailto:test@test.comzMailTo:test@test.comzmAiLtO:test@test.comNr   )r   
test_casesemailr   r   r   r   %test_new_with_case_insensitive_mailto   s
   
z8TestVCalAddressNew.test_new_with_case_insensitive_mailtoc                 C   s4   t jddd}t|dksJ |jd dksJ dS )z,Test creating vCalAddress with CN parameter.r   	Test Usercnr   CNNr   r   r	   r   r   r   r   r   test_new_with_cn_parameter(   s   z-TestVCalAddressNew.test_new_with_cn_parameter)argumentvalue	parameterexpected_value))cutype
INDIVIDUALCUTYPEr"   )r!   GROUPr#   r$   )r!   RESOURCEr#   r%   )r!   ROOMr#   r&   )roleREQ-PARTICIPANTROLEr(   )r'   OPT-PARTICIPANTr)   r*   )r'   NON-PARTICIPANTr)   r+   )r'   CHAIRr)   r,   )partstatNEEDS-ACTIONPARTSTATr.   )r-   ACCEPTEDr/   r0   )r-   DECLINEDr/   r1   )r-   	TENTATIVEr/   r2   )r-   	DELEGATEDr/   r3   )languageen-USLANGUAGEr5   )r4   de-DEr6   r7   )	directoryldap://example.comDIRr9   c                 C   >   ||i}t jdi |}t|dksJ |j| |ksJ dS )z6Test vCalAddress.new() with various string parameters.r   r   Nr   r   )r   r   r   r   r    kwargsr   r   r   r   test_new_with_string_parameters/   s   z2TestVCalAddressNew.test_new_with_string_parameters)
rsvp_valueexpected_param)TTRUE)FFALSEc                 C   s4   t jd|d}t|dksJ |jd |ksJ dS )z+Test vCalAddress.new() with RSVP parameter.r   )rsvpr   RSVPNr   )r   r?   r@   r   r   r   r   test_new_with_rsvp_parameterN   s   	z/TestVCalAddressNew.test_new_with_rsvp_parameter)delegate_paramdelegate_valuer@   r    ))delegated_fromsender@test.comDELEGATED-FROMmailto:sender@test.com)rH   rK   rJ   rK   )delegated_todelegate@test.comDELEGATED-TOmailto:delegate@test.com)rL   MAILTO:delegate@test.comrN   rP   )sent_bysecretary@test.comSENT-BYmailto:secretary@test.com)rQ   rT   rS   rT   c                 C   r;   )z8Test vCalAddress.new() with email delegation parameters.r   r   Nr<   r   )r   rF   rG   r@   r    r=   r   r   r   r   test_new_with_email_parameters\   s   (z1TestVCalAddressNew.test_new_with_email_parametersc                 C   s   t jddddddddd	d
dd}t|dksJ |jd dks!J |jd dks*J |jd dks3J |jd dks<J |jd dksEJ |jd dksNJ |jd dksWJ |jd d	ks`J |jd dksiJ |jd dksrJ dS )z.Test creating vCalAddress with all parameters.r   r   r"   rI   rM   r9   r5   r0   r(   TrR   )
r   r!   rH   rL   r8   r4   r-   r'   rC   rQ   r   r   r#   rJ   rK   rN   rO   r:   r6   r/   r)   rD   rA   rS   rT   Nr   r   r   r   r   test_new_with_all_parameters   s0   z/TestVCalAddressNew.test_new_with_all_parametersc                 C   sP   t jddddd}t|dksJ d|jvsJ d|jvsJ d|jvs&J dS )z&Test that None parameters are ignored.r   N)r   r'   rC   r   r   r)   rD   r   r   r   r   r   %test_new_with_none_parameters_ignored   s   z8TestVCalAddressNew.test_new_with_none_parameters_ignoredc                 C   sp   t jdddd}tj|gd}|j|gksJ |jd }t|dks$J |jd dks-J |jd	 d
ks6J dS )z7Test that vCalAddress.new() works with Event attendees.r   r   T)r   rC   )	attendeesr   r   r   rD   rA   N)r   r   r   rX   r	   r   )r   r   eventattendeer   r   r   test_new_integration_with_event   s   
z2TestVCalAddressNew.test_new_integration_with_eventN)__name__
__module____qualname____doc__r   r   r   r   pytestmarkparametrizer>   rE   rU   rV   rW   r[   r   r   r   r   r      s4    



$
r   c                   @   s    e Zd ZdZdd Zdd ZdS )TestVCalAddressNewErrorCasesz.Test error cases for vCalAddress.new() method.c                 C   s8   t t t  W d   dS 1 sw   Y  dS )z&Test that email parameter is required.Nr`   raises	TypeErrorr   r   r   r   r   r   test_new_requires_email   s   
"z4TestVCalAddressNewErrorCases.test_new_requires_emailc                 C   sx   t jtdd td W d   n1 sw   Y  t jtdd tdg W d   dS 1 s5w   Y  dS )z!Test that email must be a string.zEmail must be a string, not int)match{   Nz Email must be a string, not listr   rd   rg   r   r   r   test_new_email_must_be_string   s   "z:TestVCalAddressNewErrorCases.test_new_email_must_be_stringN)r\   r]   r^   r_   rh   rk   r   r   r   r   rc      s    rc   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TestVCalAddressNewExamplesz7Test examples that demonstrate vCalAddress.new() usage.c                 C   s   t d}t|dksJ dS )z(Test basic usage example from docstring.r   r   Nr   r   r   r   r   test_basic_usage_example   s   
z3TestVCalAddressNewExamples.test_basic_usage_examplec                 C   s8   t jdddd}|jd dksJ |jd dksJ dS )z,Test example with parameters from docstring.r   r   r,   )r   r'   r   r)   N)r   r   r   r   r   r   r   test_with_parameters_example   s   z7TestVCalAddressNewExamples.test_with_parameters_examplec                 C   s^   t jdtdddddd}tjddd	}|g|_t|jdks!J |jd jd
 dks-J dS )z=Test that vCalAddress.new() integrates well with Event.new().Testi        r   )summarystartr   r   r   r   N)r   r   r   r   rX   r
   r   )r   rY   r   r   r   r   test_consistent_with_event_new   s
   z9TestVCalAddressNewExamples.test_consistent_with_event_newN)r\   r]   r^   r_   rm   rn   rt   r   r   r   r   rl      s
    rl   )
r_   r   r`   	icalendarr   icalendar.propr   r   rc   rl   r   r   r   r   <module>   s     6