示例#1
0
文件: tests.py 项目: Code4SA/mapit
 def test_partial_json(self):
     url = '/postcode/partial/SW1A'
     response = self.client.get(url)
     content = get_content(response)
     countries.get_postcode_display(self.postcode.postcode)
     in_gb_coords = self.postcode.location.transform(27700, clone=True)
     self.assertDictEqual(content, {
         'wgs84_lat': self.postcode.location.y,
         'wgs84_lon': self.postcode.location.x,
         'coordsyst': 'G',
         'postcode': 'SW1A',
         'easting': round(in_gb_coords.x),
         'northing': round(in_gb_coords.y)
     })
示例#2
0
 def test_partial_json(self):
     url = '/postcode/partial/SW1A'
     response = self.client.get(url)
     content = get_content(response)
     countries.get_postcode_display(self.postcode.postcode)
     in_gb_coords = self.postcode.as_uk_grid()
     self.assertDictEqual(content, {
         'wgs84_lat': self.postcode.location.y,
         'wgs84_lon': self.postcode.location.x,
         'coordsyst': 'G',
         'postcode': 'SW1A',
         'easting': round(in_gb_coords[0]),
         'northing': round(in_gb_coords[1])
     })
示例#3
0
    def test_postcode_json(self):
        pc = self.postcode.postcode
        url = '/postcode/%s' % urllib.parse.quote(pc)
        response = self.client.get(url)
        content = get_content(response)

        in_gb_coords = self.postcode.location.transform(27700, clone=True)
        pc = countries.get_postcode_display(self.postcode.postcode)
        self.assertDictEqual(
            content, {
                'postcode': pc,
                'wgs84_lat': self.postcode.location.y,
                'wgs84_lon': self.postcode.location.x,
                'coordsyst': 'G',
                'easting': round(in_gb_coords.x),
                'northing': round(in_gb_coords.y),
                'areas': {
                    str(self.area.id): {
                        'id': self.area.id,
                        'name': self.area.name,
                        'parent_area': None,
                        'type': self.type.code,
                        'type_name': self.type.description,
                        'generation_low': self.generation.id,
                        'generation_high': self.generation.id,
                        'country': '',
                        'country_name': '-',
                        'codes': {
                            'CodeType': 'CODE',
                        },
                        'all_names': {},
                    }
                }
            })
示例#4
0
文件: tests.py 项目: Code4SA/mapit
    def test_postcode_json(self):
        pc = self.postcode.postcode
        url = '/postcode/%s' % urllib.parse.quote(pc)
        response = self.client.get(url)
        content = get_content(response)

        in_gb_coords = self.postcode.location.transform(27700, clone=True)
        pc = countries.get_postcode_display(self.postcode.postcode)
        self.assertDictEqual(content, {
            'postcode': pc,
            'wgs84_lat': self.postcode.location.y,
            'wgs84_lon': self.postcode.location.x,
            'coordsyst': 'G',
            'easting': round(in_gb_coords.x),
            'northing': round(in_gb_coords.y),
            'areas': {
                str(self.area.id): {
                    'id': self.area.id,
                    'name': self.area.name,
                    'parent_area': None,
                    'type': self.type.code,
                    'type_name': self.type.description,
                    'generation_low': self.generation.id,
                    'generation_high': self.generation.id,
                    'country': '',
                    'country_name': '-',
                    'codes': {
                        'CodeType': 'CODE',
                    },
                    'all_names': {},
                }
            }
        })
示例#5
0
 def test_partial_json(self):
     url = '/postcode/partial/SW1A'
     response = self.client.get(url)
     content = json.loads(response.content)
     pc = countries.get_postcode_display(self.postcode.postcode)
     in_gb_coords = self.postcode.location.transform(27700, clone=True)
     self.assertDictEqual(content, {
         'wgs84_lat': self.postcode.location.y,
         'wgs84_lon': self.postcode.location.x,
         'coordsyst': 'G',
         'postcode': 'SW1A',
         'easting': round(in_gb_coords.x),
         'northing': round(in_gb_coords.y)
     })
示例#6
0
 def test_nearest_json(self):
     url = '/nearest/4326/%f,%f' % self.postcode.location.coords
     response = self.client.get(url)
     content = get_content(response)
     pc = countries.get_postcode_display(self.postcode.postcode)
     in_gb_coords = self.postcode.as_uk_grid()
     self.assertDictEqual(content, {
         'postcode': {
             'distance': 0,
             'wgs84_lat': self.postcode.location.y,
             'wgs84_lon': self.postcode.location.x,
             'coordsyst': 'G',
             'postcode': pc,
             'easting': round(in_gb_coords[0]),
             'northing': round(in_gb_coords[1])
         }
     })
示例#7
0
文件: tests.py 项目: Code4SA/mapit
 def test_nearest_json(self):
     url = '/nearest/4326/%f,%f' % self.postcode.location.coords
     response = self.client.get(url)
     content = get_content(response)
     pc = countries.get_postcode_display(self.postcode.postcode)
     in_gb_coords = self.postcode.location.transform(27700, clone=True)
     self.assertDictEqual(content, {
         'postcode': {
             'distance': 0,
             'wgs84_lat': self.postcode.location.y,
             'wgs84_lon': self.postcode.location.x,
             'coordsyst': 'G',
             'postcode': pc,
             'easting': round(in_gb_coords.x),
             'northing': round(in_gb_coords.y)
         }
     })
示例#8
0
 def test_nearest_json(self):
     url = '/nearest/4326/%f,%f' % self.postcode.location.coords
     response = self.client.get(url)
     content = json.loads(response.content)
     pc = countries.get_postcode_display(self.postcode.postcode)
     in_gb_coords = self.postcode.location.transform(27700, clone=True)
     self.assertDictEqual(content, {
         'postcode': {
             'distance': 0,
             'wgs84_lat': self.postcode.location.y,
             'wgs84_lon': self.postcode.location.x,
             'coordsyst': 'G',
             'postcode': pc,
             'easting': round(in_gb_coords.x),
             'northing': round(in_gb_coords.y)
         }
     })
示例#9
0
def url_postcode(pc):
    return urllib.parse.quote(countries.get_postcode_display(pc))
示例#10
0
文件: tests.py 项目: Code4SA/mapit
def url_postcode(pc):
    return urllib.parse.quote(countries.get_postcode_display(pc))