def __init__(self, postgres_username=None, postgres_password=None, db_username='dbpedia_app', db_password='dummy_password'):
    user_name = db_username
    password = db_password
    if ((postgres_password is not None) and (postgres_username is not None)):
        try:
            connection = psycopg2.connect(("dbname='postgres' user='%s' host='localhost' password='%s'" % (postgres_username, postgres_password)))
            connection.autocommit = True
            cursor = connection.cursor()
            cursor.execute("SELECT COUNT(*) = 0 FROM pg_catalog.pg_database WHERE datname = 'dbpedia'")
            not_exists_row = cursor.fetchone()
            not_exists = not_exists_row[0]
            if not_exists:
                cursor.execute(("CREATE USER %s PASSWORD '%s'" % (user_name, password)))
                cursor.execute(('CREATE DATABASE dbpedia OWNER %s' % (user_name,)))
            connection.close()
        except:
            raise
    try:
        self.connection = psycopg2.connect(("dbname='dbpedia' user='%s' host='localhost' password='%s'" % (user_name, password)))
    except:
        raise AssertionError('Failed to connect to dbpedia database. Has the local dbpedia been created?')
def __init__(self, postgres_username=None, postgres_password=None, db_username='dbpedia_app', db_password='dummy_password'):
    user_name = db_username
    password = db_password
    if ((postgres_password is not None) and (postgres_username is not None)):
        try:
            connection = psycopg2.connect(("dbname='postgres' user='%s' host='localhost' password='%s'" % (postgres_username, postgres_password)))
            connection.autocommit = True
            cursor = connection.cursor()
            cursor.execute("SELECT COUNT(*) = 0 FROM pg_catalog.pg_database WHERE datname = 'dbpedia'")
            not_exists_row = cursor.fetchone()
            not_exists = not_exists_row[0]
            if not_exists:
                cursor.execute(("CREATE USER %s PASSWORD '%s'" % (user_name, password)))
                cursor.execute(('CREATE DATABASE dbpedia OWNER %s' % (user_name,)))
            connection.close()
        except:
            raise
    try:
        self.connection = psycopg2.connect(("dbname='dbpedia' user='%s' host='localhost' password='%s'" % (user_name, password)))
    except:
        raise AssertionError('Failed to connect to dbpedia database. Has the local dbpedia been created?')