def setUp(self): super(AuthTestCase, self).setUp() logsetting.init() database.init(self.DATABASE_URL) database.create_db() self.test_client = app.test_client()
def setUp(self): super(ApiTestCase, self).setUp() # Create database file try: self.db_dir = tempfile.mkdtemp() self.db_file = '/'.join((self.db_dir, 'app.db')) except Exception: sys.exit(2) database_url = '/'.join(('sqlite://', self.db_file)) # Get a free random port for app server try: tmp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tmp_socket.bind(('', 0)) self.port = tmp_socket.getsockname()[-1] tmp_socket.close() time.sleep(10) except socket.error: sys.exit(1) cmd = '%s run_server.py %s %d' % (sys.executable, database_url, self.port) self.proc = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, preexec_fn=os.setsid, cwd=curr_dir) time.sleep(5) # Initial database try: database.init(database_url) except Exception as error: print "Exception when initializing database: %s" % error
def setUp(self): super(ApiTestCase, self).setUp() # Create database file try: self.db_dir = tempfile.mkdtemp() self.db_file = '/'.join((self.db_dir, 'app.db')) except Exception: sys.exit(2) database_url = '/'.join(('sqlite://', self.db_file)) # Get a free random port for app server try: tmp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tmp_socket.bind(('', 0)) self.port = tmp_socket.getsockname()[-1] tmp_socket.close() time.sleep(10) except socket.error: sys.exit(1) cmd = '%s run_server.py %s %d' % ( sys.executable, database_url, self.port) self.proc = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, preexec_fn=os.setsid, cwd=curr_dir) time.sleep(5) # Initial database try: database.init(database_url) except Exception as error: print "Exception when initializing database: %s" % error
def tearDown(self): super(ApiTestCase, self).tearDown() database.ENGINE.dispose() database.init('sqlite://') os.killpg(self.proc.pid, signal.SIGTERM) try: if os.path.exists(self.db_dir): shutil.rmtree(self.db_dir) except Exception: sys.exit(1)
def setUp(self): super(ApiTestCase, self).setUp() database.init(self.DATABASE_URL) database.create_db() self.app = app.test_client() # We do not want to send a real task as our test environment # does not have a AMQP system set up. TODO(): any better way? current_app.send_task = Mock() # We do not want to send a real task as our test environment # does not have a AMQP system set up. TODO(): any better way? current_app.send_task = Mock()
def setUp(self): super(TestPollSwitch, self).setUp() logsetting.init() database.init(self.DATABASE_URL) database.create_db() self.test_client = app.test_client() with database.session() as session: # Add one switch to DB switch = Switch(ip="127.0.0.1", credential=self.SWITCH_CREDENTIAL) session.add(switch) # Add filter port to SwitchConfig table filter_list = [ SwitchConfig(ip="127.0.0.1", filter_port='6'), SwitchConfig(ip="127.0.0.1", filter_port='7') ] session.add_all(filter_list)
def setUp(self): super(ApiTestCase, self).setUp() database.init(self.DATABASE_URL) database.create_db() self.app = app.test_client() # We do not want to send a real task as our test environment # does not have a AMQP system set up. TODO(): any better way? current_app.send_task = Mock() # We do not want to send a real task as our test environment # does not have a AMQP system set up. TODO(): any better way? current_app.send_task = Mock() self.backup_logfile = flags.OPTIONS.logfile if not flags.OPTIONS.logfile: flags.OPTIONS.logfile = '/tmp/test_api.log' logsetting.init()
def test_init(self): database.init('sqlite:///tmp/app.db') self.assertEqual(str(database.ENGINE.url), 'sqlite:///tmp/app.db') self.assertEqual(str(database.SCOPED_SESSION.bind.url), 'sqlite:///tmp/app.db')
def setUp(self): super(TestDatabase, self).setUp() logsetting.init() database.init('sqlite://')
def setUp(self): super(TestModel, self).setUp() logsetting.init() database.init('sqlite://') database.create_db()
def setUp(self): super(TestModel, self).setUp() logsetting.init() database.init("sqlite://") database.create_db()
message="Successfully!"), HostState(id=4, state="ERROR", progress=0.5, message="Failed!"), HostState(id=5, state="READY", progress=1.0, message="Successfully!"), HostState(id=6, state="ERROR", progress=1.0, message="Failed!") ] session.add_all(host_states) if __name__ == '__main__': db_url, port = sys.argv[1:] print db_url try: database.init(db_url) database.create_db() except Exception as error: print "=====> Failed to create database" print error try: setupDb() except Exception as error: print "setupDb=====>Failed to setup database" print error print "Starting server ....." print "port is ", port app.run(use_reloader=False, host="0.0.0.0", port=port)