U
    d=                     @   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dd	d
g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   I/tmp/pip-unpacked-wheel-dnjn05s9/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   sF   | j dddd* | ttddg | ttd W 5 Q R X 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   sD   | j ddgd* | ttddg | ttd W 5 Q R X d S )Nr'   r+   r)   r,   r-   r.   r   r   r   r   test_countries_limit_codes.   s     z.TestCountriesObject.test_countries_limit_codesc              	   C   s4   | j dd id | tttd  W 5 Q R X 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   s4   | j ddid | tttd  W 5 Q R X 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   s6   G dd d}| j d| id tj W 5 Q R X 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   sL   t  }t d z(| tdd | tdd W 5 t | X 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    rS   r   r   r   r   test_alpha2_invalidp   s    z'TestCountriesObject.test_alpha2_invalidc              	   C   s2   | j dd id | tdd W 5 Q R X d S )Nr1   r2   rV   r   r   r   rT   r   r   r   r   test_alpha2_overrides   s    z(TestCountriesObject.test_alpha2_overridec              	   C   sb   | j d ddiddidd< | tdd | tdd | tdd W 5 Q R X d S )	Nalpha3rV   XXXr1   r'   USr2   r1   r'   r]   )r   r   r   rZ   r   r   r   r   test_alpha3_overridew   s    z(TestCountriesObject.test_alpha3_overridec              	   C   sb   | j d dd iddidd< | tdd  | tdd  | tdd W 5 Q R X 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   s2   | j ddid | tdd W 5 Q R X d S )Nr5   r%   r2   rX   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 5 Q R X d S )NzBahamas in Pajamasrd   rV   r%   r[   ZKosovoZKOS)r"   rd   )rb   r1   r'   r5   r]   XKr2   rb   rc   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 coderf   z=Should use IOC code for a custom country that provides a code)r   r   r   rd   r   r   r   r   test_ioc_code_override   sN    
  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 darussalamrh   ri   rk   r   r   r   test_fetch_by_name_official   s    
z/TestCountriesObject.test_fetch_by_name_officialc                 C   s   t d}| |d d S )NZbRuNeIrh   ri   rk   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CZri   rk   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 republicro   ri   rk   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]   ri   rk   r   r   r   test_fetch_by_name_i18n   s    z+TestCountriesObject.test_fetch_by_name_i18nc                 C   s   |  tdd d S )Nr%   rV   )r   r   rj   r   r   r   r   test_fetch_by_name_no_match   s    z/TestCountriesObject.test_fetch_by_name_no_matchc              	   C   sd   | j ddidddgidd< | tdd | tdd	 | tdd	 W 5 Q R X d S )
Nr"   Oznamesr$   Hobbiton)r1   r'   r)   r1   r'   )r   r   r   rj   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|dddh d S )Nz([ao])\1T)regexZCKZCMZSX)r   rj   r   set)r   codesr   r   r   test_fetch_by_name_regex   s    z,TestCountriesObject.test_fetch_by_name_regexc              	   C   sL   | j dddgiddiddd tt}W 5 Q R X | |d	d
ddg d S )Nrw   r$   rx   r"   rv   r%   )r'   r1   r(   r)   r'   rx   r+   r,   )r1   rv   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_I18NrR   rU   rW   rY   r^   r`   ra   re   rg   rl   rm   rn   rp   rq   rt   ru   ry   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d!d" Zd#S )$CountriesFirstTestc              	   C   s@   | j ddgd& | ttd d ddgt  W 5 Q R X 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   sD   | j ddgdd( | ttd d dddgt  W 5 Q R X d S )	Nr'   r1   ------r   COUNTRIES_FIRST_BREAK   r,   r   rV   r   r   r   r   r   r   test_countries_first_break  s     z-CountriesFirstTest.test_countries_first_breakc              	   C   s^   | j dddgdd tt}W 5 Q R X | |d d ddd	gt  | t|td
  d S )Nr5   r'   r1   r   r   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   sL   | j dgdd tt}W 5 Q R X | |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   sh   | j ddgdd tt}W 5 Q R X | 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>&  s     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   s6   | j dddgd | tttd  W 5 Q R X d S )Nr'   r1   r5   r   r-   r3   r   r   r   r   test_countries_first_len*  s    z+CountriesFirstTest.test_countries_first_lenc              	   C   s8   | j dddgdd | tttd  W 5 Q R X d S )Nr'   r1   r5   r   r   r   r3   r   r   r   r   test_countries_first_break_len.  s
     z1CountriesFirstTest.test_countries_first_break_lenc              	   C   s0   | j dgdd | ttt W 5 Q R X 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   sT   | j dddgdd6 tt}dd |d d D }| dddg| W 5 Q R X d S )	Nr'   CAYETr   ZCOUNTRIES_FIRST_SORTc                 S   s   g | ]}|d  qS r   r   r   r   r   r   r   =  s     zJCountriesFirstTest.test_sorted_countries_first_english.<locals>.<listcomp>r   r   r   r   r   r   #test_sorted_countries_first_english8  s     z6CountriesFirstTest.test_sorted_countries_first_englishc              	   C   sT   | j dddgdd6 tt}dd |d d D }| dddg| W 5 Q R X d S )	Nr'   r   r   Fr   c                 S   s   g | ]}|d  qS r   r   r   r   r   r   r   F  s     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   sx   | j dddgddZ t }td z4tt}dd |d d	 D }| dddg| W 5 t| X W 5 Q R X d S )
Nr'   r   r   Tr   eoc                 S   s   g | ]}|d  qS r   r   r   r   r   r   r   R  s     zMCountriesFirstTest.test_sorted_countries_first_translated.<locals>.<listcomp>r   )r   r   rO   rP   r   r   r   )r   rQ   r   r   r   r   r   &test_sorted_countries_first_translatedI  s     
z9CountriesFirstTest.test_sorted_countries_first_translatedc              	   C   s^   t  }t }z<td | |dd td | |dd W 5 t| X d S Nr   r'   Nov-Zelandoen@testEndorr   ZTranslationFallbackCountriesr   rO   rP   r   r"   r   Ztrans_fall_countriesrQ   r   r   r   *test_translation_fallback_from_common_nameX  s    

z=CountriesFirstTest.test_translation_fallback_from_common_namec              	   C   s^   t  }t }z<td | |dd td | |dd W 5 t| X 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  }zxt d | tdd t d | tdd t j}| jd|did t`| tdd W 5 Q R X W 5 t | X d S )	Nr   r'   r   r   r$   Middle Earthr2   r   )r   rO   rP   r   r   r"   gettext_lazyr   )r   rQ   gtlr   r   r   "test_translation_fallback_overrideq  s    

 z5CountriesFirstTest.test_translation_fallback_overridec              
   C   s   t j}| jdd|dt dgiidX t  }z<t d | tdd t d | tdd	 W 5 t | X W 5 Q R X d S )
Nr'   rw   r   r$   r2   r   r   r   r   )r   r   r   rO   rP   r   r   r"   )r   r   rQ   r   r   r   (test_translation_fallback_override_names  s"    

z;CountriesFirstTest.test_translation_fallback_override_namesc              	   C   sL   | j dgddddgiddd tt}W 5 Q R X | |d	d
ddg d S )Nr'   r   rw   r$   rx   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      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 3