
^Q\                 @   s  d  d l  m Z d  d l 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 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 d
 d l m Z m Z d
 d l m Z m Z m Z i d d 6e _ Gd d   d e   Z! Gd d   d e j"  Z# Gd d   d e! e j"  Z$ Gd d   d e j"  Z% Gd d   d e  Z& Gd d   d e  Z' Gd d   d e  Z( Gd d    d  e  Z) Gd! d"   d" e  Z* Gd# d$   d$ e  Z+ Gd% d&   d& e  Z, Gd' d(   d( e  Z- Gd) d*   d* e  Z. Gd+ d,   d, e j"  Z/ Gd- d.   d. e  Z0 Gd/ d0   d0 e  Z1 d S)1    )unicode_literalsN)TestCase)settings)serializers)ValidationErrorSuspiciousOperation)models)
LineStringPointGeometryCollection)
smart_text   )geojsonfeature)
Serializer)GeoJSONLayerViewTiledGeoJSONLayerView)GeoJSONFieldGeoJSONFormFieldGeoJSONValidatorzdjgeojson.serializersgeojsonc               @   s"   e  Z d  Z e d d    Z d S)PictureMixinc             C   s   d S)Nz	image.png )selfr   r   D/var/www/dbchiro/venv/lib/python3.4/site-packages/djgeojson/tests.pypicture   s    zPictureMixin.pictureN)__name__
__module____qualname__propertyr   r   r   r   r   r      s   r   c               @   sd   e  Z d  Z e j d d  Z e j d d d d  Z e j	 d k  rT e j
   Z n  d	 d
   Z d S)Country
max_length   spatial_indexFsridi  r   	   c             C   s   |  j  S)N)label)r   r   r   r   natural_key%   s    zCountry.natural_keyN)r   r$   )r   r   r   r   	CharFieldr%   ZPolygonFieldgeomdjangoVERSION
GeoManagerobjectsr&   r   r   r   r   r      s
   r   c               @   s   e  Z d  Z e j d d  Z e j d d d d  Z e j e	  Z
 d d   Z e d	 d
    Z e j d k  r e j   Z n  d S)Router    r!   r"   Fr#   i  c             C   s   |  j  S)N)name)r   r   r   r   r&   .   s    zRoute.natural_keyc             C   s   |  j  j   S)N)r.   upper)r   r   r   r   
upper_name1   s    zRoute.upper_namer   r$   N)r   r$   )r   r   r   r   r'   r.   ZLineStringFieldr(   ZManyToManyFieldr   	countriesr&   r   r0   r)   r*   r+   r,   r   r   r   r   r-   )   s   r-   c               @   s^   e  Z d  Z e j d d  Z e j e d d d e j Z	 d d   Z
 e d d	    Z d
 S)Signr    r!   Zrelated_namesignsZ	on_deletec             C   s   |  j  S)N)r%   )r   r   r   r   r&   =   s    zSign.natural_keyc             C   s   |  j  j j S)N)router(   Zcentroid)r   r   r   r   r(   @   s    z	Sign.geomN)r   r   r   r   r'   r%   Z
ForeignKeyr-   ZPROTECTr4   r&   r   r(   r   r   r   r   r2   9   s   r2   c               @   s(   e  Z d  Z d d   Z d d   Z d S)GeoJsonDeSerializerTestc             C   s   d } t  t j d |   } |  j t |  d  |  j | d j j d  |  j | d j j d  |  j | d j j t	 d d d
 | d j j j
  d  S)Na?  
        {"type": "FeatureCollection",
         "features": [
            { "type": "Feature",
                "properties": {"model": "djgeojson.route", "name": "green", "upper_name": "RED"},
                "id": 1,
                "geometry": {
                    "type": "LineString",
                    "coordinates": [
                        [0.0, 0.0],
                        [1.0, 1.0]
                    ]
                }
            },
            { "type": "Feature",
                "properties": {"model": "djgeojson.route", "name": "blue"},
                "id": 2,
                "geometry": {
                    "type": "LineString",
                    "coordinates": [
                        [0.0, 0.0],
                        [1.0, 1.0]
                    ]
                }
            }
        ]}r      r   bluer   GREEN              ?r#   )r9   r9   )r:   r:   )listr   deserializeassertEquallenobjectr.   r0   r(   r	   r#   )r   input_geojsonr,   r   r   r   
test_basicG   s    z"GeoJsonDeSerializerTest.test_basicc             C   sB   d } t  t j d | d d  d j } |  j | j d  d  S)Na  
        {"type": "FeatureCollection",
         "features": [
            { "type": "Feature",
                "properties": {"name": "bleh"},
                "id": 24,
                "geometry": {
                    "type": "LineString",
                    "coordinates": [
                        [1, 2],
                        [42, 3]
                    ]
                }
            }
        ]}r   Z
