a
    YÒOcð?  ã                   @   sœ   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
 d dlmZ dZg d¢ZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    N)ÚTestCase)Útranslation)Ú	CountriesÚCountryTupleÚ	countries)Úsettings)Úcustom_countrieséù   ))ZAFZAfghanistan)ZAXu   Ã…land Islands)ÚALZAlbaniac                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚBaseTestc                 C   s   t ` d S ©N©r   ©Úself© r   ú\/var/www/html/gsl.tools/lib/python3.9/site-packages/django_countries/tests/test_countries.pyÚsetUp   s    zBaseTest.setUpc                 C   s   t ` d S r   r   r   r   r   r   ÚtearDown   s    zBaseTest.tearDownN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s   r   c                   @   s<  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d„ Zdd„ Zdd„ Zdd„ Zdd„ Zejjej dd�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/d0„ Zd1d2„ Zd3d4„ Z d5d6„ Z!d7d8„ Z"d9d:„ Z#ejjej dd�d;d<„ ƒZ$d=d>„ Z%d?d@„ Z&dAdB„ Z'dCdD„ Z(dES )FÚTestCountriesObjectc                 C   s   |   ttƒt¡ d S r   )ÚassertEqualÚlenr   ÚEXPECTED_COUNTRY_COUNTr   r   r   r   Útest_countries_len   s    z&TestCountriesObject.test_countries_lenc                 C   s   |   ttƒd d… t¡ d S )Né   )r   Úlistr   ÚFIRST_THREE_COUNTRIESr   r   r   r   Útest_countries_sorted   s    z)TestCountriesObject.test_countries_sortedc                 C   sH   t tƒd }td }|  |j|d ¡ |  |j|d ¡ |  |t¡ d S )Nr   é   )r   r   r   r   ÚcodeÚnameZassertIsInstancer   )r   ZcountryZfirst_countryr   r   r   Útest_countries_namedtuple    s
    z-TestCountriesObject.test_countries_namedtuplec                 C   sZ   | j dddœd��4 |  ttƒddg¡ |  ttƒd¡ W d   ƒ n1 sL0    Y  d S )NúNew ZealandÚ	Neverland©ÚNZÚNV©ÚCOUNTRIES_ONLY©r(   r%   ©r'   r$   é   ©r   r   r   r   r   r   r   r   r   Útest_countries_limit'   s
    ÿz(TestCountriesObject.test_countries_limitc                 C   sX   | j ddgd��4 |  ttƒddg¡ |  ttƒd¡ W d   ƒ n1 sJ0    Y  d S )Nr'   r+   r)   r,   r-   r.   r   r   r   r   Útest_countries_limit_codes.   s
    ÿz.TestCountriesObject.test_countries_limit_codesc                 C   sH   | j dd id��$ |  ttƒtd ¡ W d   ƒ n1 s:0    Y  d S )NÚAU©ZCOUNTRIES_OVERRIDEr    ©r   r   r   r   r   r   r   r   r   Ú!test_countries_custom_removed_len5   s    z5TestCountriesObject.test_countries_custom_removed_lenc                 C   sH   | j ddid��$ |  ttƒtd ¡ W d   ƒ n1 s:0    Y  d S )NÚXXr%   r2   r    r3   r   r   r   r   Útest_countries_custom_added_len9   s    z3TestCountriesObject.test_countries_custom_added_lenc                 C   s   t d  d S )Nr   r   r   r   r   r   Útest_countries_getitem=   s    z*TestCountriesObject.test_countries_getitemc                 C   s"   t ddd… }|  t|ƒd¡ d S )Né
   é   r-   é   )r   r   r   )r   Zslicedr   r   r   Útest_countries_slice@   s    z(TestCountriesObject.test_countries_slicec                 C   sJ   G dd„ dƒ}| j d|ƒ id�� tj W d   ƒ n1 s<0    Y  d S )Nc                   @   s   e Zd Zdd„ ZdS )zUTestCountriesObject.test_countries_custom_gettext_evaluation.<locals>.FakeLazyGetTextc                 S   s   t dƒ‚d S )NzCan't evaluate lazy_gettext yet)Ú
