def test_states_import_without_existing_xref_fails(self, imp_adb): db = imp_adb.context.db utils.clear_tables(db, 'states', 'countries') imp_adb.errors = [] imp_adb.sheet_name = 'states' from conftest import wb with pytest.raises(Exception): imp_adb.import_data(wb()) db.rollback()
def test_organization_type_import(self, cache): from conftest import wb db = cache._XRefResolver__dbsession utils.clear_tables(db, 'organization_types') context = AttrDict(db=db, cache=cache) importer = OrganizationTypeImporter(context) importer.import_data(wb()) assert len(importer.errors) == 0 found = db.query(OrganizationType).count() assert found == 3
def test_countries_import(self, imp_adb): from conftest import wb db = imp_adb.context.db utils.clear_tables(db, 'states', 'countries') imp_adb.errors = [] imp_adb.sheet_name = 'countries' imp_adb.import_data(wb()) assert len(imp_adb.errors) == 0 found = db.query(Country).count() assert found == 2
def test_countries_after_states_listing_not_processed2(self, imp_adb): from conftest import wb db, _wb = (imp_adb.context.db, wb()) utils.clear_tables(db, 'states', 'countries') imp_adb.errors = [] imp_adb.sheet_name = 'countries-states-countries' imp_adb.import_data(_wb) assert len(imp_adb.errors) == 0 found = db.query(Country).count() assert found == 1 found2 = db.query(State).count() assert found2 == 3
def test_organization_type_fails_with_multi_isroot_non_multiroot(self, cache): from conftest import wb OrganizationTypeImporter.sheet_name = 'organization-types-2' db = cache._XRefResolver__dbsession utils.clear_tables(db, 'organization_types') context = AttrDict(db=db, cache=cache) importer = OrganizationTypeImporter(context) importer.import_data(wb()) assert len(importer.errors) == 1 found = db.query(OrganizationType).count() assert found == 2 # restore orig sheet name OrganizationTypeImporter.sheet_name = 'organization-types'
def test_states_import_with_existing_xref_passes(self, imp_adb): from conftest import wb db, _wb = (imp_adb.context.db, wb()) utils.clear_tables(db, 'states', 'countries') imp_adb.errors = [] imp_adb.sheet_name = 'countries' imp_adb.import_data(_wb) assert len(imp_adb.errors) == 0 imp_adb.sheet_name = 'states' imp_adb.import_data(_wb) assert len(imp_adb.errors) == 0 found = db.query(State).count() assert found == 2
def test_organisations_import(self, cache2): from enum import Enum from conftest import wb db = cache2._XRefResolver__dbsession utils.clear_tables(db, 'contact_details', 'organizations') context = AttrDict(db=db, cache=cache2) importer = OrganizationImporter(context) importer.import_data(wb()) assert len(importer.errors) == 0 found = db.query(Organization).count() assert found == 2 found2 = db.query(EmailContact).count() assert found2 == 2 found3 = db.query(PhoneContact).count() assert found3 == 1
def _clear_tables(self, db, *table_names): utils.clear_tables(db, *table_names)