def test_created_updated(self): # I always forget the Site is automagically created! site = Site.objects.get_current() TaarifaConfig.objects.create(site=site,bounds='POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 50.0000000000000000, 50.0000000000000000 50.0000000000000000, 50.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000))', sync_with_osm=True) diff_osm(self.path, self.osm_new) cat_num = FacilityCategory.objects.count() self.assertEqual(cat_num, 1, "Wrong number of categories: %d" % cat_num) fac_num = Facility.objects.count() self.assertEqual(fac_num, 1, "Wrong number of facilities: %d" % fac_num) facility = Facility.objects.get(pk=1) self.assertEqual(facility.name, "Nguruka", "Name wrong: %s" % facility.name) diff_osm(self.path, self.osm_update) facility = Facility.objects.get(pk=1) self.assertEqual(facility.name, "Moo", "Name wrong: %s" % facility.name)
def test_created_updated(self): # I always forget the Site is automagically created! site = Site.objects.get_current() TaarifaConfig.objects.create( site=site, bounds= 'POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 50.0000000000000000, 50.0000000000000000 50.0000000000000000, 50.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000))', sync_with_osm=True) diff_osm(self.path, self.osm_new) cat_num = FacilityCategory.objects.count() self.assertEqual(cat_num, 1, "Wrong number of categories: %d" % cat_num) fac_num = Facility.objects.count() self.assertEqual(fac_num, 1, "Wrong number of facilities: %d" % fac_num) facility = Facility.objects.get(pk=1) self.assertEqual(facility.name, "Nguruka", "Name wrong: %s" % facility.name) diff_osm(self.path, self.osm_update) facility = Facility.objects.get(pk=1) self.assertEqual(facility.name, "Moo", "Name wrong: %s" % facility.name)
def sync_osm(filename="mapdata.osm"): # Get the current bounds of the site bounds = ",".join(map(str,TaarifaConfig.objects.get_current().get_extent())) url = "http://www.overpass-api.de/api/xapi?node[bbox=%s]" % bounds # Get the osm file from OSM API - into temp string buffer buf = cStringIO.StringIO() c = pycurl.Curl() c.setopt(c.URL, url) c.setopt(c.WRITEFUNCTION, buf.write) c.perform() # Format whilst still ensuring it's valid XML osm_new = buf.getvalue().replace("\n ", "").replace("\n </node>", "</node>") # See if the on-file OSM file exists - if not, straight create return diff_osm(os.path.join(settings.SITE_ROOT, filename), osm_new)
def sync_osm(filename="mapdata.osm"): # Get the current bounds of the site bounds = ",".join( map(str, TaarifaConfig.objects.get_current().get_extent())) url = "http://www.overpass-api.de/api/xapi?node[bbox=%s]" % bounds # Get the osm file from OSM API - into temp string buffer buf = cStringIO.StringIO() c = pycurl.Curl() c.setopt(c.URL, url) c.setopt(c.WRITEFUNCTION, buf.write) c.perform() # Format whilst still ensuring it's valid XML osm_new = buf.getvalue().replace("\n ", "").replace("\n </node>", "</node>") # See if the on-file OSM file exists - if not, straight create return diff_osm(os.path.join(settings.SITE_ROOT, filename), osm_new)