def test_areas_by_type(self):
        url = '/areas/SML'
        content = get_content(self.client.get(url))
        self.assertIn(str(self.small_area_1.id), content)
        self.assertIn(str(self.small_area_2.id), content)

        url = '/areas/SML.geojson'
        content = get_content(self.client.get(url))
        self.assertEqual(len(content), 2)
Exemple #2
0
    def test_areas_by_type(self):
        url = '/areas/SML'
        content = get_content(self.client.get(url))
        self.assertIn(str(self.small_area_1.id), content)
        self.assertIn(str(self.small_area_2.id), content)

        url = '/areas/SML.geojson'
        content = get_content(self.client.get(url))
        self.assertEqual(len(content), 2)
Exemple #3
0
    def test_areas_children(self):
        id = self.small_area_1.id
        url = '/area/%d/children' % id
        content = get_content(self.client.get(url))
        self.assertEqual(len(content), 0)

        id = self.small_area_2.id
        url = '/area/%d/children.geojson' % id
        content = get_content(self.client.get(url))
        self.assertIn('error', content)
    def test_areas_children(self):
        id = self.small_area_1.id
        url = '/area/%d/children' % id
        content = get_content(self.client.get(url))
        self.assertEqual(len(content), 0)

        id = self.small_area_2.id
        url = '/area/%d/children.geojson' % id
        content = get_content(self.client.get(url))
        self.assertIn('error', content)
Exemple #5
0
    def test_areas_polygon_geometry(self):
        id = self.small_area_1.id

        url_area = '/area/%d/geometry' % id
        response_area = self.client.get(url_area)
        self.assertEqual(response_area.status_code, 200)
        content_area = get_content(response_area)
        self.assertEqual(round(content_area['centre_lat'], 6), 51.5)
        self.assertEqual(round(content_area['centre_lon'], 6), -3.5)

        url_areas = '/areas/%d/geometry' % id
        response_areas = self.client.get(url_areas)
        self.assertEqual(response_areas.status_code, 200)
        content_areas = get_content(response_areas)
        self.assertEqual(content_area, content_areas[str(id)])
Exemple #6
0
    def test_areas_polygon_geometry(self):
        id = self.small_area_1.id

        url_area = '/area/%d/geometry' % id
        response_area = self.client.get(url_area)
        self.assertEqual(response_area.status_code, 200)
        content_area = get_content(response_area)
        self.assertEqual(content_area['centre_lat'], 51.5)
        self.assertEqual(content_area['centre_lon'], -3.5)

        url_areas = '/areas/%d/geometry' % id
        response_areas = self.client.get(url_areas)
        self.assertEqual(response_areas.status_code, 200)
        content_areas = get_content(response_areas)
        self.assertEqual(content_area, content_areas[str(id)])
Exemple #7
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': {},
                }
            }
        })
Exemple #8
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': {},
                    }
                }
            })
Exemple #9
0
    def test_areas_by_point(self):
        url = '/point/4326/-3.4,51.5.json'
        response = self.client.get(url)

        content = get_content(response)

        self.assertEqual(
            set((int(x) for x in content.keys())),
            set((x.id for x in (self.big_area, self.small_area_1))))
Exemple #10
0
    def test_areas_by_point(self):
        url = '/point/4326/-3.4,51.5.json'
        response = self.client.get(url, HTTP_ACCEPT_ENCODING='gzip')

        content = get_content(response)

        self.assertEqual(
            set((int(x) for x in content.keys())),
            set((x.id for x in (self.big_area, self.small_area_1)))
            )
Exemple #11
0
 def test_nearest(self):
     url = '/nearest/4326/4,52.json'
     response = self.client.get(url)
     content = get_content(response)
     self.assertEqual(content, {'postcode': {
         'coordsyst': 'G',
         'distance': 519051.0,
         'easting': 295977,
         'northing': 178963,
         'postcode': 'PO14 1NT',
         'wgs84_lat': 51.5, 'wgs84_lon': -3.5
     }})
Exemple #12
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])
     })
Exemple #13
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)
     })
 def test_nearest(self):
     url = '/nearest/4326/4,52.json'
     response = self.client.get(url)
     content = get_content(response)
     self.assertEqual(
         content, {
             'postcode': {
                 'coordsyst': 'G',
                 'distance': 519051.0,
                 'easting': 295977,
                 'northing': 178963,
                 'postcode': 'PO14 1NT',
                 'wgs84_lat': 51.5,
                 'wgs84_lon': -3.5
             }
         })
Exemple #15
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])
         }
     })
Exemple #16
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)
         }
     })
Exemple #17
0
 def test_example_postcode(self):
     id = self.small_area_1.id
     url = '/area/%d/example_postcode' % id
     response = self.client.get(url)
     content = get_content(response)
     self.assertEqual(content, self.postcode.postcode)
Exemple #18
0
 def test_example_postcode(self):
     id = self.small_area_1.id
     url = '/area/%d/example_postcode' % id
     response = self.client.get(url)
     content = get_content(response)
     self.assertEqual(content, self.postcode.postcode)