ó
Ż*µPc           @  s¤   d  d l  m Z d  d l 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 e j f d	     YZ d
   Z d d  Z d S(   i’’’’(   t   unicode_literalsN(   t   settings(   t   GEOSGeometry(   t   GeoIPt   GeoIPException(   t   unittest(   t   sixt	   GeoIPTestc           B  s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C  s[  t    } t j } t  | d  } t  j | d  } xI | | | f D]8 } |  j t t | j   |  j t t | j   qC Wt	 j
 j | d  } t	 j
 j | d  } t  | d d } |  j d | j  t  | d d }	 |  j d |	 j  d }
 x[ |
 D]S } |  j t t  d
 | t | t j  r7t } n t } |  j | t  | d  q Wd S(   u   Testing GeoIP initialization.i    u   GeoLiteCity.datu	   GeoIP.datt   countryu    t   cityi   u   foogö(\Āu.@t   cacheN(   i   u   foogö(\Āu.@(   R   R   t
   GEOIP_PATHt   opent   assertEqualt   Truet   boolt   _countryt   _cityt   ost   patht   joint   Nonet   assertRaisesR   t
   isinstanceR   t   string_typest	   TypeError(   t   selft   g1R   t   g2t   g3t   gR	   t   cntryt   g4t   g5t
   bad_paramst   badt   e(    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyt   test01_init   s(    			c         C  sk   t  d d  } |  j t | j d  |  j t | j d  |  j t | j d  |  j t | j t   d S(   u'   Testing GeoIP query parameter checking.R	   u   <foo>u
   google.comu	   yahoo.comi   N(   R   R   R   R	   t   coordsR   t   country_codet   country_name(   R   t   cntry_g(    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyt   test02_bad_query/   s
    c         C  sĻ   t  d d  } d } d } x­ | | f D] } x6 | j | j | j f D] } |  j d | |   qG Wx6 | j | j | j f D] } |  j d | |   q W|  j i d d 6d d 6| j |   q( Wd	 S(
   u'   Testing GeoIP country querying methods.R	   u   <foo>u   www.google.comu   12.215.42.19u   USu   United Statesu   country_codeu   country_nameN(	   R   R'   t   country_code_by_addrt   country_code_by_nameR   R(   t   country_name_by_addrt   country_name_by_nameR   (   R   R   t   fqdnt   addrt   queryt   func(    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyt   test03_country:   s    c         C  sā  t  d d  } d } d } xĄ| | f D]²} x6 | j | j | j f D] } |  j d | |   qG Wx6 | j | j | j f D] } |  j d | |   q W|  j i d d 6d d 6| j |   | j	 |  } |  j d	 | d
  |  j d | d  |  j d | d  |  j d | d  | j
 |  } |  j t | t   d \ } }	 | j |  }
 |
 d |
 d f }
 x] | j | j |  | j |  |
 f D]4 } |  j | | d d  |  j |	 | d d  q¢Wq( Wd S(   u$   Testing GeoIP city querying methods.R   u   <foo>u   128.249.1.1u   tmc.eduu   USu   United Statesu   country_codeu   country_nameu   USAu   country_code3u   Houstonu   cityu   TXu   regioniÉ  u	   area_codeglēū©ŁWĄg”Ö4ļ8µ=@i   i    i   N(   glēū©ŁWĄg”Ö4ļ8µ=@(   R   R'   R+   R,   R   R(   R-   R.   R   R	   t   geost
   assertTrueR   R   t   lat_lont   tupleR&   t   lon_latt   assertAlmostEqual(   R   R   R0   R/   R1   R2   t   dt   geomt   lont   latR6   t   tup(    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyt   test04_cityI   s.    .c         C  s0   t    } | j d  } |  j d | d  d S(   u<   Testing that GeoIP strings are properly encoded, see #16553.u   62.224.93.23u
   SchĆ¼mbergu   cityN(   R   R	   R   (   R   R   R:   (    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyt   test05_unicode_responseg   s    	c         C  s0   t    } | j d  } |  j d | d  d S(   u>   Testing that GeoIP accepts unicode string queries, see #17059.u   whitehouse.govu   USu   country_codeN(   R   R   R   (   R   R   R:   (    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyt   test06_unicode_querym   s    	(   t   __name__t
   __module__R%   R*   R3   R?   R@   RA   (    (    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyR      s   					c          C  s&   t  j   }  |  j t  j t   |  S(   N(   R   t	   TestSuitet   addTestt	   makeSuiteR   (   t   s(    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyt   suitet   s    i   c         C  s    t  j d |   j t    d  S(   Nt	   verbosity(   R   t   TextTestRunnert   runRH   (   RI   (    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyRK   y   s    (   t
   __future__R    R   t   django.confR   t   django.contrib.gis.geosR   t   django.contrib.gis.geoipR   R   t   django.utilsR   R   t   TestCaseR   RH   RK   (    (    (    s7   ../Django//lib/python/django/contrib/gis/geoip/tests.pyt   <module>   s   d	