print 'ERROR: -x /path/to/request.xml is a required argument' sys.exit(10) elif COMMAND == 'validate_xml': if XML is None: print 'ERROR: -x /path/to/file.xml is a required argument' sys.exit(11) if XSD is None: print 'ERROR: -s /path/to/file.xsd is a required argument' sys.exit(12) if COMMAND == 'setup_db': admin.setup_db(DATABASE, TABLE, HOME) elif COMMAND == 'load_records': admin.load_records(CONTEXT, DATABASE, TABLE, XML_DIRPATH, RECURSIVE) elif COMMAND == 'export_records': admin.export_records(CONTEXT, DATABASE, TABLE, XML_DIRPATH) elif COMMAND == 'rebuild_db_indexes': admin.rebuild_db_indexes(DATABASE, TABLE) elif COMMAND == 'optimize_db': admin.optimize_db(CONTEXT, DATABASE, TABLE) elif COMMAND == 'refresh_harvested_records': admin.refresh_harvested_records(CONTEXT, DATABASE, TABLE, URL) elif COMMAND == 'gen_sitemap': admin.gen_sitemap(CONTEXT, DATABASE, TABLE, URL, OUTPUT_FILE) elif COMMAND == 'gen_opensearch_description': admin.gen_opensearch_description(CONTEXT, METADATA, URL, OUTPUT_FILE) elif COMMAND == 'post_xml': print admin.post_xml(CSW_URL, XML, TIMEOUT) elif COMMAND == 'get_sysprof': print admin.get_sysprof() elif COMMAND == 'validate_xml':
sys.exit(11) if XSD is None: print 'ERROR: -s /path/to/file.xsd is a required argument' sys.exit(12) if COMMAND == 'setup_db': try: admin.setup_db(DATABASE, TABLE, HOME) except Exception as err: print err print 'ERROR: DB creation error. Database tables already exist' print 'Delete tables or database to reinitialize' elif COMMAND == 'load_records': admin.load_records(CONTEXT, DATABASE, TABLE, XML_DIRPATH, RECURSIVE, FORCE_CONFIRM) elif COMMAND == 'export_records': admin.export_records(CONTEXT, DATABASE, TABLE, XML_DIRPATH) elif COMMAND == 'rebuild_db_indexes': admin.rebuild_db_indexes(DATABASE, TABLE) elif COMMAND == 'optimize_db': admin.optimize_db(CONTEXT, DATABASE, TABLE) elif COMMAND == 'refresh_harvested_records': admin.refresh_harvested_records(CONTEXT, DATABASE, TABLE, URL) elif COMMAND == 'gen_sitemap': admin.gen_sitemap(CONTEXT, DATABASE, TABLE, URL, OUTPUT_FILE) elif COMMAND == 'post_xml': print admin.post_xml(CSW_URL, XML, TIMEOUT) elif COMMAND == 'get_sysprof': print admin.get_sysprof() elif COMMAND == 'validate_xml': admin.validate_xml(XML, XSD) elif COMMAND == 'delete_records':
def test(options): """Run unit tests""" db_setup = False db_conn = None cfg_files = [] status = 0 url = options.get('url', None) suites = options.get('suites', None) database = options.get('database', 'SQLite3') remote = options.get('remote') timems = options.get('time', None) pedantic = options.get('pedantic', False) if url is None: # run against default server call_task('stop') call_task('reset') if database == 'SQLite3': call_task('setup_testdata') call_task('start') url = 'http://*****:*****@localhost/%s' % ( user, password, temp_db) if password: sh('set PGPASSWORD=%s' % password) sh('createdb %s -U %s' % (temp_db, user)) sh('createlang --dbname=%s plpythonu -U %s' % (temp_db, user)) # update all default.cfg files to point to test DB cfg_files = glob.glob('tests%ssuites%s*%s*.cfg' % (3*(os.sep,))) for cfg in cfg_files: # generate table suite = cfg.split(os.sep)[2] tablename = 'records_cite' if suite == 'manager': tablename = 'records_manager' elif suite == 'apiso': tablename = 'records_apiso' config = configparser.SafeConfigParser() with open(cfg) as read_data: config.readfp(read_data) config.set('repository', 'database', db_conn) config.set('repository', 'table', tablename) with open(cfg, 'wb') as config2: config.write(config2) if suite in ['cite', 'manager', 'apiso']: # setup tables setup_db(db_conn, tablename, home, init_sfsql, init_sfsql) init_sfsql = False if suite in ['cite', 'apiso']: # load test data dirname = '%s%sdata' % (os.path.dirname(cfg), os.sep) load_records(context, db_conn, tablename, dirname) if suite in ['cite', 'apiso']: # export test data exportpath = 'tests/results/exports' export_records(context, db_conn, tablename, exportpath) else: raise Exception('Invalid database specified') with pushd('tests'): try: sh(cmd) except BuildFailure as err: status = 1 # stop pycsw instance call_task('stop') if db_setup: # tearDown for cfg in cfg_files: sh('git checkout %s' % cfg) if database == 'PostgreSQL': sh("psql -c \"select pg_terminate_backend(procpid) from pg_stat_activity where datname='%s';\" -U %s" % (temp_db, user)) sh('dropdb %s -U %s' % (temp_db, user)) sh('unset PGPASSWORD') sys.exit(status)