o
    1ir                     @   s  d dl Z d dlmZ d dlmZ d dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZ 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mZ d dlmZmZmZ d dlm Z  d dl!m"Z" d dl#m$Z$m%Z% d dl&m'Z'm(Z(m)Z)m*Z* de+fddZ,G dd deZ-G dd deZ.G dd deZ/dd Z0dd Z1G dd  d eZ2G d!d" d"eZ3G d#d$ d$eZ4G d%d& d&eZ5G d'd( d(eZ6G d)d* d*eZ7dS )+    N)mock)
skipUnless)checks
validators)NamedTemporaryFile)call_command)models)Select)modelform_factory)TestCaseoverride_settings)translation)	force_str)	countriesdatafields)settings)CountryField)custom_countriesforms)	AllowNullMultiCountryPersonWithPropreturnc                  C   s*   t jdd \} }| dkp| dko|dkS )Nr         )djangoVERSION)majorminor r!   c/var/www/html/humari/django-venv/lib/python3.10/site-packages/django_countries/tests/test_fields.pyhas_db_collation   s   r#   c                   @   s0  e Zd Zee 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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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&dFdG Z'dHS )ITestCountryFieldzDjango version < 3.2c                 C   s   t  }| t|d d S )Ndb_collation)r   r   
assertTruehasattrselfcountryr!   r!   r"   test_db_collation   s   z"TestCountryField.test_db_collationc                 C   sJ   t ddd}| |jd | |jd | |j d|_| |j d S )NChris BeavenNZnamer*   ZZ )r   assertEqualr*   assertNotEqualr&   assertFalser)   personr!   r!   r"   
test_logic%   s   zTestCountryField.test_logicc                 C   s   |  tjtj d S N)assertIsInstancer   r*   r   CountryDescriptorr)   r!   r!   r"   test_get_property_from_class/   s   z-TestCountryField.test_get_property_from_classc                 C   s,   t jd}| | ddg ddif d S )Nr*   $django_countries.fields.CountryField
max_lengthr   )r   _meta	get_fieldr2   deconstructr)   fieldr!   r!   r"   test_deconstruct2   s
   z!TestCountryField.test_deconstructc                 C   s"   t ddd}| t|jd d S )Nr,   r-   r.   )r   r2   r   r*   r5   r!   r!   r"   	test_text9   s   zTestCountryField.test_textc                 C       t ddd}| |jjd d S )Nr,   r-   r.   New Zealand)r   r2   r*   r/   r5   r!   r!   r"   	test_name=      zTestCountryField.test_namec                 C   sN   t ddd}| jdd | |jjd W d    d S 1 s w   Y  d S )Nr,   r-   r.   /static-assets/)
STATIC_URLz/static-assets/flags/nz.gifr   r   r2   r*   flagr5   r!   r!   r"   	test_flagA   s   "zTestCountryField.test_flagc                 C   s"   t dddd}| |jjd d S )Nr,   r-   USr/   r*   other_countryz//flags.example.com/us.gif)r   r2   rQ   rM   r5   r!   r!   r"   test_custom_field_flag_urlF      z+TestCountryField.test_custom_field_flag_urlc                 C   s$   t dddd}| t|jd d S )NzQuentin CoumesFRES)r/   r*   str_attr_countrySpain)r   r2   strrV   r5   r!   r!   r"   test_custom_field_str_attrJ   s   z+TestCountryField.test_custom_field_str_attrc                 C   s2   t dddd}| |jjd | |jjd d S )NMatthew SchinckelAUDErP   u   🇦🇺u   🇩🇪)r   r2   r*   unicode_flagrQ   r5   r!   r!   r"   test_unicode_flagsN   s   z#TestCountryField.test_unicode_flagsc                 C      t dd}| |jjd d S )NrZ   r/   r1   )r   r2   r*   r]   r5   r!   r!   r"   test_unicode_flag_blankS      
z(TestCountryField.test_unicode_flag_blankc                 C   s   t ddd}| jddd | |jjd W d    n1 s w   Y  | jdd	 | |jjd
 W d    d S 1 s?w   Y  d S )Nr,   r-   r.   zimg/flag-{code_upper}.pngrJ   )COUNTRIES_FLAG_URLrK   z/static-assets/img/flag-NZ.pngz*https://flags.example.com/{code_upper}.PNG)rc   z https://flags.example.com/NZ.PNGrL   r5   r!   r!   r"   test_COUNTRIES_FLAG_URL_settingW   s   "z0TestCountryField.test_COUNTRIES_FLAG_URL_settingc                 C   rF   )Nr,   r-   r.   zflag-sprite flag-n flag-_zr   r2   r*   flag_cssr5   r!   r!   r"   test_flag_cssd   rI   zTestCountryField.test_flag_cssc                 C   r_   )Nr,   r`   r1   re   r5   r!   r!   r"   test_flag_css_blankh   rb   z$TestCountryField.test_flag_css_blankc                 C   sB   t jjdd}| |jjd t jj|jd}| |jjd d S )NThe Outsiderr`   r1   pk)r   objectscreater2   r*   codegetrk   r5   r!   r!   r"   
