σ
E()Qc           @@  s   d  Z  d d l m Z d d l 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 m Z d
 e	 f d     YZ d S(   s-   
Tests for geography support in PostGIS 1.5+
i    (   t   absolute_importN(   t   gdal(   t   D(   t   TestCase(   t   upathi   (   t   Cityt   Countyt   Zipcodet   GeographyTestc           B@  s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C@  s   |  j  d t j j    d S(   s*   Ensure geography features loaded properly.i   N(   t   assertEqualR   t   objectst   count(   t   self(    (    s?   ../Django//lib/python/django/contrib/gis/tests/geogapp/tests.pyt   test01_fixture_load   s    c         C@  sΣ   t  j j d d  } t t j j d | j t d d  f  j d  j	 d d t
  } t t j j d | j t d d  f  j d  j	 d d t
  } x- | | g D] } |  j d	 d
 d g |  q¬ Wd S(   sJ   Testing GeoQuerySet distance lookup support on non-point geography fields.t   codet   77002t   point__distance_ltet   miiτ  t   namet   flatt   point__dwithint   Dallast   Houstons   Oklahoma CityN(   R   R
   t   gett   listR   t   filtert   polyR   t   order_byt   values_listt   TrueR	   (   R   t   zt   cities1t   cities2t   cities(    (    s?   ../Django//lib/python/django/contrib/gis/tests/geogapp/tests.pyt   test02_distance_lookup   s    		c         C@  s.   t  j j d d  } t j j | j  } d S(   sE   Testing GeoQuerySet.distance() support on non-point geography fields.R   R   N(   R   R
   R   R   t   distancet   point(   R   t   htownt   qs(    (    s?   ../Django//lib/python/django/contrib/gis/tests/geogapp/tests.pyt   test03_distance_method$   s    c         C@  s   t  j j d d  } |  j t t j j d | j  j  |  j t t j j d | j  j  t j j d d  } |  j t t j j d | j	 d S(	   sU   Ensuring exceptions are raised for operators & functions invalid on geography fields.R   R   t   point__withint   point__containedR   R   t   point__exactN(
   R   R
   R   t   assertRaisest
   ValueErrorR   R   R   R   R$   (   R   R   R%   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/geogapp/tests.pyt"   test04_invalid_operators_functions*   s
    %%c         C@  s  t  j s d Sd d l m } t j j t j j t j j t	 t
   d d   } t j j | d d  } i d d	 6d
 d 6d d 6} d d d d d g } d d d d d g } d d d d d g } | t | | d d d d	 } | j d t d t  x t t j j d	  | | |  D]g \ }	 }
 } } |  j d |	 j j  |  j | t |	 j   |  j |
 |	 j  |  j | |	 j  qWd S(   s=   Testing LayerMapping support on models with geography fields.Ni    (   t   LayerMappings   ..t   datat   countiess   counties.shpt   NameR   t   Statet   statet   MULTIPOLYGONt   mpolyt   Bexart	   Galvestont   Harrist   Honolulut   Puebloi   i   i   t   Texast   Hawaiit   Coloradot
   source_srsi­  t   uniquet   silentt   strictiζ  (   R   t   HAS_GDALt   django.contrib.gis.utilsR.   t   ost   patht   realpatht   joint   dirnameR   t   __file__R   t   saveR   t   zipR
   R   R	   R5   t   sridt   lenR   R3   (   R   R.   t   shp_patht   co_shpt
   co_mappingt   namest	   num_polyst   st_namest   lmt   cR   t   num_polyR3   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/geogapp/tests.pyt   test05_geography_layermapping9   s$    	 6

4c         C@  sD   d } d } t  j j   j d d  } |  j | j j | |  d S(   s9   Testing that Area calculations work on geography columns.gB5-ΏTAi   R   R   N(   R   R
   t   areaR   t   assertAlmostEqualt   sq_m(   R   t   ref_areat   tolR   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/geogapp/tests.pyt   test06_geography_areaV   s    (   t   __name__t
   __module__R   R"   R'   R-   RW   R]   (    (    (    s?   ../Django//lib/python/django/contrib/gis/tests/geogapp/tests.pyR      s   					(   t   __doc__t
   __future__R    RD   t   django.contrib.gisR   t   django.contrib.gis.measureR   t   django.testR   t   django.utils._osR   t   modelsR   R   R   R   (    (    (    s?   ../Django//lib/python/django/contrib/gis/tests/geogapp/tests.pyt   <module>   s   