import sqlalchemy

from osmaxx.converters.gis_converter.bootstrap.bootstrap import BootStrapper
from tests.inside_worker_test.conftest import slow, cleanup_osmaxx_schemas
from tests.inside_worker_test.declarative_schema import osm_models


@slow
def test_osmaxx_data_model_processing_puts_amenity_grave_yard_with_religion_into_table_pow_a(
        osmaxx_functions, clean_osm_tables, monkeypatch):
    assert osmaxx_functions == clean_osm_tables  # same db-connection
    engine = osmaxx_functions
    engine.execute(
        osm_models.t_osm_polygon.insert().values(
            amenity='grave_yard',
            religion='any value will do, as long as one is present',
        ).execution_options(autocommit=True)
    )
    monkeypatch.setattr(
        'osmaxx.converters.gis_converter.helper.postgres_wrapper.create_engine', lambda *_, **__: engine)
    bootstrapper = BootStrapper(pbf_file_path=None)
    try:
        bootstrapper._harmonize_database()
        bootstrapper._filter_data()
        t_pow_a = sqlalchemy.sql.schema.Table('pow_a', osm_models.metadata, schema='osmaxx')
        result = engine.execute(sqlalchemy.select([t_pow_a]))
        assert result.rowcount == 1
    finally:
        try:
            del result  # The (unfetched) result would block the dropping of SCHEMA "osmaxx" in the following cleanup.
        except NameError:
            pass
        cleanup_osmaxx_schemas(engine)

@@ -491,16 +491,48 @@
 nctions%0A
+%0A    def create_osm_data():%0A    
     engi
@@ -543,16 +543,20 @@
 xecute(%0A
+    
         
@@ -609,16 +609,20 @@
         
+    
 amenity=
@@ -635,16 +635,20 @@
 _yard',%0A
+    
         
@@ -716,16 +716,20 @@
         
+    
 ).execut
@@ -757,16 +757,20 @@
 t=True)%0A
+    
     )%0A  
@@ -906,107 +906,401 @@
     
-bootstrapper = BootStrapper(pbf_file_path=
+monkeypatch.setattr(BootStrapper, '_reset_database', lambda _self: None)  # Already taken care of by fixtures.%0A    monkeypatch.setattr(BootStrapper, '_convert_osm_pbf_to_postgres', lambda _self: create_osm_data())%0A    monkeypatch.setattr(BootStrapper, '_setup_db_functions', lambda _self: 
 None)
-%0A
   
-  try:%0A        bootstrapper._harmonize_database()
+# Already taken care of by fixtures.%0A    bootstrapper = BootStrapper(pbf_file_path=None)%0A    try:
 %0A   
@@ -1321,20 +1321,17 @@
 per.
-_filter_data
+bootstrap
 ()%0A 

call whole bootstrap in test after stubbing out some of its steps