test_blankl   s   zTestCountryField.test_blankc                 C   s>   t jjd d}| |jj t jj|jd}| |jj d S )Nr*   rj   )r   rl   rm   assertIsNoner*   rn   ro   rk   r5   r!   r!   r"   	test_nulls   s   zTestCountryField.test_nullc           	   
   C   s   zcG dd dt j}G dd dt j}t }dd |D }| |g  |jd}|jd}| |j | |j | |j	 | |j	 W dd	l
m} |d
}|j dd |j dd dS dd	l
m} |d
}|j dd |j dd w )z
        Test that multiple=True with null=True is now allowed.

        Historical note: This used to raise django_countries.E100 error,
        but that check has been removed. E100 should not be reused.
        c                   @   s   e Zd ZejddddZdS )zJTestCountryField.test_multi_null_country_allowed.<locals>.MultiNullCountryT)multiplenullblankN__name__
__module____qualname__r   r   r   r!   r!   r!   r"   MultiNullCountry   s    r{   c                   @   s   e Zd ZejdddZdS )zQTestCountryField.test_multi_null_country_allowed.<locals>.MultiNullCountryNoBlankT)rt   ru   Nrw   r!   r!   r!   r"   MultiNullCountryNoBlank   s    r|   c                 S   s   g | ]	}|j d kr|qS )zdjango_countries.E100)id).0er!   r!   r"   
<listcomp>   s    zDTestCountryField.test_multi_null_country_allowed.<locals>.<listcomp>r   r   )appsdjango_countries_testsmultinullcountryNmultinullcountrynoblank)r   Modelr   
run_checksr2   r?   r@   r&   ru   rt   django.appsr   get_app_configpop)	r)   r{   r|   errorse100_errorsfield1field2r   test_configr!   r!   r"   test_multi_null_country_allowedz   s(   

z0TestCountryField.test_multi_null_country_allowedc                 C   s8   t jjddd t jdjdd}| |jjd d S )Nr   r-   r.   r*   r`   )r   rl   rm   deferro   r2   r*   rn   r5   r!   r!   r"   test_deferred   s   zTestCountryField.test_deferredc                 C   s4   t jjddd t jd }| |jjd d S )Nr   r-   r.   r/   )r   rl   rm   onlyro   r2   r*   rn   r5   r!   r!   r"   	test_only   s   zTestCountryField.test_onlyc                 C   s0   t jjd d t jd }| |jj d S )Nrq   r*   )r   rl   rm   r   ro   rr   r*   rn   r5   r!   r!   r"   test_nullable_deferred   s   z'TestCountryField.test_nullable_deferredc                 C   s^   t ddd}| t|jd t dd d}| t|jd t ddd}| t|jd d S )Nr,   r-   r.   r   ri   r   r1   )r   r2   lenr*   r5   r!   r!   r"   test_len   s   zTestCountryField.test_lenc                 C   sj   t jjddd t jjddd t jjddd t jjdd}|djdd	d
}| t|ddg d S )Nr,   r-   r.   PavlovaKiller everythingr[   rq   r/   Tflat)r   rl   rm   filterorder_byvalues_listr2   list)r)   lookupnamesr!   r!   r"   test_lookup_text   s   z!TestCountryField.test_lookup_textc                 C   sp   t jjddd t jjddd t jjddd tjddd}t jj|d	}|jd
dd}| t|dg d S )Nr,   r-   r.   r   r   r[   r1   rn   flag_urlrq   r/   Tr   )	r   rl   rm   r   Countryr   r   r2   r   )r)   ozr   r   r!   r!   r"   test_lookup_country   s   z$TestCountryField.test_lookup_countryc                 C   s,   t jjdd t j }| |jjd d S )Nri   r`   r1   )r   rl   rm   ro   r2   r*   rn   r5   r!   r!   r"   test_save_empty_country   s   
z(TestCountryField.test_save_empty_countryc                 C   s0   t tdgd}| jd }| t|jt d S Nr*   )r   )r
   r   r   r&   
