def start_app(self): # Make up a DB URI using a named temporary file. self.tempfile = NamedTemporaryFile() uri = 'sqlite:///{}'.format(self.tempfile.name) from eventsourcing.example.interface.flaskapp import IntegerSequencedItem # Close application, importing the module constructed # the application, which will leave event handlers subscribed. close_example_application() # Setup tables. datastore = SQLAlchemyDatastore( settings=SQLAlchemySettings(uri=uri), tables=(IntegerSequencedItem,), ) datastore.setup_connection() datastore.setup_tables() datastore.close_connection() # Run uwsgi. path_to_uwsgi = join(path_to_virtualenv, 'bin', 'uwsgi') assert os.path.exists(path_to_uwsgi), path_to_uwsgi cmd = [path_to_uwsgi] if path_to_virtualenv is not None: cmd += ['-H', path_to_virtualenv] cmd += ['--master'] cmd += ['--processes', '4'] cmd += ['--threads', '2'] cmd += ['--wsgi-file', path_to_flaskwsgi] cmd += ['--http', ':{}'.format(self.port)] pythonpath = ':'.join(os.getenv('PYTHONPATH', '').split(':') + [path_to_eventsourcing]) return Popen(cmd, env={ 'PYTHONPATH': pythonpath, 'DB_URI': uri })
def start_app(self): # Make up a DB URI using a named temporary file. self.tempfile = NamedTemporaryFile() uri = "sqlite:///{}".format(self.tempfile.name) from eventsourcing.example.interface.flaskapp import IntegerSequencedItem # Close application, importing the module constructed # the application, which will leave event handlers subscribed. close_example_application() # Setup tables. datastore = SQLAlchemyDatastore(settings=SQLAlchemySettings(uri=uri), tables=(IntegerSequencedItem, )) datastore.setup_connection() datastore.setup_tables() datastore.close_connection() # Run uwsgi. path_to_uwsgi = shutil.which("uwsgi") if not os.path.exists(path_to_uwsgi): raise AssertionError("Can't find uwsgi: %s" % path_to_uwsgi) cmd = [path_to_uwsgi] if path_to_virtualenv is not None: cmd += ["-H", path_to_virtualenv] cmd += ["--master"] cmd += ["--processes", "4"] cmd += ["--threads", "2"] cmd += ["--wsgi-file", path_to_flaskapp] cmd += ["--http", ":{}".format(self.port)] pythonpath = ":".join( os.getenv("PYTHONPATH", "").split(":") + [path_to_eventsourcing]) return Popen(cmd, env={"PYTHONPATH": pythonpath, "DB_URI": uri})
def start_app(self): # Make up a DB URI using a named temporary file. self.tempfile = NamedTemporaryFile() uri = 'sqlite:///{}'.format(self.tempfile.name) from eventsourcing.example.interface.flaskapp import IntegerSequencedItem # Close application, importing the module constructed # the application, which will leave event handlers subscribed. close_example_application() # Setup tables. datastore = SQLAlchemyDatastore( settings=SQLAlchemySettings(uri=uri), tables=(IntegerSequencedItem,), ) datastore.setup_connection() datastore.setup_tables() datastore.drop_connection() # Run uwsgi. path_to_uwsgi = join(path_to_virtualenv, 'bin', 'uwsgi') assert os.path.exists(path_to_uwsgi), path_to_uwsgi cmd = [path_to_uwsgi] if path_to_virtualenv is not None: cmd += ['-H', path_to_virtualenv] cmd += ['--master'] cmd += ['--processes', '4'] cmd += ['--threads', '2'] cmd += ['--wsgi-file', path_to_flaskwsgi] cmd += ['--http', ':{}'.format(self.port)] pythonpath = ':'.join(os.getenv('PYTHONPATH', '').split(':') + [path_to_eventsourcing]) return Popen(cmd, env={ 'PYTHONPATH': pythonpath, 'DB_URI': uri })
def tearDown(self): # Teardown single instance. close_example_application() # Teardown the database. self.datastore.drop_tables() self.datastore.drop_connection() super(TestExampleApplicationSingleInstanceFunctions, self).tearDown()
def tearDown(self): # Teardown single instance. close_example_application() # Teardown the database. self.datastore.drop_tables() self.datastore.drop_connection() super(TestExampleApplicationSingleInstanceFunctions, self).tearDown()
def test(self): self.datastore.setup_connection() self.datastore.setup_tables() active_record_strategy = SQLAlchemyActiveRecordStrategy( active_record_class=IntegerSequencedItemRecord, session=self.datastore.session, ) # Can't get the single instance before it has been constructed. with self.assertRaises(AssertionError): get_example_application() # Construct single instance. init_example_application( entity_active_record_strategy=active_record_strategy ) # Can't construct single instance twice. with self.assertRaises(AssertionError): init_example_application( entity_active_record_strategy=active_record_strategy ) # Get the single instance. app1 = get_example_application() app2 = get_example_application() self.assertEqual(id(app1), id(app2)) # Close single instance. close_example_application() # Can't get the single instance before it has been constructed. with self.assertRaises(AssertionError): get_example_application() # Construct single instance. init_example_application( entity_active_record_strategy=active_record_strategy ) # Can't construct single instance twice. with self.assertRaises(AssertionError): init_example_application( entity_active_record_strategy=active_record_strategy ) # Get the single instance. app1 = get_example_application() app2 = get_example_application() self.assertEqual(id(app1), id(app2))
def test(self): self.datastore.setup_connection() self.datastore.setup_tables() record_manager = SQLAlchemyRecordManager( record_class=IntegerSequencedNoIDRecord, session=self.datastore.session, ) # Can't get the single instance before it has been constructed. with self.assertRaises(AssertionError): get_example_application() # Construct single instance. init_example_application( entity_record_manager=record_manager ) # Can't construct single instance twice. with self.assertRaises(AssertionError): init_example_application( entity_record_manager=record_manager ) # Get the single instance. app1 = get_example_application() app2 = get_example_application() self.assertEqual(id(app1), id(app2)) # Close single instance. close_example_application() # Can't get the single instance before it has been constructed. with self.assertRaises(AssertionError): get_example_application() # Construct single instance. init_example_application( entity_record_manager=record_manager ) # Can't construct single instance twice. with self.assertRaises(AssertionError): init_example_application( entity_record_manager=record_manager ) # Get the single instance. app1 = get_example_application() app2 = get_example_application() self.assertEqual(id(app1), id(app2))
def start_app(self): # Make up a DB URI using a named temporary file. self.tempfile = NamedTemporaryFile() uri = "sqlite:///{}".format(self.tempfile.name) from eventsourcing.example.interface.flaskapp import IntegerSequencedItem # Close application, importing the module constructed # the application, which will leave event handlers subscribed. close_example_application() # Setup tables. datastore = SQLAlchemyDatastore(settings=SQLAlchemySettings(uri=uri), tables=(IntegerSequencedItem, )) datastore.setup_connection() datastore.setup_tables() datastore.close_connection() # Run uwsgi. if path_to_virtualenv: path_to_uwsgi = join(path_to_virtualenv, "bin", "uwsgi") assert os.path.exists(path_to_uwsgi), path_to_uwsgi else: # In a container, without a virtualenv? path_to_uwsgi = "/usr/local/bin/uwsgi" # Todo: Maybe use shutil.which, after dropping support for Python 2.7. cmd = [path_to_uwsgi] if path_to_virtualenv is not None: cmd += ["-H", path_to_virtualenv] cmd += ["--master"] cmd += ["--processes", "4"] cmd += ["--threads", "2"] cmd += ["--wsgi-file", path_to_flaskwsgi] cmd += ["--http", ":{}".format(self.port)] pythonpath = ":".join( os.getenv("PYTHONPATH", "").split(":") + [path_to_eventsourcing]) return Popen(cmd, env={"PYTHONPATH": pythonpath, "DB_URI": uri})