def test_set_property_selected_false(self): connection = get_database_connection(IN_MEMORY_DB_NAME) with connection: create_database(connection) set_property_selected_true(connection, 0) selected_properties = get_selected_properties(connection) self.assertEqual( len(selected_properties), 1, "There was not exactly one selected property. This is unexpected." ) self.assertEqual( selected_properties[0]["index"], 0, "The selected property's index was not zero. This is unexpected." ) set_property_selected_false(connection, 0) selected_properties_2 = get_selected_properties(connection) self.assertEqual( len(selected_properties_2), 0, "There was not exactly zero selected properties. This is unexpected." )
def test_get_properties_by_address_or_description_fragment(self): connection = get_database_connection(IN_MEMORY_DB_NAME) with connection: create_database(connection) properties = get_properties_by_address_or_description_fragment( connection, "six") self.assertGreater( len(properties), 0, "Zero properties were returned. This is unexpected.")
def test_create_database(self): connection = get_database_connection(IN_MEMORY_DB_NAME) with connection: create_database(connection) cursor = connection.cursor() cursor.execute(get_show_tables_command_string()) response = cursor.fetchall() if len(response) > 0: self.assertEqual( response[0][0], "properties", "The correct database table was not created.") else: self.fail( "There appears to be no database tables. This is unexpected." )
import logging from flask import Flask from app.util import configure_logging from app.apis import register_apis_blueprint from app.views import register_views_blueprint from app.db import (create_database, get_database_connection) logger = logging.getLogger(__name__) configure_logging() flask_application = Flask("enodo", static_folder="app/static") connection = get_database_connection() with connection: create_database(connection) register_views_blueprint(flask_application) register_apis_blueprint(flask_application) flask_application.run(port=8080, debug=True)
try: self._connection = sqlite3.connect(self._file_name) return True except Error as e: print(e) finally: if self._connection: self._connection.close() db.create_all() if __name__ == "__main__": parser = ArgumentParser() parser.add_argument( "-d", "--database", help="""Enter the name of the database or the full path to create it in a different directory""", type=str) args = parser.parse_args() if args.database: db = SQliteDatabse(file_name=args.database) print("Creating database please wait...") if db.create_database(): print("Successfully created database") else: print("Failed to create database")
def setup_db(): db.create_database(settings.DATABASE_URI, run_alembic=False)