class SpatialTest(TestCase): ''' Tests the spatial representations of Stands and ForestProperties ''' def setUp(self): self.client = Client() import_rasters() self.user = User.objects.create_user( 'featuretest', '*****@*****.**', password='******') self.stand1 = Stand(user=self.user, name="My Stand", geometry_orig=g1) self.stand1.save() self.stand2 = Stand(user=self.user, name="My Stand2", geometry_orig=g1) self.stand2.save() self.prop1 = ForestProperty(user=self.user, name="My Property", geometry_final=p1) self.prop1.save() self.prop1.add(self.stand1) def test_rest_defaultkml_url(self): self.client.login(username='******', password='******') link = self.stand1.options.get_link('KML') url = link.reverse(self.stand1) response = self.client.get(url) errors = kml_errors(response.content) self.assertFalse(errors,"invalid KML %s" % str(errors)) def test_stand_json(self): thejson = self.stand1.geojson() d = loads(thejson) self.assertEquals(d['properties']['name'], 'My Stand') def test_property_json(self): thejson = self.prop1.feature_set_geojson() d = loads(thejson) self.assertEquals(len(d['features']), 1) self.assertEquals(d['features'][0]['properties']['name'], 'My Stand') self.prop1.add(self.stand2) thejson = self.prop1.feature_set_geojson() d = loads(thejson) self.assertEquals(len(d['features']), 2) def test_property_bbox(self): thejson = self.prop1.feature_set_geojson() d = loads(thejson) for x, y in zip(d['bbox'], self.prop1.bbox): self.assertAlmostEquals(x, y, places=5) def test_stand_json_url(self): self.client.login(username='******', password='******') link = self.stand1.options.get_link('GeoJSON') url = link.reverse(self.stand1) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertTrue('application/json' in response['Content-Type']) d = loads(response.content) self.assertEquals(d['features'][0]['properties']['name'], 'My Stand') def test_property_json_url(self): self.client.login(username='******', password='******') link = self.stand1.options.get_link('GeoJSON') url = link.reverse(self.prop1) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertTrue('application/json' in response['Content-Type']) d = loads(response.content) self.assertEquals(d['features'][0]['properties']['name'], 'My Property') def test_multistand_json_url(self): self.client.login(username='******', password='******') uids = [self.stand1.uid, self.stand2.uid] link = Stand.get_options().get_link('GeoJSON') url = link.reverse([self.stand1, self.stand2]) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertTrue('application/json' in response['Content-Type']) d = loads(response.content) self.assertEquals(len(d['features']), 2) foundit = False for f in d['features']: if f['properties']['name'] == 'My Stand2': foundit = True self.assertTrue(foundit) def test_property_stands_json_url(self): self.prop1.add(self.stand2) self.client.login(username='******', password='******') link = self.prop1.options.get_link('Property Stands GeoJSON') url = link.reverse(self.prop1) response = self.client.get(url) self.assertEqual(response.status_code, 200, response) self.assertTrue('application/json' in response['Content-Type']) d = loads(response.content) self.assertEquals(len(d['features']), 2) foundit = False for f in d['features']: if f['properties']['name'] == 'My Stand2': foundit = True self.assertTrue(foundit)
class SpatialTest(TestCase): """ Tests the spatial representations of Stands and ForestProperties """ def setUp(self): self.client = Client() import_rasters() self.user = User.objects.create_user("featuretest", "*****@*****.**", password="******") self.stand1 = Stand(user=self.user, name="My Stand", geometry_orig=g1) self.stand1.save() self.stand2 = Stand(user=self.user, name="My Stand2", geometry_orig=g1) self.stand2.save() self.prop1 = ForestProperty(user=self.user, name="My Property", geometry_final=p1) self.prop1.save() self.prop1.add(self.stand1) def test_rest_defaultkml_url(self): self.client.login(username="******", password="******") link = self.stand1.options.get_link("KML") url = link.reverse(self.stand1) response = self.client.get(url) errors = kml_errors(response.content) self.assertFalse(errors, "invalid KML %s" % str(errors)) def test_stand_json(self): thejson = self.stand1.geojson() d = loads(thejson) self.assertEquals(d["properties"]["name"], "My Stand") def test_property_json(self): thejson = self.prop1.feature_set_geojson() d = loads(thejson) self.assertEquals(len(d["features"]), 1) self.assertEquals(d["features"][0]["properties"]["name"], "My Stand") self.prop1.add(self.stand2) thejson = self.prop1.feature_set_geojson() d = loads(thejson) self.assertEquals(len(d["features"]), 2) def test_property_bbox(self): thejson = self.prop1.feature_set_geojson() d = loads(thejson) for x, y in zip(d["bbox"], self.prop1.bbox): self.assertAlmostEquals(x, y, places=5) def test_stand_json_url(self): self.client.login(username="******", password="******") link = self.stand1.options.get_link("GeoJSON") url = link.reverse(self.stand1) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertTrue("application/json" in response["Content-Type"]) d = loads(response.content) self.assertEquals(d["features"][0]["properties"]["name"], "My Stand") def test_property_json_url(self): self.client.login(username="******", password="******") link = self.stand1.options.get_link("GeoJSON") url = link.reverse(self.prop1) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertTrue("application/json" in response["Content-Type"]) d = loads(response.content) self.assertEquals(d["features"][0]["properties"]["name"], "My Property") def test_multistand_json_url(self): self.client.login(username="******", password="******") uids = [self.stand1.uid, self.stand2.uid] link = Stand.get_options().get_link("GeoJSON") url = link.reverse([self.stand1, self.stand2]) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertTrue("application/json" in response["Content-Type"]) d = loads(response.content) self.assertEquals(len(d["features"]), 2) foundit = False for f in d["features"]: if f["properties"]["name"] == "My Stand2": foundit = True self.assertTrue(foundit) def test_property_stands_json_url(self): self.prop1.add(self.stand2) self.client.login(username="******", password="******") link = self.prop1.options.get_link("Property Stands GeoJSON") url = link.reverse(self.prop1) response = self.client.get(url) self.assertEqual(response.status_code, 200, response) self.assertTrue("application/json" in response["Content-Type"]) d = loads(response.content) self.assertEquals(len(d["features"]), 2) foundit = False for f in d["features"]: if f["properties"]["name"] == "My Stand2": foundit = True self.assertTrue(foundit)