def test_database_url(self): a = pw_database_url.config() assert not a os.environ['DATABASE_URL'] = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' url = pw_database_url.config() assert url['engine'] == 'peewee.PostgresqlDatabase' 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
def test_database_url(self): a = pw_database_url.config() assert not a os.environ[ 'DATABASE_URL'] = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' url = pw_database_url.config() assert url['engine'] == 'peewee.PostgresqlDatabase' 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
def test_multiple_database_parsing(self): os.environ.setdefault('DATABASE_URL', 'postgres://*****:*****@host-1.localhost.com:5432/test_db') os.environ.setdefault('DB2_DATABASE_URL', 'mysql://*****:*****@host-2.localhost.com:3306/test_db') databases = pw_database_url.config() assert databases['default']['name'] == 'test_db' assert databases['default']['host'] == 'host-1.localhost.com' assert databases['default']['user'] == 'user1' assert databases['default']['password'] == 'pass1' assert databases['default']['port'] == 5432 assert databases['db2']['name'] == 'test_db' assert databases['db2']['host'] == 'host-2.localhost.com' assert databases['db2']['user'] == 'user2' assert databases['db2']['password'] == 'pass2' assert databases['db2']['port'] == 3306
def test_multiple_database_parsing(self): os.environ.setdefault( 'DATABASE_URL', 'postgres://*****:*****@host-1.localhost.com:5432/test_db') os.environ.setdefault( 'DB2_DATABASE_URL', 'mysql://*****:*****@host-2.localhost.com:3306/test_db') databases = pw_database_url.config() assert databases['default']['name'] == 'test_db' assert databases['default']['host'] == 'host-1.localhost.com' assert databases['default']['user'] == 'user1' assert databases['default']['password'] == 'pass1' assert databases['default']['port'] == 5432 assert databases['db2']['name'] == 'test_db' assert databases['db2']['host'] == 'host-2.localhost.com' assert databases['db2']['user'] == 'user2' assert databases['db2']['password'] == 'pass2' assert databases['db2']['port'] == 3306
import os from flask import * from datetime import datetime from peewee import * import pw_database_url from flask_peewee.db import Database DATABASE = pw_database_url.config() DEBUG = True SECRET_KEY = 'ssshhhh' app = Flask('tweet') app.config.from_object(__name__) db = Database(app) class Tweet(db.Model): """ The data type for a tweet """ created = DateTimeField() content = TextField() class Meta: order_by = ('-created',) @app.template_filter('strftime') def strftime(date): return date.strftime('%a, %b %d, %Y %I %p')
from peewee import * import os import pw_database_url import logging import operator from timeit import default_timer as timer from datetime import datetime, timedelta logger = logging.getLogger('peewee') logger.setLevel(logging.DEBUG) logger.addHandler(logging.StreamHandler()) if os.environ.get('DATABASE_URL', None): config = pw_database_url.config() else: config = { 'engine': 'peewee.PostgresqlDatabase', 'name': 'headlines_development', 'host': 'localhost', 'port': 5432, 'password': None, 'user': None, } db = PostgresqlDatabase(config['name'], host=config['host'], port=config['port'], password=config['password'], user=config['user']) db.get_conn().set_client_encoding('UTF8') db.connect() class SourceHeadline(Model):
import os import pw_database_url from peewee import PostgresqlDatabase, Model config = pw_database_url.config() database = PostgresqlDatabase(config['name'], host=config['host'], port=config['port'], user=config['user'], password=config['password']) database.connect() class BaseModel(Model): class Meta: database = database
import os from flask import * from datetime import datetime from peewee import * import pw_database_url from flask_peewee.db import Database DATABASE = pw_database_url.config() DEBUG = True SECRET_KEY = 'ssshhhh' app = Flask('tweet') app.config.from_object(__name__) db = Database(app) class Tweet(db.Model): """ The data type for a tweet """ created = DateTimeField() content = TextField() class Meta: order_by = ('-created', ) @app.template_filter('strftime') def strftime(date): return date.strftime('%a, %b %d, %Y %I %p')