model_namezdjgeojson.router   Zbleh)r;   r   r<   r?   r=   r.   )r   r@   Z	my_objectr   r   r   'test_with_model_name_passed_as_argumento   s    	z?GeoJsonDeSerializerTest.test_with_model_name_passed_as_argumentN)r   r   r   rA   rB   r   r   r   r   r5   E   s   (r5   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 S)GeoJsonSerializerTestc          
   C   sA  t  j j d d d d  } t  j j d d d d  } t  j j d d d d  } t j t j d t  j j   d d g  } |  j | i i d	 d
 6i d d 6d d
 6d 6d 6d d
 6i i d d
 6d d g d d g g d 6d 6d d
 6i d d 6d d 6d 6| j	 d 6i i d d
 6d d g d d g g d 6d 6d d
 6i d d 6d d 6d 6| j	 d 6i i d d
 6d d g d d g g d 6d 6d d
 6i d d 6d d 6d 6| j	 d 6g d 6 t j t j d t  j j   d d d d g  } |  j | i i d	 d
 6i d d 6d d
 6d 6d 6d d
 6i i d d
 6d d g d d g g d 6d 6d d
 6i d d 6d d 6d d 6d d 6d 6| j	 d 6i i d d
 6d d g d d g g d 6d 6d d
 6i d d 6d d 6d d 6d d 6d 6| j	 d 6i i d d
 6d d g d d g g d 6d 6d d
 6i d d 6d d 6d d 6d d 6d 6| j	 d 6g d 6 d  S) Nr.   greenr(   zLINESTRING (0 0, 1 1)r7   redr   
propertieslinktypez*http://spatialreference.org/ref/epsg/4326/hrefproj4crsFeatureCollectionr	   g        g      ?coordinatesgeometryFeaturezdjgeojson.routemodelidfeaturesr0   r   z	image.pngr8   ZBLUEZRED)
r-   r,   createjsonloadsr   	serializeallr=   pk)r   route1route2route3Zactual_geojsonZactual_geojson_with_propr   r   r   rA      s     ! ,	z GeoJsonSerializerTest.test_basicc             C   s   t    } t j | j i d d 6g d d d d  } |  j | i d d 6i i d	 d 6d d g d 6d 6d d 6i  d 6g d 6 d  S)NzSRID=2154;POINT (1 1)r(   Z	precisionr6   rK   FrL   rH   r
   g(\?gQ@rM   rN   rO   rF   rR   g(\gQ)r   rT   rU   rV   r=   )r   
serializerrR   r   r   r   test_precision   s
    	"z$GeoJsonSerializerTest.test_precisionc          	   C   s   t    } t j | j i d d 6g d d d d  } |  j | i d d 6i i d	 d 6d
 d
 g d d g d d g g d 6d 6d d 6i  d 6g d 6 d  S)Nz+SRID=4326;LINESTRING (1 1, 1.5 1, 2 3, 3 3)r(   simplifyg      ?rK   FrL   rH   r	   g      ?g       @g      @rM   rN   rO   rF   rR   )r   rT   rU   rV   r=   )r   r\   rR   r   r   r   test_simplify   s
    	"z#GeoJsonSerializerTest.test_simplifyc             C   s   t    } t j | j i d d 6g d d d d  } |  j | i d d 6i i d	 d 6d
 d g d 6d 6d d 6i  d 6g d 6 d  S)NzSRID=4326;POINT Z (1 2 3)r(   force2dTrK   FrL   rH   r
   g      ?g       @rM   rN   rO   rF   rR   )r   rT   rU   rV   r=   )r   r\   
features2dr   r   r   test_force2d   s    	z"GeoJsonSerializerTest.test_force2dc             C   s^   t    } t j | j i d d 6g d d  } |  j | d i d d 6i d d 6d 6 d  S)	NzSRID=4326;POINT (1 2)r(   crs_typer.   rK   rH   z	EPSG:4326rF   )r   rT   rU   rV   r=   )r   r\   rR   r   r   r   test_named_crs   s    	z$GeoJsonSerializerTest.test_named_crsc             C   se   t    } t j | j i d d 6g d d  } |  j | d i d d 6i d d	 6d
 d 6d 6 d  S)NzSRID=4326;POINT (1 2)r(   rc   namedrK   rG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rF   )r   rT   rU   rV   r=   )r   r\   rR   r   r   r   test_misspelled_named_crs   s    	z/GeoJsonSerializerTest.test_misspelled_named_crsc             C   s   t  j j d d d d  } t   } t j | j t  j j   d d g d d  } |  j | i d	 d
 6i i d d
 6d d g d d g g d 6d 6d d
 6i d d 6| j	 d 6d 6| j	 d 6g d 6 d  S)Nr.   rE   r(   zLINESTRING (0 0, 1 1)rF   rQ   rK   FrL   rH   r	   g        g      ?rM   rN   rO   zdjgeojson.routerP   rR   )
