def test_fake_2(self): boundary = fake_boundary(self.location, 2) self.assertEqual("Placeholder", boundary.name) self.assertEqual("Future Data Placeholder", boundary.display_name) self.assertEqual("Future Data Placeholder", boundary.kind) self.assertFalse(boundary.external_id) self.assertFalse(boundary.id) self.assertEqual("fake_2_-96.00_36.14", boundary.slug) expected_shape = ((((-96.0, 36.14), (-96.0, 36.15), (-95.99, 36.15), (-95.99, 36.14), (-96.0, 36.14)),),) self.assertEqual(expected_shape, boundary.shape.coords) self.assertEqual((-95.995, 36.145), boundary.centroid.coords)
def get_boundary(self, location, boundary_set_slug): '''Get the boundary by location and boundary set slug''' # If location changed, clear the cache if self.location: if location != self.location: self.boundaries = {} self.location = location else: self.location = location # If needed, load the boundaries if not self.boundaries: wkt = 'POINT({} {})'.format(*location) boundaries = Boundary.objects.filter( shape__contains=wkt).select_related('set') for boundary in boundaries: self.boundaries[boundary.set.slug] = boundary self.boundaries['fake_2'] = fake_boundary(location, 2) # Return the boundary return self.boundaries.get(boundary_set_slug)