Пример #1
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.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
    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
 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
def url_postcode(pc):
    return urllib.parse.quote(countries.get_postcode_display(pc))