r-   r,   rS   r   rT   rU   rV   rW   r=   rX   )r   r4   r\   ra   r   r   r   test_pk_property   s    	$z&GeoJsonSerializerTest.test_pk_propertyc             C   s   Gd d   d t  j  } t   } t j | j |   g d d d d  } i d d 6i i d	 d 6i d
 d 6d d g d d g g d 6i d d 6d d g d 6g d 6d 6d d 6i d  d 6d 6g d 6} |  j | |  d  S)Nc               @   s"   e  Z d  Z e d d    Z d S)z<GeoJsonSerializerTest.test_geometry_property.<locals>.Basketc             S   s(   t  t d d  t d d d  d	 d
 S)N                  r   r6   r#   i  )rh   ri   rj   )rk   rl   rm   )r   r	   r
   )r   r   r   r   r(      s    zAGeoJsonSerializerTest.test_geometry_property.<locals>.Basket.geomN)r   r   r   r   r(   r   r   r   r   Basket   s   rn   rK   Fr`   TrL   rH   r   r	   g      @g      @g      @g      @rM   r
   g      ?g       @Z
geometriesrN   rO   rQ   rF   rR   )r   Modelr   rT   rU   rV   r=   )r   rn   r\   rR   Zexpected_contentr   r   r   test_geometry_property   s    	${z,GeoJsonSerializerTest.test_geometry_propertyc             C   s   Gd d   d t  j  } t   } t j | j |   g d d  } |  j | i d d 6i d  d 6d d 6i d  d	 6d
 6g d 6 d  S)Nc               @   s   e  Z d  Z d Z d S)z7GeoJsonSerializerTest.test_none_geometry.<locals>.EmptyN)r   r   r   r(   r   r   r   r   Empty   s   rq   rK   FrL   rH   rN   rO   rQ   rF   rR   )r   ro   r   rT   rU   rV   r=   )r   rq   r\   rR   r   r   r   test_none_geometry   s    	$z(GeoJsonSerializerTest.test_none_geometryc             C   s   t    } t j | j i d d 6g d d d d  } |  j | i d d 6i i d	 d 6d
 d
 g d d g g d 6d 6d d 6i  d 6d
 d
 d d g d 6g d 6 d  S)NzSRID=4326;LINESTRING (1 1, 3 3)r(   Z	bbox_autoTrK   FrL   rH   r	   g      ?g      @rM   rN   rO   rF   bboxrR   )r   rT   rU   rV   r=   )r   r\   rR   r   r   r   test_bbox_auto   s    	'z$GeoJsonSerializerTest.test_bbox_autoN)r   r   r   rA   r]   r_   rb   rd   rf   rg   rp   rr   rt   r   r   r   r   rC      s   rC   c               @   s4   e  Z d  Z d d   Z d d   Z d d   Z d S)ForeignKeyTestc             C   s>   t  j j d d d d  |  _ t d d d |  j  j   d  S)Nr.   rD   r(   zLINESTRING (0 0, 1 1)r%   Ar4   )r-   r,   rS   r4   r2   save)r   r   r   r   setUp   s    zForeignKeyTest.setUpc             C   s   t    } t j | j t j j   d d g  } |  j | i i d d 6i d d 6d d 6d 6d 6d	 d 6i i d
 d 6d d g d 6d 6d d 6i d d 6d d 6d 6|  j j	 d 6g d 6 d  S)NrF   r4   rG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rK   rL   r
   g      ?rM   rN   rO   r   zdjgeojson.signrP   rQ   rR   )
r   rT   rU   rV   r2   r,   rW   r=   r4   rX   )r   r\   rR   r   r   r   test_serialize_foreign   s    	*z%ForeignKeyTest.test_serialize_foreignc             C   s   t    } t j | j t j j   d d d d g  } |  j | i i d d 6i d d 6d	 d 6d 6d
 6d d 6i i d d 6d d g d 6d 6d d 6i d d 6d d 6d 6|  j j	 d 6g d 6 d  S)Nuse_natural_keysTrF   r4   rG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rK   rL   r
   g      ?rM   rN   rO   rD   zdjgeojson.signrP   rQ   rR   )
r   rT   rU   rV   r2   r,   rW   r=   r4   rX   )r   r\   rR   r   r   r   test_serialize_foreign_natural  s
    	$z-ForeignKeyTest.test_serialize_foreign_naturalN)r   r   r   rx   ry   r{   r   r   r   r   ru      s   ru   c               @   s4   e  Z d  Z d d   Z d d   Z d d   Z d S)ManyToManyTestc             C   s   t  d d d d  } | j   t  d d d d  } | j   t j j d d d d  |  _ t j j d d	 d d  |  _ |  j j j |  t j j d d
 d d  |  _	 |  j	 j j |  |  j	 j j |  d  S)Nr%   C1r(   zPOLYGON ((0 0,1 1,0 2,0 0))C2r.   rD   zLINESTRING (0 0, 1 1)r7   rE   )
r   rw   r-   r,   rS   rY   rZ   r1   addr[   )r   Zcountry1Zcountry2r   r   r   rx     s    

zManyToManyTest.setUpc          
   C   sz  t    } t j | j t j j   d d g  } |  j | i i d d 6i d d 6d d 6d 6d 6d	 d 6i i d
 d 6d d g d d g g d 6d 6d d 6i d d 6g  d 6d 6|  j j	 d 6i i d
 d 6d d g d d g g d 6d 6d d 6i d d 6d g d 6d 6|  j
 j	 d 6i i d
 d 6d d g d d g g d 6d 6d d 6i d d 6d d g d 6d 6|  j j	 d 6g d 6 d  S)NrF   r1   rG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rK   rL   r	   g        g      ?rM   rN   rO   zdjgeojson.routerP   rQ   r   r6   rR   )r   rT   rU   rV   r-   r,   rW   r=   rY   rX   rZ   r[   )r   r\   rR   r   r   r   test_serialize_manytomany  s
    	z(ManyToManyTest.test_serialize_manytomanyc          
   C   s  t    } t j | j t j j   d d d d g  } |  j | i i d d 6i d d 6d	 d 6d 6d
 6d d 6i i d d 6d d g d d g g d 6d 6d d 6i d d 6g  d 6d 6|  j j	 d 6i i d d 6d d g d d g g d 6d 6d d 6i d d 6d g d 6d 6|  j
 j	 d 6i i d d 6d d g d d g g d 6d 6d d 6i d d 6d d g d 6d 6|  j j	 d 6g d 6 d  S)Nrz   TrF   r1   rG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rK   rL   r	   g        g      ?rM   rN   rO   zdjgeojson.routerP   rQ   r}   r~   rR   )r   rT   rU   rV   r-   r,   rW   r=   rY   rX   rZ   r[   )r   r\   rR   r   r   r   !test_serialize_manytomany_natural"  s
    	$z0ManyToManyTest.test_serialize_manytomany_naturalN)r   r   r   rx   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	 S)
ReverseForeignkeyTestc             C   s   t  d d d d  |  _ |  j j   t j j d d d |  j  |  _ t j j d d d |  j  |  _ t j j d d	 d |  j  |  _ d  S)
Nr.   rD   r(   zLINESTRING (0 0, 1 1)r%   rv   r4   BC)	r-   r4   rw   r2   r,   rS   sign1sign2sign3)r   r   r   r   rx   ,  s
    !!zReverseForeignkeyTest.setUpc             C   s&   |  j  t |  j j j    d  d  S)Nrh   )r=   r>   r4   r3   rW   )r   r   r   r   test_relation_set3  s    z'ReverseForeignkeyTest.test_relation_setc             C   s   t    } t j | j t j j   d d g  } |  j | i i d d 6i d d 6d d 6d 6d 6d	 d 6i i d
 d 6d d g d d g g d 6d 6d d 6i d d 6|  j j	 |  j
 j	 |  j j	 g d 6d 6|  j j	 d 6g d 6 d  S)NrF   r3   rG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rK   rL   r	   g        g      ?rM   rN   rO   zdjgeojson.routerP   rQ   rR   )r   rT   rU   rV   r-   r,   rW   r=   r   rX   r   r   r4   )r   r\   rR   r   r   r   test_serialize_reverse6  s*    	
		z,ReverseForeignkeyTest.test_serialize_reversec             C   s   t    } t j | j t j j   d d d d g  } |  j | i i d d 6i d d 6d	 d 6d 6d
 6d d 6i i d d 6d d g d d g g d 6d 6d d 6i d d 6d d d g d 6d 6|  j j	 d 6g d 6 d  S)Nrz   TrF   r3   rG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rK   rL   r	   g        g      ?rM   rN   rO   zdjgeojson.routerP   rv   r   r   rQ   rR   )
r   rT   rU   rV   r-   r,   rW   r=   r4   rX   )r   r\   rR   r   r   r   test_serialize_reverse_naturalS  s(    	$z4ReverseForeignkeyTest.test_serialize_reverse_naturalN)r   r   r   rx   r   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 S)GeoJsonTemplateTagTestc             C   s^   t  j j d d d d  |  _ t  j j d d d d  |  _ t  j j d d d d  |  _ d  S)Nr.   rD   r(   zLINESTRING (0 0, 1 1)r7   rE   )r-   r,   rS   rY   rZ   r[   )r   r   r   r   rx   p  s    zGeoJsonTemplateTagTest.setUpc             C   s   t  j t |  j   } |  j | i i d d 6i d d 6d d 6d 6d 6d d 6i i d	 d 6d
 d
 g d d g g d 6d 6d d 6i  d 6g d 6 d  S)NrG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rF   rK   rL   r	   g        g      ?rM   rN   rO   rR   )rT   rU   r   rY   r=   )r   featurer   r   r   &test_templatetag_renders_single_objectx  s    z=GeoJsonTemplateTagTest.test_templatetag_renders_single_objectc          
   C   sG  t  j t t j j     } |  j | i i d d 6i d d 6d d 6d 6d 6d d 6i i d	 d 6d
 d
 g d d g g d 6d 6d d 6i d d 6d 6|  j j d 6i i d	 d 6d
 d
 g d d g g d 6d 6d d 6i d d 6d 6|  j	 j d 6i i d	 d 6d
 d
 g d d g g d 6d 6d d 6i d d 6d 6|  j
 j d 6g d 6 d  S)NrG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rF   rK   rL   r	   g        g      ?rM   rN   rO   zdjgeojson.routerP   rQ   rR   )rT   rU   r   r-   r,   rW   r=   rY   rX   rZ   r[   )r   r   r   r   r   !test_templatetag_renders_queryset  s:    

z8GeoJsonTemplateTagTest.test_templatetag_renders_querysetc             C   sd   t  j t |  j j   } |  j | i i d d 6d d g d d g g d 6d 6d d 6i  d 6 d  S)	Nr	   rH   g        g      ?rM   rN   rO   rF   )rT   rU   r   rY   r(   r=   )r   r   r   r   r   test_template_renders_geometry  s    
z5GeoJsonTemplateTagTest.test_template_renders_geometryc             C   sK   t  j t |  j d   } | d d } |  j | d d |  j j  d  S)Nr.   rR   r   rF   )rT   rU   r   rY   r=   r.   )r   rR   r   r   r   r   test_property_can_be_specified  s
    z5GeoJsonTemplateTagTest.test_property_can_be_specifiedc             C   s[   t  j t |  j d   } | d d } |  j | d i |  j j d 6|  j j d 6 d  S)Nzname,idrR   r   rF   r.   rQ   )rT   rU   r   rY   r=   r.   rQ   )r   rR   r   r   r   r   (test_several_properties_can_be_specified  s    z?GeoJsonTemplateTagTest.test_several_properties_can_be_specifiedc             C   sL   t  j t |  j j d   } |  j | d d d d g d d g g  d  S)Nz::2154rN   rM   g	PAgr+AgOAg`Jw0A)rT   rU   r   rY   r(   r=   )r   r   r   r   r   test_srid_can_be_specified  s    	z1GeoJsonTemplateTagTest.test_srid_can_be_specifiedc             C   sW   t  j t |  j d   } | d d } |  j | d d d d g d d g g  d  S)Nz:geomrR   r   rN   rM   g        g      ?)rT   rU   r   rY   r=   )r   rR   r   r   r   r   %test_geom_field_name_can_be_specified  s    z<GeoJsonTemplateTagTest.test_geom_field_name_can_be_specifiedc             C   s   |  j  t t |  j d  d  S)Nz:geo)assertRaisesAttributeErrorr   rY   )r   r   r   r   0test_geom_field_raises_attributeerror_if_unknown  s    zGGeoJsonTemplateTagTest.test_geom_field_raises_attributeerror_if_unknownN)r   r   r   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   n  s   *	r   c               @   sL   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d S)	ViewsTestc             C   s>   t  j j d d d d  |  _ t d d d |  j  j   d  S)Nr.   rD   r(   zLINESTRING (0 0, 1 1)r%   rv   r4   )r-   r,   rS   r4   r2   rw   )r   r   r   r   rx     s    zViewsTest.setUpc             C   sx   t  d t  } g  | _ | j d i   } t j t | j   } |  j | d d d d d d g d d g g  d  S)	NrP   contextrR   r   rN   rM   g        g      ?)	r   r-   object_listrender_to_responserT   rU   r   contentr=   )r   viewresponser   r   r   r   test_view_default_options  s    	z#ViewsTest.test_view_default_optionsc             C   s|   Gd d   d t   } | d t  } g  | _ | j d i   } t j t | j   } |  j | d d d d d	  d  S)