isinstancewidgetr	   )r)   Form
form_fieldr!   r!   r"   test_create_modelform   s   z&TestCountryField.test_create_modelformc                 C   s   t tdgd}|   d S r   )r
   r   as_p)r)   r   r!   r!   r"   test_render_form   s   z!TestCountryField.test_render_formc                 C   s.   t ddd}| |jjd | |jd d S )NrT   test)r*   public_field)r   r2   r*   rn   r   )r)   	with_propr!   r!   r"   test_model_with_prop   s   z%TestCountryField.test_model_with_propc                 C   sp   t jjddd t jjddd t jjddd t jjddd | tt jjddgd	jd
ddg d d S )NAr-   r.   Br[   CrT   D)country__inr/   Tr   )r   r   r   )r   rl   rm   r2   r   r   r   r;   r!   r!   r"   test_in   s   zTestCountryField.test_inc                 C   sd   t jjddd}| tt jjdd|g | tt jjddg  | tt jjddg  d S )Nr   r-   r.   )country__exactnzrG   r   rl   rm   r2   r   r   r)   pr!   r!   r"   
test_exact   s   zTestCountryField.test_exactc                 C   s0   t jjddd}| tt jjdd|g d S )Nr   r-   r.   r   )country__iexactr   r   r!   r!   r"   test_iexact   s    zTestCountryField.test_iexactc                 C   s   t jjddd}| tt jjdd|g | tt jjddg  | tt jjdd|g | tt jjddg  d S )	Nr   r-   r.   rG   )country__nameznew zealand)country__inameznew zr   r   r!   r!   r"   test_by_country_name   s
   z%TestCountryField.test_by_country_namec                 C   s   t jjddd}t jjddd}| tt jjdd||g | tt jjddg  | tt jjdd||g | tt jjdd|g | tt jjd	dg  | tt jjd	d|g d S )
Nr   r-   r.   NCewcountry__containsEW)country__icontainsr   r   r)   r   ppr!   r!   r"   test_by_country_name_contains   s    z.TestCountryField.test_by_country_name_containsc                 C   s   t jjddd}t jjddd}| tt jjdd||h | tt jjdd|g | tt jjddg  | tt jjdd	|g | tt jjdd|g | tt jjd
dg  | tt jjd
d	|g d S )Nr   ZAr.   TFSouthr   )country__startswithsouth)country__istartswithzar   rl   rm   r2   setr   r   r   r!   r!   r"   test_by_country_name_startswith	  s    z0TestCountryField.test_by_country_name_startswithc                 C   s   t jjddd}t jjddd}| tt jjdd||h | tt jjdd|g | tt jjddg  | tt jjdd	|g | tt jjdd|g | tt jjd
dg  | tt jjd
d	|g d S )Nr   ASr.   rO   Americar   )country__endswithamerica)country__iendswithusr   r   r!   r!   r"   test_by_country_name_endswith  s    z.TestCountryField.test_by_country_name_endswithc                 C   s   t jjddd}t jjddd}| tt jjdd||h | tt jjdd|g | tt jjd	dg  | tt jjd	d
|g | tt jjdd|g | tt jjddg  | tt jjdd
|g d S )Nr   MKr.   MPNorthr   zNorth\b)country__regexznorth\b)country__iregexmpr   r   r!   r!   r"   test_by_country_name_regex'  s    z+TestCountryField.test_by_country_name_regexN)(rx   ry   rz   r   r#   r+   r7   r<   rD   rE   rH   rN   rR   rY   r^   ra   rd   rg   rh   rp   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   r$      sJ    


