def main(argv=None): """Initialize the database.""" print( 'Deprecation warning: This script is going to be removed. ' 'Please use cnx-db init instead.', file=sys.stderr) parser = create_parser('initdb', description=__doc__) parser.add_argument('--with-example-data', action='store_true', help="Initializes the database with example data.") parser.add_argument('--superuser', action='store', help="NOT IMPLEMENTED") parser.add_argument('--super-password', action='store', help="NOT IMPLEMENTED") args = parser.parse_args(argv) settings = get_app_settings_from_arguments(args) try: init_db(settings[config.CONNECTION_STRING], as_venv_importable=True) except DBSchemaInitialized: print("Error: Database is already initialized.", file=sys.stderr) return 1 if args.with_example_data: connection_string = settings[config.CONNECTION_STRING] with psycopg2.connect(connection_string) as db_connection: with db_connection.cursor() as cursor: for filepath in EXAMPLE_DATA_FILEPATHS: with open(filepath, 'r') as fb: cursor.execute(fb.read()) return 0
def setUp(self): EPUBMixInTestCase.setUp(self) config = testing.setUp(settings=self.settings) init_db(self.db_conn_str, True) # Assign API keys for testing self.set_up_api_keys()
def setUp(self, cursor): settings = testing.integration_test_settings() from ...config import CONNECTION_STRING self.db_conn_str = settings[CONNECTION_STRING] # Initialize database init_db(self.db_conn_str, True)
def _init_database(db_engines): engine = db_engines['super'] try: # Check for database engine.execute('select 1') except (ProgrammingError, OperationalError): # Create the database and initialize the schema _create_database(db_engines) init_db(db_engines['super']) # Assign priveleges to our common user. for element in ( 'tables', 'sequences', ): engine.execute( text('GRANT ALL PRIVILEGES ON ALL {} ' 'IN SCHEMA PUBLIC TO {}'.format( element.upper(), db_engines['common'].url.username))) engine.execute( text('REASSIGN OWNED BY {} TO {}'.format( db_engines['super'].url.username, db_engines['common'].url.username))) finally: # Dispose of any connection(s) engine.dispose()
def setUp(self): if self.is_set_up: # Failed to clean up after last use. self.tearDown() # Initialize the database schema. from cnxdb.init import init_db init_db(self._settings[config.CONNECTION_STRING], True) self.is_set_up = True
def setUp(self): if self.is_set_up: # Failed to clean up after last use. self.tearDown() # Initialize the database schema. from cnxdb.init import init_db from sqlalchemy import create_engine dsn = self._settings[config.CONNECTION_STRING] engine = create_engine(libpq_dsn_to_url(dsn)) init_db(engine, True) self.is_set_up = True
def setUp(self): self.config = testing.setUp(settings=self.settings) init_db(self.db_conn_str, True) self.create_post_args = { 'message': 'test message', 'priority': 1, 'type': 1, 'start_date': '2017-01-01', 'start_time': '00:01', 'end_date': '2017-01-02', 'end_time': '00:02', }
def install_intercept(): """Initializes both the archive and publishing applications. Then this will register intercepts for both applications using the configuration setting found in the authoring config file. This sets up the example data found in cnx-archive. Any previously initialized data will be lost. Therefore, it is a good idea to only initialize the applications during testcase class setup (i.e. setUpClass). """ settings = publishing_settings() authoring_settings = integration_test_settings() connection_string = settings[config.CONNECTION_STRING] # Wipe out any previous attempts. with psycopg2.connect(connection_string) as db_connection: with db_connection.cursor() as cursor: cursor.execute("DROP SCHEMA public CASCADE; CREATE SCHEMA public") # Initialize the database. init_db(connection_string, True) with psycopg2.connect(connection_string) as db_connection: with db_connection.cursor() as cursor: filepath = config.TEST_DATA_SQL_FILE with open(filepath, 'r') as fb: cursor.execute(fb.read()) # Make amendments to the data that are specific to the authoring tests. _amend_archive_data() _amend_publishing_data() # Set up the intercept for archive global _archive_app if not _archive_app: _archive_app = archive_main({}, **publishing_settings()) def make_app(): return _archive_app # Grab the configured archive url from the authoring config. host, port = _parse_url_from_settings(authoring_settings, 'archive.url') add_wsgi_intercept(host, port, make_app) # Set up the intercept for publishing global _publishing_app if not _publishing_app: _publishing_app = publishing_main({}, **publishing_settings()) def make_app(): return _publishing_app # Grab the configured publishing url from the authoring config. host, port = _parse_url_from_settings(authoring_settings, 'publishing.url') add_wsgi_intercept(host, port, make_app)
def setUp(self): self.config = testing.setUp(settings=self.settings) init_db(self.db_conn_str, True)
def setUp(self): self.config = testing.setUp(settings=self.settings) self.config.include('cnxpublishing.tasks') init_db(self.db_conn_str, True)