Nc               @   s   e  Z d  Z d g Z d S)z?ViewsTest.test_view_can_control_properties.<locals>.FullGeoJSONr.   N)r   r   r   rF   r   r   r   r   FullGeoJSON  s   r   rP   r   rR   r   rF   r.   rD   )	r   r-   r   r   rT   rU   r   r   r=   )r   r   r   r   r   r   r   r    test_view_can_control_properties  s    	z*ViewsTest.test_view_can_control_propertiesc             C   s|   Gd d   d t   } | d t  } g  | _ | j d i   } t j t | j   } |  j | d d d d d	  d  S)
Nc               @   s   e  Z d  Z d d g Z d S)z0ViewsTest.test_view_foreign.<locals>.FullGeoJSONr%   r4   N)r   r   r   rF   r   r   r   r   r     s   r   rP   r   rR   r   rF   r4   r   )	r   r2   r   r   rT   rU   r   r   r=   )r   r   r   r   r   r   r   r   test_view_foreign  s    	zViewsTest.test_view_foreignc             C   s|   Gd d   d t   } | d t  } g  | _ | j d i   } t j t | j   } |  j | d d d d d	  d  S)
Nc               @   s"   e  Z d  Z d d g Z d Z d S)z8ViewsTest.test_view_foreign_natural.<locals>.FullGeoJSONr%   r4   TN)r   r   r   rF   rz   r   r   r   r   r     s   r   rP   r   rR   r   rF   r4   rD   )	r   r2   r   r   rT   rU   r   r   r=   )r   r   r   r   r   r   r   r   test_view_foreign_natural   s    	z#ViewsTest.test_view_foreign_naturalN)r   r   r   rx   r   r   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	 S)
TileEnvelopTestc             C   s   t    |  _ d  S)N)r   r   )r   r   r   r   rx     s    zTileEnvelopTest.setUpc             C   s/   d |  j  _ |  j t |  j  j d d d  d  S)Nij  r   )r   Z	tile_sridr   AssertionError
tile_coord)r   r   r   r   +test_raises_error_if_not_spherical_mercator  s    z;TileEnvelopTest.test_raises_error_if_not_spherical_mercatorc             C   s&   |  j  d |  j j d d d   d  S)Ng     f@IECU@r        f)r   r   )r=   r   r   )r   r   r   r   $test_origin_is_north_west_for_tile_0  s    	z4TileEnvelopTest.test_origin_is_north_west_for_tile_0c             C   s&   |  j  d |  j j d d d   d  S)Nr   rm   ri   )r   r   )r=   r   r   )r   r   r   r   %test_origin_is_center_for_middle_tile  s    z5TileEnvelopTest.test_origin_is_center_for_middle_tileN)r   r   r   rx   r   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 d d   Z d d    Z d! d"   Z d# d$   Z d% d&   Z d' S)(TiledGeoJSONViewTestc             C   sd   t  d t  |  _ g  |  j _ t j j d t d d   |  _ t j j d t d	 d   |  _ d  S)NrP   r(   r   r   
   )r   r   )r   r   )r   r   r   )r   r   )	r   r-   r   argsr,   rS   r	   r1Zr2)r   r   r   r   rx     s    !zTiledGeoJSONViewTest.setUpc             C   s   i d d 6d d 6d d 6|  j  _ |  j  j d i   } t j t | j   } |  j | d d	 d
 d d d g d d g g  d  S)Nri   zrm   xrl   yr   rR   r   rN   rM   g        g      ?g      $@)r   kwargsr   rT   rU   r   r   r=   )r   r   r   r   r   r   test_view_with_kwargs#  s    
