<s> import json <EOL> try : <EOL> from urllib . parse import quote <EOL> except ImportError : <EOL> from urllib import quote <EOL> from django . http import HttpRequest <EOL> from testcases import TestCaseWithFixture <EOL> from . utils import skipIfSpatialite <EOL> golden_gate_park_query = quote ( """<STR_LIT>""" ) <EOL> class ViewsTestCase ( TestCaseWithFixture ) : <EOL> def test_gets ( self ) : <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> deserialized = json . loads ( resp . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( len ( deserialized ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( deserialized [ '<STR_LIT>' ] , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> deserialized = json . loads ( resp . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( len ( deserialized ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( deserialized [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:20> ) <EOL> self . assertEqual ( len ( deserialized [ '<STR_LIT>' ] ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( [ obj [ '<STR_LIT:title>' ] for obj in deserialized [ '<STR_LIT>' ] ] , [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> deserialized = json . loads ( resp . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( len ( deserialized ) , <NUM_LIT:12> ) <EOL> self . assertEqual ( deserialized [ '<STR_LIT:title>' ] , u'<STR_LIT>' ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> deserialized = json . loads ( resp . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( len ( deserialized ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( deserialized [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( [ obj [ '<STR_LIT:title>' ] for obj in deserialized [ '<STR_LIT>' ] ] , [ u'<STR_LIT>' , u'<STR_LIT>' ] ) <EOL> def test_posts ( self ) : <EOL> request = HttpRequest ( ) <EOL> post_data = '<STR_LIT>' <EOL> request . _body = request . _raw_post_data = post_data <EOL> resp = self . client . post ( '<STR_LIT>' , data = post_data , content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertTrue ( resp [ '<STR_LIT:location>' ] . endswith ( '<STR_LIT>' ) ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> obj = json . loads ( resp . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( obj [ '<STR_LIT:content>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( obj [ '<STR_LIT:user>' ] , '<STR_LIT>' ) <EOL> def test_puts ( self ) : <EOL> request = HttpRequest ( ) <EOL> post_data = '<STR_LIT>' <EOL> request . _body = request . _raw_post_data = post_data <EOL> resp = self . client . put ( '<STR_LIT>' , data = post_data , content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> obj = json . loads ( resp . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( obj [ '<STR_LIT:content>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( obj [ '<STR_LIT:user>' ] , '<STR_LIT>' ) <EOL> def test_api_field_error ( self ) : <EOL> request = HttpRequest ( ) <EOL> post_data = '<STR_LIT>' <EOL> request . _body = request . _raw_post_data = post_data <EOL> resp = self . client . post ( '<STR_LIT>' , data = post_data , content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content . decode ( '<STR_LIT:utf-8>' ) , '<STR_LIT>' ) <EOL> def test_options ( self ) : <EOL> resp = self . client . options ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> allows = '<STR_LIT>' <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , allows ) <EOL> self . assertEqual ( resp . content . decode ( '<STR_LIT:utf-8>' ) , allows ) <EOL> resp = self . client . options ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> allows = '<STR_LIT>' <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , allows ) <EOL> self . assertEqual ( resp . content . decode ( '<STR_LIT:utf-8>' ) , allows ) <EOL> resp = self . client . options ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> allows = '<STR_LIT:GET>' <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , allows ) <EOL> self . assertEqual ( resp . content . decode ( '<STR_LIT:utf-8>' ) , allows ) <EOL> resp = self . client . options ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> allows = '<STR_LIT:GET>' <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , allows ) <EOL> self . assertEqual ( resp . content . decode ( '<STR_LIT:utf-8>' ) , allows ) <EOL> class MoreViewsTestCase ( TestCaseWithFixture ) : <EOL> def test_get_apis_json ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' , HTTP_ACCEPT = '<STR_LIT:application/json>' ) <EOL> data = json . loads ( response . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( data , { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } ) <EOL> def test_get_apis_xml ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' , HTTP_ACCEPT = '<STR_LIT>' ) <EOL> data = response . content . decode ( '<STR_LIT:utf-8>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( data , '<STR_LIT>' ) <EOL> def test_get_list ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' , HTTP_ACCEPT = '<STR_LIT:application/json>' ) <EOL> data = json . loads ( response . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( data [ '<STR_LIT>' ] ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:content>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT:content>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( data [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( data [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( data [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) , <NUM_LIT:8> ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ '<STR_LIT:content>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> def test_post_object ( self ) : <EOL> post_data = '<STR_LIT>' <EOL> response = self . client . post ( '<STR_LIT>' , data = post_data , HTTP_ACCEPT = '<STR_LIT:application/json>' , content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> location = response [ '<STR_LIT>' ] <EOL> self . assertTrue ( location . endswith ( '<STR_LIT>' ) ) <EOL> response = self . client . get ( '<STR_LIT>' , HTTP_ACCEPT = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> data = response . content . decode ( '<STR_LIT:utf-8>' ) <EOL> obj = json . loads ( data ) <EOL> self . assertEqual ( obj [ '<STR_LIT:content>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( obj [ '<STR_LIT:user>' ] , '<STR_LIT>' ) <EOL> def test_post_geojson ( self ) : <EOL> post_data = """<STR_LIT>""" <EOL> response = self . client . post ( '<STR_LIT>' , data = post_data , HTTP_ACCEPT = '<STR_LIT:application/json>' , content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> location = response [ '<STR_LIT>' ] <EOL> self . assertTrue ( location . endswith ( '<STR_LIT>' ) ) <EOL> response = self . client . get ( '<STR_LIT>' , HTTP_ACCEPT = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> data = response . content . decode ( '<STR_LIT:utf-8>' ) <EOL> obj = json . loads ( data ) <EOL> self . assertEqual ( obj [ '<STR_LIT:content>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( obj [ '<STR_LIT:user>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , { u'<STR_LIT:type>' : u'<STR_LIT>' , u'<STR_LIT>' : [ [ [ [ - <NUM_LIT> , <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT> ] ] ] ] } ) <EOL> def test_post_xml ( self ) : <EOL> post_data = """<STR_LIT>""" <EOL> response = self . client . post ( '<STR_LIT>' , data = post_data , HTTP_ACCEPT = '<STR_LIT>' , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> location = response [ '<STR_LIT>' ] <EOL> self . assertTrue ( location . endswith ( '<STR_LIT>' ) ) <EOL> response = self . client . get ( '<STR_LIT>' , HTTP_ACCEPT = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> data = response . content . decode ( '<STR_LIT:utf-8>' ) <EOL> obj = json . loads ( data ) <EOL> self . assertEqual ( obj [ '<STR_LIT:content>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( obj [ '<STR_LIT:user>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , { "<STR_LIT>" : [ [ - <NUM_LIT> , <NUM_LIT> ] , [ - <NUM_LIT> , <NUM_LIT> ] ] , "<STR_LIT:type>" : "<STR_LIT>" } ) <EOL> response = self . client . get ( '<STR_LIT>' , HTTP_ACCEPT = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> data = response . content . decode ( '<STR_LIT:utf-8>' ) <EOL> self . assertIn ( '<STR_LIT>' , data ) <EOL> def test_filter_within_on_points ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' % golden_gate_park_query , HTTP_ACCEPT = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> data = json . loads ( response . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:content>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> @ skipIfSpatialite <EOL> def test_filter_within_on_lines ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' % golden_gate_park_query , HTTP_ACCEPT = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> data = json . loads ( response . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:content>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , - <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> self . assertAlmostEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <NUM_LIT> , places = <NUM_LIT:5> ) <EOL> @ skipIfSpatialite <EOL> def test_filter_contains ( self ) : <EOL> points_inside_golden_gate_park = """<STR_LIT>""" <EOL> response = self . client . get ( '<STR_LIT>' % quote ( points_inside_golden_gate_park ) , HTTP_ACCEPT = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> data = json . loads ( response . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:content>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) , <NUM_LIT:8> ) </s>