#	
r$   c                   @   sd   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S )TestValidationc                 C      t ddd}|  d S )NChrisr-   r.   r   
full_cleanr5   r!   r!   r"   test_validate5     zTestValidation.test_validatec                 C   r   )Nr   NZLr.   r   r5   r!   r!   r"   test_validate_alpha39  r   z#TestValidation.test_validate_alpha3c                 C   s   t dd}| tj|j d S )Nr   r`   r   assertRaisesr   ValidationErrorr   r5   r!   r!   r"   test_validate_empty=  rb   z"TestValidation.test_validate_emptyc                 C   s    t ddd}| tj|j d S )Nr   :(r.   r   r5   r!   r!   r"   test_validate_invalidA  rI   z$TestValidation.test_validate_invalidc                 C   s   t ddgd}|  d S )Nr-   r[   r   r   r   r5   r!   r!   r"   test_validate_multipleE  s   z%TestValidation.test_validate_multiplec                 C   s   t  }| tj|j d S r8   r   r   r   r   r   r5   r!   r!   r"   test_validate_multiple_emptyI  s   z+TestValidation.test_validate_multiple_emptyc                 C   s"   t ddgd}| tj|j d S )Nr   r[   r   r   r5   r!   r!   r"   test_validate_multiple_invalidM  rS   z-TestValidation.test_validate_multiple_invalidc                 C   r   )Nr-   xx)r   uneditable_countriesr   r5   r!   r!   r"   !test_validate_multiple_uneditableQ  r   z0TestValidation.test_validate_multiple_uneditablec                 C   s&   t ddd}|d}| |d d S )NTrt   rv   r1   r   get_prep_valuer2   r)   country_field_instance
prep_valuer!   r!   r"    test_get_prep_value_empty_stringU     
z/TestValidation.test_get_prep_value_empty_stringc                 C   s&   t ddd}|d}| |d dS )z
        Note: django migrations will call get_prep_value() with None
        see: https://github.com/SmileyChris/django-countries/issues/215
        Tr   Nr1   r   r  r!   r!   r"   test_get_prep_value_noneZ  s   
z'TestValidation.test_get_prep_value_nonec                 C   s&   t ddd}|d}| |d d S )NTr   r   0r   r  r!   r!   r"    test_get_prep_value_invalid_typec  r  z/TestValidation.test_get_prep_value_invalid_typeN)rx   ry   rz   r   r   r   r   r   r   r   r   r  r  r  r!   r!   r!   r"   r   4  s    	r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestCountryCustomc                 C   rF   )Nr,   NVr/   fantasy_country	Neverland)r   r2   r  r/   r5   r!   r!   r"   rH   j  rI   zTestCountryCustom.test_namec                 C   s"   |  ttjdjddg d S )Nr  )r
  r  )r-   rG   )r2   r   r   r?   r@   choicesr;   r!   r!   r"   
test_fieldn  s   zTestCountryCustom.test_fieldc              
   C   s2   t jd}| | ddg tjdddf d S )Nr  r=   Tr   )r   rv   r>   )r   r?   r@   r2   rA   r   FantasyCountriesrB   r!   r!   r"   rD   t  s   z"TestCountryCustom.test_deconstructN)rx   ry   rz   rH   r  rD   r!   r!   r!   r"   r	  i  s    r	  c                  C   s0   t tjd} |  d dg tjddfksJ d S )Nr   r=      )r   r>   )r   r   GBRegionCountriesrA   )rC   r!   r!   r"   'test_longer_country_code_deconstruction  s   
r  c                  C   sX   t tjdd} t| jd tdd | jjD  }|  d dg tj|ddfks*J d S )NT)r   rt      c                 s   s    | ]}t |V  qd S r8   )r   )r~   rn   r!   r!   r"   	<genexpr>      zCtest_longer_country_code_multiple_deconstruction.<locals>.<genexpr>r=   )r   r>   rt   )r   r   r  r   r   sumrA   )rC   expected_max_lengthr!   r!   r"   0test_longer_country_code_multiple_deconstruction  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dS )TestCountryMultiplec                 C   s   t  }| |jg  d S r8   )r   r2   r   r)   objr!   r!   r"   
test_empty  s   zTestCountryMultiple.test_emptyc                 C   s   t j  d S r8   )r   rl   rm   r;   r!   r!   r"   test_empty_save  s   z#TestCountryMultiple.test_empty_savec                 C   sJ   t dd}| t|jd | t|jd tj | |jd d d S )Nr-   r   r  r   r   r2   r   r   r&   r   r   r   r  r!   r!   r"   test_single  s   
zTestCountryMultiple.test_singlec                 C   sb   t dd}| t|jd |jD ]}| t|tj q| |jd d | |jd d d S )NzAU,NZr   r   r   r[   r  r-   r  )r)   r  r*   r!   r!   r"   test_multiple  s   