z*TiledGeoJSONViewTest.test_view_with_kwargsc             C   sA   i d d 6d d 6d d 6|  j  _ |  j t |  j  j d i  d  S)Nar   rm   r   rl   r   r   )r   r   r   r   r   )r   r   r   r   "test_view_with_kwargs_wrong_type_z+  s    
	z7TiledGeoJSONViewTest.test_view_with_kwargs_wrong_type_zc             C   sA   i d d 6d d 6d d 6|  j  _ |  j t |  j  j d i  d  S)Nr   r   r   r   rl   r   r   )r   r   r   r   r   )r   r   r   r   "test_view_with_kwargs_wrong_type_x3  s    
	z7TiledGeoJSONViewTest.test_view_with_kwargs_wrong_type_xc             C   sA   i d d 6d d 6d d 6|  j  _ |  j t |  j  j d i  d  S)Nri   r   rm   r   r   r   r   )r   r   r   r   r   )r   r   r   r   "test_view_with_kwargs_wrong_type_y;  s    
	z7TiledGeoJSONViewTest.test_view_with_kwargs_wrong_type_yc             C   s:   i d d 6d d 6|  j  _ |  j t |  j  j d i  d  S)Nrm   r   rl   r   r   )r   r   r   r   r   )r   r   r   r   test_view_with_kwargs_no_zC  s
    
	z/TiledGeoJSONViewTest.test_view_with_kwargs_no_zc             C   s:   i d d 6d d 6|  j  _ |  j t |  j  j d i  d  S)Nrm   r   rl   r   r   )r   r   r   r   r   )r   r   r   r   test_view_with_kwargs_no_xJ  s
    
	z/TiledGeoJSONViewTest.test_view_with_kwargs_no_xc             C   s:   i d d 6d d 6|  j  _ |  j t |  j  j d i  d  S)Nrm   r   rl   r   r   )r   r   r   r   r   )r   r   r   r   test_view_with_kwargs_no_yQ  s
    
	z/TiledGeoJSONViewTest.test_view_with_kwargs_no_yc             C   sx   d d d g |  j  _ |  j  j d i   } t j t | j   } |  j | d d d d d	 d
 g d d
 g g  d  S)Nri   rm   rl   r   rR   r   rN   rM   g        g      ?g      $@)r   r   r   rT   rU   r   r   r=   )r   r   r   r   r   r   "test_view_is_serialized_as_geojsonX  s
    z7TiledGeoJSONViewTest.test_view_is_serialized_as_geojsonc             C   sx   d d d g |  j  _ |  j  j d i   } t j t | j   } |  j | d d d d d	 d
 g d d
 g g  d  S)Nrm         r   rR   r   rN   rM   g        g      ?g     ?)r   r   r   rT   rU   r   r   r=   )r   r   r   r   r   r   (test_view_trims_to_geometries_boundaries_  s
    z=TiledGeoJSONViewTest.test_view_trims_to_geometries_boundariesc             C   s   d d d g |  j  _ d |  j  _ |  j  j d i   } t j t | j   } |  j | d d d d	 d
 d g d d g g  d  S)Nrm   r   r   Fr   rR   r   rN   rM   g        g      ?g      $@)	r   r   Ztrim_to_boundaryr   rT   rU   r   r   r=   )r   r   r   r   r   r   $test_geometries_trim_can_be_disabledf  s    z9TiledGeoJSONViewTest.test_geometries_trim_can_be_disabledc             C   sf   d d d g |  j  _ |  j  j d i   } t j t | j   } |  j | d d d d d g  d  S)	Nrm   r   r   r   rs   g        g     ?gelk?)r   r   r   rT   rU   r   r   r=   )r   r   r   r   r   r   *test_tile_extent_is_provided_in_collectionn  s
    z?TiledGeoJSONViewTest.test_tile_extent_is_provided_in_collectionc             C   s8   d d d g |  j  _ |  j d t |  j  j     d  S)N0r6   )r   r   r=   r>   get_queryset)r   r   r   r   (test_url_parameters_are_converted_to_intu  s    z=TiledGeoJSONViewTest.test_url_parameters_are_converted_to_intc             C   s8   d d d g |  j  _ |  j d t |  j  j     d  S)Nr   r6   )r   r   r=   r>   r   )r   r   r   r   !test_zoom_0_queryset_contains_ally  s    z6TiledGeoJSONViewTest.test_zoom_0_queryset_contains_allc             C   s>   d d d g |  j  _ |  j |  j g t |  j  j     d  S)Nri   rm   rl   )r   r   r=   r   r;   r   )r   r   r   r   "test_zoom_4_filters_by_tile_extent}  s    z7TiledGeoJSONViewTest.test_zoom_4_filters_by_tile_extentc             C   s8   d d d g |  j  _ |  j d t |  j  j     d  S)Nri   rk   rm   r   )r   r   r=   r>   r   )r   r   r   r   #test_some_tiles_have_empty_queryset  s    z8TiledGeoJSONViewTest.test_some_tiles_have_empty_querysetc             C   sO   i d d 6|  j  _ d d d g |  j  _ |  j  j   |  j |  j  j d  d  S)Nd   rk   rm   ri   )r   simplificationsr   r   r=   r^   )r   r   r   r   )test_simplification_depends_on_zoom_level  s    z>TiledGeoJSONViewTest.test_simplification_depends_on_zoom_levelc             C   sH   i  |  j  _ d d d g |  j  _ |  j  j   |  j |  j  j d   d  S)Nr   rm   ri   )r   r   r   r   r=   r^   )r   r   r   r   /test_simplification_is_default_if_not_specified  s    zDTiledGeoJSONViewTest.test_simplification_is_default_if_not_specifiedc             C   sV   i d d 6d d 6|  j  _ d d d g |  j  _ |  j  j   |  j |  j  j d  d  S)Nr   rh      rk   ri   rm   )r   r   r   r   r=   r^   )r   r   r   r   1test_simplification_takes_the_closest_upper_level  s    zFTiledGeoJSONViewTest.test_simplification_takes_the_closest_upper_levelN)r   r   r   rx   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 e   Z d S)AddressN)r   r   r   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 S)ModelFieldTestc             C   s=   t    |  _ i d d 6d d g d 6|  j _ |  j j   d  S)Nr
   rH   r   rM   )r   addressr(   rw   )r   r   r   r   rx     s     zModelFieldTest.setUpc             C   sr   t  j j d |  j j  } t | j t  rI |  j | j |  j j  n% |  j	 t
 j | j j  |  j j  d  S)NrQ   )r   r,   getr   rQ   
