def setup(self): dummy_db = None mapper = None self.importer = DictBasedImporter(None, dummy_db, mapper, None, dry_run=False)
class TestDictBasedImporter(object): def setup(self): dummy_db = None mapper = None self.importer = DictBasedImporter(None, dummy_db, mapper, None, dry_run=False) def test_insert(self): mappings = [ (('highway', 'secondary'), [defaultmapping.mainroads]), (('railway', 'tram'), [defaultmapping.railways]), (('landusage', 'grass'), [defaultmapping.landusages]), ] assert self.importer.insert( mappings, 1234, [(0, 0), (1, 0), (1, 1), (0, 0)], { 'highway': 'secondary', 'railway': 'tram', 'oneway': '1', 'name': 'roundabout', }) # get items, sort by mapping_names so that landusages comes first queue_items = [ self.importer.db_queue.get(), self.importer.db_queue.get() ] queue_items.sort(key=lambda x: x['mapping_names']) polygon_item = queue_items[0] linestring_item = queue_items[1] eq_(linestring_item['mapping_names'], ['mainroads', 'railways']) eq_(linestring_item['osm_id'], 1234) eq_( linestring_item['fields'], { 'highway': 'secondary', 'railway': 'tram', 'oneway': 1, 'z_order': 7, 'bridge': 0, 'tunnel': 0, 'name': 'roundabout', 'ref': None }) eq_(polygon_item['mapping_names'], ['landusages']) eq_(polygon_item['osm_id'], 1234) assert_almost_equal(polygon_item['fields']['area'], 6195822904.182782) del polygon_item['fields']['area'] eq_(polygon_item['fields'], { 'z_order': 27, 'landusage': 'grass', 'name': 'roundabout', })