z!TestCountryMultiple.test_multiplec                 C   s   d}t ||||d}|jD ]}| t|tj q| |jddg | |jddg | |jg d | |j	g d t dd}| |jg  d S )	NzNZ,AU,NZ)r   unsorted_countriesduplicate_countriesunsorted_duplicate_countriesr[   r-   )r[   r-   r-   )r-   r[   r-   r1   r   )
r   r   r&   r   r   r   r2   r"  r#  r$  )r)   codesr  r*   r!   r!   r"   test_multiple_with_duplicates  s   

z1TestCountryMultiple.test_multiple_with_duplicatesc                 C   s"   t  }d|_| |jddg d S )NzNZ,AUr[   r-   r   r   r2   r  r!   r!   r"   test_set_text  s   z!TestCountryMultiple.test_set_textc                 C   s&   t  }ddg|_| |jddg d S Nr-   r[   r'  r  r!   r!   r"   test_set_list  s   
z!TestCountryMultiple.test_set_listc                 C   s&   t  }td|_| |jdg d S )Nr-   r   r   r   r   r2   r  r!   r!   r"   test_set_country  s   z$TestCountryMultiple.test_set_countryc                 C   s2   t  }tdtdg|_| |jddg d S r)  r+  r  r!   r!   r"   test_set_countries  s   z&TestCountryMultiple.test_set_countriesc                 C   s:   t  }| jtdtdg7  _| |jddg d S r)  )r   r   r   r   r2   r  r!   r!   r"   test_add_countries  s   z&TestCountryMultiple.test_add_countriesc                 C   s.   t  }| jddg7  _| |jddg d S r)  r'  r  r!   r!   r"   test_add_country_codes  s   z*TestCountryMultiple.test_add_country_codesc                 C   s<   t dd tD }tjj|d tj }| |j| d S )Nc                 s   s    | ]}|d  V  qdS )r   Nr!   )r~   cr!   r!   r"   r    r  z9TestCountryMultiple.test_all_countries.<locals>.<genexpr>r   )sortedr   r   rl   rm   ro   r2   )r)   	all_codesr  r!   r!   r"   test_all_countries  s   
z&TestCountryMultiple.test_all_countriesc              	   C   s@   t jd}ttjd d }| | ddg |ddf d S )Nr   r   r  r=   T)r>   rt   )r   r?   r@   r   r   	COUNTRIESr2   rA   r)   rC   r  r!   r!   r"   rD     s   z$TestCountryMultiple.test_deconstructc                 C   s6   t jjddgd}t jjdd}| t||g d S )Nr-   r[   r   )countries__contains)r   rl   rm   r   r2   r   )r)   r  qsr!   r!   r"   test_contains  s   z!TestCountryMultiple.test_containsN)rx   ry   rz   r  r  r   r!  r&  r(  r*  r,  r-  r.  r/  r3  rD   r8  r!   r!   r!   r"   r    s    r  c                   @   s4   e Zd Zdd Zdd Zeddgddd	d
 ZdS )#TestCountryFieldFirstRepeatMultiplec                 C      t ` d S r8   r   r;   r!   r!   r"   setUp     z)TestCountryFieldFirstRepeatMultiple.setUpc                 C   r:  r8   r   r;   r!   r!   r"   tearDown  r<  z,TestCountryFieldFirstRepeatMultiple.tearDownr-   r[   T)COUNTRIES_FIRSTCOUNTRIES_FIRST_REPEATc                 C   sP   t dd}| tt| ttjd  ttjd d }| |j| d S )NT)rt   r   r   r  )r   r2   r   r   get_choicesr   r4  r>   r5  r!   r!   r"   test_max_length	  s   