isinstancer(   dictZassertDictEqualr=   rT   rU   r   )r   Zsavedr   r   r   #test_models_can_have_geojson_fields  s    z2ModelFieldTest.test_models_can_have_geojson_fieldsc             C   s5   |  j  j j d  j   } |  j t | t   d  S)Nr(   )r   _meta	get_field	formfield
assertTruer   r   )r   fieldr   r   r   'test_default_form_field_is_geojsonfield  s    z6ModelFieldTest.test_default_form_field_is_geojsonfieldc             C   sB   |  j  j j d  j   } | j d } |  j t | t   d  S)Nr(   r   )r   r   r   r   Z
validatorsr   r   r   )r   r   	validatorr   r   r   -test_default_form_field_has_geojson_validator  s    z<ModelFieldTest.test_default_form_field_has_geojson_validatorc             C   sC   |  j  j j d  j   } |  j t | j i d d 6d d 6 d  S)Nr(   rL   rH   barfoo)r   r   r   r   r   r   clean)r   r   r   r   r   &test_form_field_raises_if_invalid_type  s    z5ModelFieldTest.test_form_field_raises_if_invalid_typec             C   s<   |  j  j j d  j   } |  j t | j i d d 6 d  S)Nr(   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   &test_form_field_raises_if_type_missing  s    z5ModelFieldTest.test_form_field_raises_if_type_missingc             C   s   t    } | j t j j   d d } t j |  } |  j | i d d 6i |  j j	 d 6d d 6i d d 6d d g d	 6d
 6i d d 6d 6g d 6 d  S)NrK   FrL   rH   rQ   rO   r
   r   rM   rN   zdjgeojson.addressrP   rF   rR   )
