def initialize_test_environment(): global test_dir # there is no reason to run anything as root if os.geteuid() == 0: print("do not run ace as root please") sys.exit(1) # where is ACE? saq_home = '/opt/saq' if 'SAQ_HOME' in os.environ: saq_home = os.environ['SAQ_HOME'] # adjust search path if os.path.join(saq_home, 'lib') not in sys.path: sys.path.append(os.path.join(saq_home, 'lib')) # initialize saq import saq saq.initialize(saq_home=saq_home, config_paths=[], logging_config_path=os.path.join(saq_home, 'etc', 'unittest_logging.ini'), args=None, relative_dir=None) if saq.CONFIG['global']['instance_type'] not in [ 'PRODUCTION', 'QA', 'DEV' ]: sys.stderr.write( '\n\n *** CRITICAL ERROR *** \n\ninvalid instance_type setting in configuration\n' ) sys.exit(1) if saq.CONFIG['global']['instance_type'] == 'PRODUCTION': sys.stderr.write( '\n\n *** PROTECT PRODUCTION *** \ndo not execute this in production, idiot\n' ) sys.exit(1) # additional logging required for testing initialize_unittest_logging() # create a temporary storage directory test_dir = os.path.join(saq.SAQ_HOME, 'var', 'test') if os.path.exists(test_dir): try: shutil.rmtree(test_dir) except Exception as e: logging.error("unable to delete {}: {}".format(test_dir, e)) sys.exit(1) try: os.makedirs(test_dir) except Exception as e: logging.error("unable to create temp dir {}: {}".format(test_dir, e)) #initialize_database() initialized = True
def initialize_test_environment(): global initialized global test_dir if initialized: return # there is no reason to run anything as root if os.geteuid() == 0: print("do not run ace as root please") sys.exit(1) # where is ACE? saq_home = '/opt/saq' if 'SAQ_HOME' in os.environ: saq_home = os.environ['SAQ_HOME'] # adjust search path sys.path.append(os.path.join(saq_home, 'lib')) # initialize saq import saq saq.initialize(saq_home=saq_home, config_paths=[], logging_config_path=os.path.join(saq_home, 'etc', 'unittest_logging.ini'), args=None, relative_dir=None) # additional logging required for testing initialize_unittest_logging() # create a temporary storage directory test_dir = os.path.join(saq.SAQ_HOME, 'var', 'test') if os.path.exists(test_dir): try: shutil.rmtree(test_dir) except Exception as e: logging.error("unable to delete {}: {}".format(test_dir, e)) sys.exit(1) try: os.makedirs(test_dir) except Exception as e: logging.error("unable to create temp dir {}: {}".format(test_dir, e)) # in all our testing we use the password "password" for encryption/decryption from saq.crypto import get_aes_key saq.ENCRYPTION_PASSWORD = get_aes_key('password') initialize_database() initialized = True
def initialize_test_environment(): global test_dir #import saq # indicate that we are unit testing # this changes the behavior of ACE in various places #code = compile('saq.UNIT_TESTING = True', '<string>', 'exec') #import dis; import pdb; pdb.set_trace() #saq.UNIT_TESTING = True # there is no reason to run anything as root if os.geteuid() == 0: print("do not run ace as root please") sys.exit(1) # where is ACE? saq_home = '/opt/saq' if 'SAQ_HOME' in os.environ: saq_home = os.environ['SAQ_HOME'] # adjust search path sys.path.append(os.path.join(saq_home, 'lib')) # initialize saq import saq saq.initialize(saq_home=saq_home, config_paths=[], logging_config_path=os.path.join(saq_home, 'etc', 'unittest_logging.ini'), args=None, relative_dir=None, unittest=True) if saq.CONFIG['global']['instance_type'] not in [ 'PRODUCTION', 'QA', 'DEV' ]: sys.stderr.write( '\n\n *** CRITICAL ERROR *** \n\ninvalid instance_type setting in configuration\n' ) sys.exit(1) if saq.CONFIG['global']['instance_type'] == 'PRODUCTION': sys.stderr.write( '\n\n *** PROTECT PRODUCTION *** \ndo not execute this in production, idiot\n' ) sys.exit(1) # additional logging required for testing initialize_unittest_logging() # create a temporary storage directory test_dir = os.path.join(saq.SAQ_HOME, 'var', 'test') if os.path.exists(test_dir): try: shutil.rmtree(test_dir) except Exception as e: logging.error("unable to delete {}: {}".format(test_dir, e)) sys.exit(1) try: os.makedirs(test_dir) except Exception as e: logging.error("unable to create temp dir {}: {}".format(test_dir, e)) # in all our testing we use the password "password" for encryption/decryption saq.ENCRYPTION_PASSWORD = get_aes_key('password') #initialize_database() initialized = True