ValueErrorr   r   r   r   Ú__bool__F   s    z^TestCountriesObject.test_countries_custom_gettext_evaluation.<locals>.FakeLazyGetText.__bool__N)r   r   r   r=   r   r   r   r   ÚFakeLazyGetTextE   s   r>   r1   r2   )r   r   )r   r>   r   r   r   Ú(test_countries_custom_gettext_evaluationD   s    z<TestCountriesObject.test_countries_custom_gettext_evaluationc                 C   s   ddl m} |dd� d S )Nr-   )Úcheck_ioc_countriesr   ©Ú	verbosity)Zioc_datar@   )r   r@   r   r   r   Útest_ioc_countriesL   s    z&TestCountriesObject.test_ioc_countriesc                 C   s   t tƒ ƒ d S r   )Údictr   r   r   r   r   Útest_initial_iterQ   s    z%TestCountriesObject.test_initial_iterc                 C   s   ddl m} |dd� d S )Nr-   )Úcheck_flagsr   rA   )ÚdatarF   )r   rF   r   r   r   Ú
test_flagsU   s    zTestCountriesObject.test_flagsc                 C   s   ddl m} |ƒ  d S )Nr-   )Úcheck_common_names)rG   rI   )r   rI   r   r   r   Útest_common_namesZ   s    z%TestCountriesObject.test_common_namesúNo i18n©Úreasonc              	   C   sV   t  ¡ }t  d¡ z2|  t d¡d¡ |  t d¡d¡ W t  |¡ nt  |¡ 0 d S )NÚdeZBOZBolivienZVEZ	Venezuela)r   Úget_languageÚactivater   r   r"   ©r   Úlangr   r   r   Útest_common_name_translation_   s    
z0TestCountriesObject.test_common_name_translationc                 C   s^   |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ d S )Nr'   ZnZZNzli*  Z554©r   r   Úalpha2r   r   r   r   Útest_alpha2i   s
    zTestCountriesObject.test_alpha2c                 C   s   |   t d¡d¡ d S )Nr5   Ú rT   r   r   r   r   Útest_alpha2_invalidp   s    z'TestCountriesObject.test_alpha2_invalidc                 C   sF   | j dd id��" |  t d¡d¡ W d   ƒ n1 s80    Y  d S )Nr1   r2   rW   ©r   r   r   rU   r   r   r   r   Útest_alpha2_overrides   s    z(TestCountriesObject.test_alpha2_overridec                 C   sv   | j d ddiddidœd��F |  t d¡d¡ |  t d¡d¡ |  t d¡d¡ W d   ƒ n1 sh0    Y  d S )	NÚalpha3rW   ÚXXX©r1   r'   ÚUSr2   r1   r'   r^   )r   r   r   r[   r   r   r   r   Útest_alpha3_overridew   s    ýÿz(TestCountriesObject.test_alpha3_overridec                 C   sv   | j d dd iddidœd��F |  t d¡d ¡ |  t d¡d ¡ |  t d¡d¡ W d   ƒ n1 sh0    Y  d S )NÚnumerici„  r]   r2   r1   r'   r^   )r   r   r   r`   r   r   r   r   Útest_numeric_overrideƒ   s    ýÿz)TestCountriesObject.test_numeric_overridec                 C   sF   | j ddid��" |  t d¡d¡ W d   ƒ n1 s80    Y  d S )Nr5   r%   r2   rY   r   r   r   r   Útest_alpha2_override_new�   s    z,TestCountriesObject.test_alpha2_override_newc                 C   s   |   t d¡d¡ d S )NÚBSÚBAH)r   r   Úioc_coder   r   r   r   Útest_ioc_code“   s    z!TestCountriesObject.test_ioc_codec              	   C   sÄ   | j dd ddidddidddœd	œd
��ˆ |  t d¡dd¡ |  t d¡dd¡ |  t d¡dd¡ |  t d¡dd¡ |  t d¡dd¡ |  t d¡dd¡ W d   ƒ n1 s¶0    Y  d S )NzBahamas in Pajamasre   rW   r%   r\   ZKosovoZKOS)r"   re   )rc   r1   r'   r5   r^   ÚXKr2   rc   rd   z3Should still use built-in code if only name changedr1   z4Should be empty since country was marked not presentr'   z9Should be empty since country exists but IOC code clearedr5   z5Should be empty for a custom country with no IOC coder^   z#Should use provided custom IOC coderg   z=Should use IOC code for a custom country that provides a code)r   r   r   re   r   r   r   r   Útest_ioc_code_override–   sJ    úÿ
ýýýýÿýz*TestCountriesObject.test_ioc_code_overridec                 C   s   t  d¡}|  |d¡ d S )NZBruneiÚBN©r   Úby_namer   ©r   r!   r   r   r   Útest_fetch_by_name¾   s    
z&TestCountriesObject.test_fetch_by_namec                 C   s   t  d¡}|  |d¡ d S )Nzbrunei darussalamri   rj   rl   r   r   r   Útest_fetch_by_name_officialÂ   s    
z/TestCountriesObject.test_fetch_by_name_officialc                 C   s   t  d¡}|  |d¡ d S )NZbRuNeIri   rj   rl   r   r   r   Ú#test_fetch_by_name_case_insensitiveÆ   s    
z7TestCountriesObject.test_fetch_by_name_case_insensitivec                 C   s   t  d¡}|  |d¡ d S )NzCzech RepublicÚCZrj   rl   r   r   r   Útest_fetch_by_name_oldÊ   s    
z*TestCountriesObject.test_fetch_by_name_oldc                 C   s   t  d¡}|  |d¡ d S )NzCzech republicrp   rj   rl   r   r   r   Ú'test_fetch_by_name_old_case_insensitiveÎ   s    
z;TestCountriesObject.test_fetch_by_name_old_case_insensitivec                 C   s   t jddd�}|  |d¡ d S )NzEstados UnidosÚes)Úlanguager^   rj   rl   r   r   r   Útest_fetch_by_name_i18nÒ   s    z+TestCountriesObject.test_fetch_by_name_i18nc                 C   s   |   t d¡d¡ d S )Nr%   rW   )r   r   rk   r   r   r   r   Útest_fetch_by_name_no_match×   s    z/TestCountriesObject.test_fetch_by_name_no_matchc                 C   sx   | j ddidddgidœd��F |  t d¡d¡ |  t d¡d	¡ |  t d¡d	¡ W d   ƒ n1 sj0    Y  d S )
Nr"   ÚOzÚnamesr$   ÚHobbiton)r1   r'   r)   r1   r'   )r   r   r   rk   r   r   r   r   Útest_fetch_by_name_customÚ   s    
þÿz-TestCountriesObject.test_fetch_by_name_customc                 C   s&   t jddd�}|  t|ƒh d£¡ d S )Nz([ao])\1T)Úregex>   ZCKZCMZSX)r   rk   r   Úset)r   Úcodesr   r   r   Útest_fetch_by_name_regexå   s    z,TestCountriesObject.test_fetch_by_name_regexc                 C   s\   | j dddgiddiddœd�� ttƒ}W d   ƒ n1 s>0    Y  |  |g d	¢¡ d S )
Nrx   r$   ry   r"   rw   r%   )r'   r1   r(   r)   )©r'   ry   r+   r,   )r1   rw   ©r   r   r   r   )r   Zlist_countriesr   r   r   Útest_multiple_labelsê   s    
ýÿ&þz(TestCountriesObject.test_multiple_labelsN))r   r   r   r   r   r#   r/   r0   r4   r6   r7   r;   r?   rC   rE   rH   rJ   ÚpytestÚmarkÚskipifr   ÚUSE_I18NrS   rV   rX   rZ   r_   ra   rb   rf   rh   rm   rn   ro   rq   rr   ru   rv   rz   r~   r�   r   r   r   r   r      sF   
	(
r   c                   @   s  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d„ Zejjej dd�dd„ ƒZejjej dd�dd„ ƒZejjej dd�dd„ ƒZejjej dd�dd„ ƒZejjej dd�dd „ ƒZejjej dd�d!d"„ ƒZd#d$„ Zd%S )&ÚCountriesFirstTestc                 C   sT   | j ddgd��0 |  ttƒd d… ddgt ¡ W d   ƒ n1 sF0    Y  d S )Nr'   r1   ©ÚCOUNTRIES_FIRSTr:   r,   ©r1   Z	Australia©r   r   r   r   r   r   r   r   r   Útest_countries_firstÿ   s
    
þz'CountriesFirstTest.test_countries_firstc                 C   sV   | j ddgdd��0 |  ttƒd d… g d¢t ¡ W d   ƒ n1 sH0    Y  d S )Nr'   r1   ú------©rˆ   ÚCOUNTRIES_FIRST_BREAKé   ©r,   r‰   ©rW   rŒ   rŠ   r   r   r   r   Útest_countries_first_break  s    ÿÿþz-CountriesFirstTest.test_countries_first_breakc                 C   sn   | j g d¢dd�� ttƒ}W d   ƒ n1 s00    Y  |  |d d… g d¢t ¡ |  t|ƒtd ¡ d S )N)r5   r'   r1   rŒ   r�   r�   r�   r    ©r   r   r   r   r   r   r   ©r   Úcountries_listr   r   r   Útest_countries_first_some_valid  s    ÿ&
ÿþz2CountriesFirstTest.test_countries_first_some_validc                 C   s`   | j dgdd�� ttƒ}W d   ƒ n1 s.0    Y  |  |d d… t¡ |  t|ƒt¡ d S )Nr5   rŒ   r�   r   r“   r”   r   r   r   Útest_countries_first_no_valid  s    &z0CountriesFirstTest.test_countries_first_no_validc                 C   s|   | j ddgdd�� ttƒ}W d   ƒ n1 s00    Y  |  t|ƒtd ¡ dd„ |dd … D ƒ}| d¡ | d¡ d S )Nr'   r1   T)rˆ   ZCOUNTRIES_FIRST_REPEATr-   c                 S   s   g | ]}|d  ‘qS ©r   r   ©Ú.0Úitemr   r   r   Ú
<listcomp>&  ó    zBCountriesFirstTest.test_countries_first_repeat.<locals>.<listcomp>)r   r   r   r   r   r   Úindex©r   r•   Úsorted_codesr   r   r   Útest_countries_first_repeat"  s    &
z.CountriesFirstTest.test_countries_first_repeatc                 C   sH   | j g d¢d��$ |  ttƒtd ¡ W d   ƒ n1 s:0    Y  d S )N©r'   r1   r5   r‡   r-   r3   r   r   r   r   Útest_countries_first_len*  s    z+CountriesFirstTest.test_countries_first_lenc                 C   sJ   | j g d¢dd��$ |  ttƒtd ¡ W d   ƒ n1 s<0    Y  d S )Nr¢   rŒ   r�   r   r3   r   r   r   r   Útest_countries_first_break_len.  s    ÿz1CountriesFirstTest.test_countries_first_break_lenc                 C   sD   | j dgdd��  |  ttƒt¡ W d   ƒ n1 s60    Y  d S )Nr5   rŒ   r�   r3   r   r   r   r   Ú'test_countries_first_break_len_no_valid4  s    z:CountriesFirstTest.test_countries_first_break_len_no_validc                 C   sd   | j g d¢dd��> ttƒ}dd„ |d d… D ƒ}|  g d¢|¡ W d   ƒ n1 sV0    Y  d S )N©r'   ÚCAÚYET©rˆ   ZCOUNTRIES_FIRST_SORTc                 S   s   g | ]}|d  ‘qS r˜   r   r™   r   r   r   rœ   =  r�   zJCountriesFirstTest.test_sorted_countries_first_english.<locals>.<listcomp>r   )r§   r'   r¨   r€   rŸ   r   r   r   Ú#test_sorted_countries_first_english8  s    ÿz6CountriesFirstTest.test_sorted_countries_first_englishc                 C   sd   | j g d¢dd��> ttƒ}dd„ |d d… D ƒ}|  g d¢|¡ W d   ƒ n1 sV0    Y  d S )Nr¦   Fr©   c                 S   s   g | ]}|d  ‘qS r˜   r   r™   r   r   r   rœ   F  r�   zLCountriesFirstTest.test_unsorted_countries_first_english.<locals>.<listcomp>r   r€   )r   r•   Zunsorted_codesr   r   r   Ú%test_unsorted_countries_first_englishA  s    ÿz8CountriesFirstTest.test_unsorted_countries_first_englishrK   rL   c              
   C   s’   | j g d¢dd��l t ¡ }t d¡ z<ttƒ}dd„ |d d… D ƒ}|  g d¢|¡ W t |¡ nt |¡ 0 W d   ƒ n1 s„0    Y  d S )	Nr¦   Tr©   Úeoc                 S   s   g | ]}|d  ‘qS r˜   r   r™   r   r   r   rœ   R  r�   zMCountriesFirstTest.test_sorted_countries_first_translated.<locals>.<listcomp>r   )r¨   r§   r'   )r   r   rO   rP   r   r   r   )r   rR   r•   r    r   r   r   Ú&test_sorted_countries_first_translatedI  s    ÿ
