88from unittest import skipIf
99
1010import django
11- from django .contrib .gis .geos import GEOSGeometry , Point
12- from django .test import TestCase
13-
14- try :
15- from django .urls import reverse
16- except ImportError :
17- from django .core .urlresolvers import reverse
18-
1911import rest_framework
12+ from django .contrib .gis .geos import GEOSGeometry , Point
2013from django .core .exceptions import ImproperlyConfigured
14+ from django .test import TestCase
15+ from django .urls import reverse
2116
2217from rest_framework_gis import serializers as gis_serializers
2318from rest_framework_gis .fields import GeoJsonDict
@@ -40,16 +35,10 @@ def setUp(self):
4035 'Unable to convert to python object:'
4136 ' Invalid geometry pointer returned from "OGR_G_CreateGeometryFromJson".'
4237 )
43- if django .VERSION >= (2 , 0 , 0 ):
44- self .value_error_message = (
45- "Unable to convert to python object:"
46- " String input unrecognized as WKT EWKT, and HEXEWKB."
47- )
48- else :
49- self .value_error_message = (
50- "Unable to convert to python object:"
51- " String or unicode input unrecognized as WKT EWKT, and HEXEWKB."
52- )
38+ self .value_error_message = (
39+ "Unable to convert to python object:"
40+ " String input unrecognized as WKT EWKT, and HEXEWKB."
41+ )
5342 self .type_error_message = (
5443 "Unable to convert to python object: Improper geometry input type:"
5544 )
@@ -144,7 +133,7 @@ def test_post_HTML_browsable_api(self):
144133 ),
145134 }
146135 response = self .client .post (
147- self .location_list_url , data , HTTP_ACCEPT = 'text/html'
136+ self .location_list_url , data , headers = { "accept" : 'text/html' }
148137 )
149138 self .assertEqual (response .status_code , 201 )
150139 self .assertEqual (Location .objects .count (), 1 )
@@ -300,7 +289,7 @@ def test_geojson_format(self):
300289 self .assertCountEqual (json .dumps (response .data ), json .dumps (expected ))
301290 else :
302291 self .assertItemsEqual (json .dumps (response .data ), json .dumps (expected ))
303- response = self .client .get (url , HTTP_ACCEPT = 'text/html' )
292+ response = self .client .get (url , headers = { "accept" : 'text/html' } )
304293 self .assertContains (response , "Kool geojson test" )
305294
306295 def test_geojson_id_attribute (self ):
@@ -402,7 +391,7 @@ def test_post_geojson_location_list_HTML(self):
402391 self .geojson_location_list_url ,
403392 data = json .dumps (data ),
404393 content_type = 'application/json' ,
405- HTTP_ACCEPT = 'text/html' ,
394+ headers = { "accept" : 'text/html' } ,
406395 )
407396 self .assertEqual (response .status_code , 201 )
408397 self .assertEqual (Location .objects .count (), 1 )
@@ -506,12 +495,12 @@ def test_geofeatured_model_post_as_multipartformdata(self):
506495
507496 def test_HTML_browsable_geojson_location_list (self ):
508497 response = self .client .get (
509- self .geojson_location_list_url , HTTP_ACCEPT = 'text/html'
498+ self .geojson_location_list_url , headers = { "accept" : 'text/html' }
510499 )
511500 self .assertEqual (response .status_code , 200 )
512501 self ._create_locations ()
513502 response = self .client .get (
514- self .geojson_location_list_url , HTTP_ACCEPT = 'text/html'
503+ self .geojson_location_list_url , headers = { "accept" : 'text/html' }
515504 )
516505 self .assertContains (response , 'l1' )
517506 self .assertContains (response , 'l2' )
@@ -523,7 +512,7 @@ def test_post_geojson_location_list_HTML_web_form(self):
523512 "geometry" : json .dumps ({"type" : "Point" , "coordinates" : [10.1 , 10.1 ]}),
524513 }
525514 response = self .client .post (
526- self .geojson_location_list_url , data , HTTP_ACCEPT = 'text/html'
515+ self .geojson_location_list_url , data , headers = { "accept" : 'text/html' }
527516 )
528517 self .assertEqual (response .status_code , 201 )
529518 self .assertEqual (Location .objects .count (), 1 )
@@ -535,7 +524,7 @@ def test_post_geojson_location_list_HTML_web_form_WKT(self):
535524 self .assertEqual (Location .objects .count (), 0 )
536525 data = {"name" : "HTML test WKT" , "geometry" : "POINT (10.1 10.1)" }
537526 response = self .client .post (
538- self .geojson_location_list_url , data , HTTP_ACCEPT = 'text/html'
527+ self .geojson_location_list_url , data , headers = { "accept" : 'text/html' }
539528 )
540529 self .assertEqual (response .status_code , 201 )
541530 self .assertEqual (Location .objects .count (), 1 )
@@ -546,7 +535,7 @@ def test_post_geojson_location_list_HTML_web_form_WKT(self):
546535 def test_geojson_HTML_widget_value (self ):
547536 self ._create_locations ()
548537 response = self .client .get (
549- self .geojson_location_list_url , HTTP_ACCEPT = 'text/html'
538+ self .geojson_location_list_url , headers = { "accept" : 'text/html' }
550539 )
551540 self .assertContains (response , '<textarea name="geometry"' )
552541 self .assertContains (response , '"type": "Point"' )
@@ -556,7 +545,7 @@ def test_geojson_HTML_widget_value(self):
556545 def test_geojson_HTML_widget_value_pre_drf_39 (self ):
557546 self ._create_locations ()
558547 response = self .client .get (
559- self .geojson_location_list_url , HTTP_ACCEPT = 'text/html'
548+ self .geojson_location_list_url , headers = { "accept" : 'text/html' }
560549 )
561550 self .assertContains (response , '<textarea name="geometry"' )
562551 self .assertContains (response , '"type": "Point"' )
0 commit comments