def test_cleardb_parsing(self): url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = pw_database_url.parse(url) assert url['engine'] == 'peewee.MySQLDatabase' assert url['name'] == 'heroku_97681db3eff7580' assert url['host'] == 'us-cdbr-east.cleardb.com' assert url['user'] == 'bea6eb025ca0d8' assert url['password'] == '69772142' assert url['port'] is None
def test_postgresext_parsing(self): url = 'postgresext://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' url = pw_database_url.parse(url) assert url['engine'] == 'playhouse.postgres_ext.PostgresqlExtDatabase' assert url['name'] == 'd8r82722r2kuvn' assert url['host'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['user'] == 'uf07k1i6d8ia0v' assert url['password'] == 'wegauwhgeuioweg' assert url['port'] == 5431
from lib.log import log # Default DATABASE_URL will be LOCAL_DB_DEFAULT below for local development # Set environment variable DATABASE_URL if you want something different # Other suitable cloud DBs: # HEROKU_TEST_DB = "postgres://vyxede....." # ELEPHANTSQL_TEST_DB = "postgres://bffueem....." ## THE PRODUCTION DB: LOCAL_DB_DEFAULT = "postgres://localhost:5432/localDB" import os # TODO: avoid os, use a env.py module to centralize all env-vars DATABASE_URL = os.environ.get('DATABASE_URL', LOCAL_DB_DEFAULT) import pw_database_url db_dict = pw_database_url.parse(DATABASE_URL) print("Database dict: %s" % db_dict) TheDB = PostgresqlDatabase(db_dict['name'], user=db_dict['user'], password=db_dict['password'], host=db_dict['host'], port=db_dict['port']) TheDB.connect() class BaseModel(Model): class Meta: database = TheDB @classmethod def exists(cls, expr):