"z3TestCountryFieldFirstRepeatMultiple.test_max_lengthN)rx   ry   rz   r;  r=  r   rA  r!   r!   r!   r"   r9    s
    r9  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dd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+S ),TestCountryObjectc                 C   s&   t jddd}| t|td d S NXXr1   r   )r   r   r2   hashr(   r!   r!   r"   	test_hash  s   zTestCountryObject.test_hashc                 C   s   t jdd}t jddd}t jddd}| t|ddd | t|ddd	dd | t|ddd
dd d S )NrD  rn   r1   r   r/   rn   str_attrzCountry(code=)z, flag_url=z, str_attr=)r   r   r2   repr)r)   country1country2country3r!   r!   r"   	test_repr  s   zTestCountryObject.test_reprc                 C   s    t jdd}| t|d d S )Nr-   rG  r   r   r2   rX   r(   r!   r!   r"   test_str(  rI   zTestCountryObject.test_strc                 C   s"   t jddd}| t|d d S )Nr-   r/   rH  rG   rP  r(   r!   r!   r"   test_str_attr,  rS   zTestCountryObject.test_str_attrc                 C   s    t jddd}| |jd d S )Nr1   r   r   r   r2   rM   r(   r!   r!   r"   test_flag_on_empty_code0     z)TestCountryObject.test_flag_on_empty_codec                 C   s    t jddd}| |jd d S )NNLr1   r   NED)r   r   r2   ioc_coder(   r!   r!   r"   test_ioc_code4  rU  zTestCountryObject.test_ioc_codec                 C   s&   t jd}| |t jddd d S )NrW  rV  r1   )r   )r   r   country_from_iocr2   r(   r!   r!   r"   test_country_from_ioc_code8  s   z,TestCountryObject.test_country_from_ioc_codec                 C      t jd}| | d S )Nr1   r   r   rZ  rr   r(   r!   r!   r"    test_country_from_blank_ioc_code<     z2TestCountryObject.test_country_from_blank_ioc_codec                 C   r\  )NXXXr]  r(   r!   r!   r"   'test_country_from_nonexistence_ioc_code@  r_  z9TestCountryObject.test_country_from_nonexistence_ioc_codec                 C      t jdd}| |jd d S )NBNrG  BRNr   r   r2   alpha3r(   r!   r!   r"   test_alpha3D     zTestCountryObject.test_alpha3c                 C   rb  )NrD  rG  r1   re  r(   r!   r!   r"   test_alpha3_invalidH  rh  z%TestCountryObject.test_alpha3_invalidc                 C   rb  )Nrc  rG  `   r   r   r2   numericr(   r!   r!   r"   test_numericL  rh  zTestCountryObject.test_numericc                 C   sR   t jdd}| |jd t jdd}| |jd t jdd}| |jd d S )NALrG  008rc  096r-   554r   r   r2   numeric_paddedr(   r!   r!   r"   test_numeric_paddedP  s   z%TestCountryObject.test_numeric_paddedc                 C      t jdd}| |jd  d S NrD  rG  rk  r(   r!   r!   r"   test_numeric_invalidX  rh  z&TestCountryObject.test_numeric_invalidc                 C   ru  rv  rr  r(   r!   r!   r"   test_numeric_padded_invalid\  rh  z-TestCountryObject.test_numeric_padded_invalidc                 C   s    t jddd}| |jd d S rC  rS  r(   r!   r!   r"   test_empty_flag_url`  rU  z%TestCountryObject.test_empty_flag_urlc                 C   rb  )Nr   rG  r-   r   r   r2   rn   r(   r!   r!   r"   test_alpha2_coded  rh  z"TestCountryObject.test_alpha2_codec                 C      t jdd}| |jd d S )NNZXrG  rz  r(   r!   r!   r"   test_alpha2_code_invalidh  rh  z*TestCountryObject.test_alpha2_code_invalidc                 C   rb  )Ni*  rG  r-   rz  r(   r!   r!   r"   test_numeric_codel  rh  z#TestCountryObject.test_numeric_codec                 C   r|  )Ni  rG  rz  r(   r!   r!   r"   test_numeric_code_invalidp  rh  z+TestCountryObject.test_numeric_code_invalidc                 C   sX   t jtdddd i tjdd}| |jd W d    d S 1 s%w   Y  d S )N
EXTENSIONScodex2c                 S   s
   | j d S )Nr   rG  )r0  r!   r!   r"   <lambda>u  s   
 z3TestCountryObject.test_extensions.<locals>.<lambda>r-   rG  NZNZ)r   patchobjectr   r   r2   r  r(   r!   r!   r"   test_extensionst  s   "z!TestCountryObject.test_extensionsN)rx   ry   rz   rF  rO  rQ  rR  rT  rY  r[  r^  ra  rg  ri  rm  rt  rw  rx  ry  r{  r~  r  r  r  r!   r!   r!   r"   rB    s,    rB  c                   @   sP   e Z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S )TestModelFormzNo i18n)reasonc              	   C   s   t  }t d t }z1| ttd d d | |jd j	d d d | |jd j
j	d d d W t | d S t | w )Neor   r  Afganior*   )r   get_languageactivater   
PersonFormr2   r   r   r   r  r   )r)   langformr!   r!   r"   test_translated_choices{  s   
 z%TestModelForm.test_translated_choicesc                 C   s   d}t  }| |jd jd | t|d ddd }| |d t  }| |jd jd | t|d ddd }d}| || d S )	N)r1   z	---------r*   r   >r  z/<select name="country" required id="id_country"r   z<<select name="countries" required id="id_countries" multiple)	r   r  r2   r   r  rX   splitMultiCountryFormr3   )r)   rv   r  html
multi_formexpectedr!   r!   r"   test_blank_choice  s   zTestModelForm.test_blank_choicec                 C   s$   t  }| |jd jd d d S )Nfavourite_countryr   )AFAfghanistan)r   r  r2   r   r  r)   r  r!   r!   r"   test_no_blank_choice  s   z"TestModelForm.test_no_blank_choicec                 C   s8   t  }| |jd jd t|d }| d| d S )Nr  r-   z<option value="NZ" selected>)r   r  r2   r   initialrX   assertInr)   r  r  r!   r!   r"   test_selected_default  s   z#TestModelForm.test_selected_defaultc                 C   sH   t  }| |jd jd d t|d ddd }| |d d S )Nr*   r   )r1   z(select country)r  r  z&<select name="country" id="id_country")r   AllowNullFormr2   r   r  rX   r  r  r!   r!   r"   test_blank_choice_label  s   z%TestModelForm.test_blank_choice_labelc                 C   s&   t jdddgid}| |ji  d S )Nr   r-   r[   )r   )r   r  r2   r   r  r!   r!   r"   test_validation  s   zTestModelForm.test_validationN)rx   ry   rz   pytestmarkskipifr   USE_I18Nr  r  r  r  r  r  r!   r!   r!   r"   r  z  s    
r  c                   @   s   e Zd Zdd Zdd ZdS )TestPicklingc                 C   s~   t ddd}tj|jdd}| t|d t|}| |jd | |j	d | |j
d  | |jt | |j d S )Nr,   r-   r.   r   protocol   rG   )r   pickledumpsr*   
assertLessr   loadsr2   rn   r/   r   assertIsr   rr   r   )r)   chrisnewly_pickled_zealand	unpickledr!   r!   r"   test_standard_country_pickling  s   
z+TestPickling.test_standard_country_picklingc                 C   st   t ddd}tj|jdd}| t|d t|}| |jd | |j	d | |j
d  | |jtj d S )Nr,   r
  r  r   r  i,  r  )r   r  r  r  r  r   r  r2   rn   r/   r   r9   r   r   r  )r)   r  pickled_neverland	neverlandr!   r!   r"   test_custom_country_pickling  s   
z)TestPickling.test_custom_country_picklingN)rx   ry   rz   r  r  r!   r!   r!   r"   r    s    r  c                   @   s   e Zd Zdd ZdS )TestLoadDatac                 C   s   t jjddd}tjjddgd}tddd(}td	d
|d |  |  |  |d td|j	dd W d    n1 sBw   Y  | 
t j jd tj j}dd |D }| 
|ddg d S )Nr,   r-   r.   r[   r   z.jsonzw+)suffixmodedumpdatar   )stdoutr   loaddataz-vr  c                 S   s   g | ]}|j qS r!   rG  )r~   r*   r!   r!   r"   r     s    z+TestLoadData.test_basic.<locals>.<listcomp>)r   rl   rm   r   r   r   deleteflushseekr/   r2   ro   r*   r   )r)   singlemulticapturer   r!   r!   r"   
test_basic  s   
zTestLoadData.test_basicN)rx   ry   rz   r  r!   r!   r!   r"   r    s    r  )8r  unittestr   unittest.caser   r   r  django.corer   r   django.core.files.tempr   django.core.managementr   	django.dbr   django.formsr	   django.forms.modelsr
   django.testr   r   django.utilsr   django.utils.encodingr   django_countriesr   r   r   django_countries.confr   django_countries.fieldsr   django_countries.testsr   r   django_countries.tests.modelsr   r   r   r   boolr#   r$   r   r	  r  r  r  r9  rB  r  r  r  r!   r!   r!   r"   <module>   sB      5
_e5#