r   rV   r   r,   rW   rT   rU   r=   r   rQ   )r   r\   r   rR   r   r   r   test_field_can_be_serialized  s    	z+ModelFieldTest.test_field_can_be_serializedc             C   sP   d } t  t j d |   } |  j | d j j i d d 6d d g d 6 d  S)NaQ  
        {"type": "FeatureCollection",
         "features": [
            { "type": "Feature",
                "properties": {"model": "djgeojson.address"},
                "id": 1,
                "geometry": {
                    "type": "Point",
                    "coordinates": [0.0, 0.0]
                }
            }
        ]}r   r   r
   rH   rM   )r;   r   r<   r=   r?   r(   )r   r@   r,   r   r   r   test_field_can_be_deserialized  s    z-ModelFieldTest.test_field_can_be_deserializedc             C   s   t    } | j t j j   d d } t j |  } |  j | i i d d 6i d d 6d d 6d 6d	 6d
 d 6i |  j j	 d 6d d 6i d d 6d d g d 6d 6i  d 6g d 6 d  S)NZwith_modelnameFrG   rH   z*http://spatialreference.org/ref/epsg/4326/rI   rJ   rF   rK   rL   rQ   rO   r
   r   rM   rN   rR   )
r   rV   r   r,   rW   rT   rU   r=   r   rQ   )r   r\   r   rR   r   r   r   test_model_can_be_omitted  s"    		z(ModelFieldTest.test_model_can_be_omittedN)r   r   r   rx   r   r   r   r   r   r   r   r   r   r   r   r   r     s   r   c               @   sL   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d S)GeoJSONValidatorTestc             C   s*   t  d  } |  j t | i d d 6 d  S)NGEOMETRYr   r   )r   r   r   )r   r   r   r   r   %test_validator_raises_if_missing_type  s    z:GeoJSONValidatorTest.test_validator_raises_if_missing_typec             C   s1   t  d  } |  j t | i d d 6g  d 6 d  S)Nr   rL   rH   rR   )r   r   r   )r   r   r   r   r   &test_validator_raises_if_type_is_wrong  s    
z;GeoJSONValidatorTest.test_validator_raises_if_type_is_wrongc             C   s7   t  d  } |  j | i d d 6d d g d 6  d  S)NPOINTr
   rH   r   coords)r   assertIsNone)r   r   r   r   r   'test_validator_succeeds_if_type_matches  s    z<GeoJSONValidatorTest.test_validator_succeeds_if_type_matchesc             C   s   t  d  } |  j | i d d 6d d g d 6  |  j | i d d 6d d g d 6  |  j | i d d 6d d g d 6  d  S)Nr   r
   rH   r   r   r	   ZPolygon)r   r   )r   r   r   r   r   *test_validator_succeeds_if_type_is_generic  s    ''z?GeoJSONValidatorTest.test_validator_succeeds_if_type_is_genericc             C   s7   t  d  } |  j t | i d d 6d d g d 6 d  S)Nr   r	   rH   r   r   )r   r   r   )r   r   r   r   r   +test_validator_fails_if_type_does_not_match  s    z@GeoJSONValidatorTest.test_validator_fails_if_type_does_not_matchN)r   r   r   r   r   r   r   r   r   r   r   r   r     s
   r   )2
__future__r   rT   r)   Zdjango.testr   Zdjango.confr   Zdjango.corer   Zdjango.core.exceptionsr   r   Zdjango.contrib.gis.dbr   Zdjango.contrib.gis.geosr	   r
   r   Zdjango.utils.encodingr   Ztemplatetags.geojson_tagsr   r   Zviewsr   r   fieldsr   r   r   ZSERIALIZATION_MODULESr?   r   ro   r   r-   r2   r5   rC   ru   r|   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s<   An!Do/|[