z9CountriesFirstTest.test_sorted_countries_first_translatedc              	   C   sh   t  ¡ }t ¡ }zFt d¡ |  | d¡d¡ t d¡ |  | d¡d¡ W t |¡ nt |¡ 0 d S ©Nr¬   r'   úNov-ZelandoÚen_TestÚEndor©r   ZTranslationFallbackCountriesr   rO   rP   r   r"   ©r   Ztrans_fall_countriesrR   r   r   r   Ú*test_translation_fallback_from_common_nameX  s    

z=CountriesFirstTest.test_translation_fallback_from_common_namec              	   C   sh   t  ¡ }t ¡ }zFt d¡ |  | d¡d¡ t d¡ |  | d¡d¡ W t |¡ nt |¡ 0 d S r®   r²   r³   r   r   r   Ú'test_translation_fallback_from_old_named  s    

z:CountriesFirstTest.test_translation_fallback_from_old_namec              	   C   s°   t  ¡ }z–t  d¡ |  t d¡d¡ t  d¡ |  t d¡d¡ t j}| jd|dƒid��& t`|  t d¡d¡ W d   ƒ n1 sˆ0    Y  W t  |¡ nt  |¡ 0 d S )	Nr¬   r'   r¯   r°   r$   úMiddle Earthr2   r±   )r   rO   rP   r   r   r"   Úgettext_lazyr   )r   rR   Úgtlr   r   r   Ú"test_translation_fallback_overrideq  s    

2z5CountriesFirstTest.test_translation_fallback_overridec              
   C   sŒ   | j dd��l t ¡ }zFt d¡ |  t d¡d¡ t d¡ |  t d¡d¡ W t |¡ nt |¡ 0 W d   ƒ n1 s~0    Y  d S )NF)r…   r¬   r'   r¯   r°   r$   )r   r   rO   rP   r   r   r"   rQ   r   r   r   Ú!test_translation_fallback_no_i18nƒ  s    

z4CountriesFirstTest.test_translation_fallback_no_i18nc              
   C   s¨   t j}| jdd|dƒt  d¡giid��l t  ¡ }zFt  d¡ |  t d¡d¡ t  d¡ |  t d¡d	¡ W t  |¡ nt  |¡ 0 W d   ƒ n1 sš0    Y  d S )
Nr'   rx   r¶   r$   r2   r¬   r¯   r°   r±   )r   r·   r   rO   rP   r   r   r"   )r   r¸   rR   r   r   r   Ú(test_translation_fallback_override_names�  s"    þÿÿÿ

z;CountriesFirstTest.test_translation_fallback_override_namesc                 C   s\   | j dgddddgiddœd�� ttƒ}W d   ƒ n1 s>0    Y  |  |g d	¢¡ d S )
Nr'   rŒ   rx   r$   ry   r%   r&   )rˆ   rŽ   r*   )r,   r‘   r   r+   r€   r”   r   r   r   Útest_first_multiple_labels§  s    
þý&þz-CountriesFirstTest.test_first_multiple_labelsN)r   r   r   r‹   r’   r–   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.   
	





r†   c                   @   s   e Zd Zdd„ ZdS )ÚTestCountriesCustomc                 C   s0   t  ¡ }|  t|ƒddg¡ |  t|ƒd¡ d S )Nr+   r,   r-   )r   ZFantasyCountriesr   r   r   )r   Zfantasy_countriesr   r   r   r/   ½  s
    ÿz(TestCountriesCustom.test_countries_limitN)r   r   r   r/   r   r   r   r   r½   ¼  s   r½   )r‚   Zdjango.testr   Zdjango.utilsr   Zdjango_countriesr   r   r   Zdjango_countries.confr   Zdjango_countries.testsr   r   r   r   r   r†   r½   r   r   r   r   Ú<module>   s    f ?