示例#1
0
def db():
    app = App(__name__)
    db = Database(
        app, config=sdict(
            uri='sqlite:memory', auto_migrate=True, auto_connect=True))
    db.define_models(Register)
    return db
示例#2
0
def test_step_two_create_table(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepTwoThing)
    ops = _make_ops(db)
    op = ops.ops[0]
    sql = _make_sql(db, op)
    assert sql == _step_two_sql
示例#3
0
def test_step_two_create_table(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepTwoThing)
    ops = _make_ops(db)
    op = ops.ops[0]
    sql = _make_sql(db, op)
    assert sql == _step_two_sql
示例#4
0
def db():
    app = App(__name__)
    db = Database(app, config=sdict(uri='sqlite://validators.db'))
    db.define_models([
        A, AA, AAA, B, Consist, Len, Inside, Num, Eq, Match, Anyone, Proc,
        Person, Thing, Allowed, Mixed
    ])
    return db
示例#5
0
def db():
    app = App(__name__)
    db = Database(app,
                  config=sdict(uri='sqlite:memory',
                               auto_migrate=True,
                               auto_connect=True))
    db.define_models(Register)
    return db
示例#6
0
def test_step_one_create_table(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepOneThing)
    ops = _make_ops(db)
    diffs = ops.as_diffs()
    assert len(diffs) == 1 and diffs[0][0] == "add_table"
    op = ops.ops[0]
    sql = _make_sql(db, op)
    assert sql == _step_one_sql
示例#7
0
def db():
    app = App(__name__)
    db = Database(app, config=sdict(uri='sqlite://dal.db'))
    db.define_models([
        Stuff, Person, Thing, Feature, Price, Doctor, Patient, Appointment,
        User, Organization, Membership, House, Mouse, NeedSplit, Zoo, Animal,
        Elephant, Dog, Subscription
    ])
    return db
示例#8
0
def test_step_one_create_table(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepOneThing)
    ops = _make_ops(db)
    diffs = ops.as_diffs()
    assert len(diffs) == 1 and diffs[0][0] == "add_table"
    op = ops.ops[0]
    sql = _make_sql(db, op)
    assert sql == _step_one_sql
示例#9
0
def test_step_three_drop_column(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepThreeThingTwo)
    ops = _make_ops(db)
    db2 = Database(app, auto_migrate=False)
    db2.define_models(StepThreeThingThree)
    ops2 = _make_ops(db2, ops)
    op = ops2.ops[0]
    sql = _make_sql(db, op)
    assert sql == _step_three_sql_drop
示例#10
0
def test_step_three_drop_column(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepThreeThingTwo)
    ops = _make_ops(db)
    db2 = Database(app, auto_migrate=False)
    db2.define_models(StepThreeThingThree)
    ops2 = _make_ops(db2, ops)
    op = ops2.ops[0]
    sql = _make_sql(db, op)
    assert sql == _step_three_sql_drop
示例#11
0
def test_step_four_alter_table(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepFourThing)
    ops = _make_ops(db)
    db2 = Database(app, auto_migrate=False)
    db2.define_models(StepFourThingEdit)
    ops2 = _make_ops(db2, ops)
    sql = []
    for op in ops2.ops:
        sql.append(_make_sql(db2, op))
    assert "\n".join(sql) == _step_four_sql
示例#12
0
def db():
    app = App(__name__)
    db = Database(
        app, config=sdict(
            uri='sqlite://validators.db', auto_connect=True,
            auto_migrate=True))
    db.define_models([
        A, AA, AAA, B, Consist, Len, Inside, Num, Eq, Match, Anyone, Proc,
        Person, Thing, Allowed, Mixed
    ])
    return db
示例#13
0
def test_step_four_alter_table(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepFourThing)
    ops = _make_ops(db)
    db2 = Database(app, auto_migrate=False)
    db2.define_models(StepFourThingEdit)
    ops2 = _make_ops(db2, ops)
    sql = []
    for op in ops2.ops:
        sql.append(_make_sql(db2, op))
    assert "\n".join(sql) == _step_four_sql
示例#14
0
def db():
    app = App(__name__)
    db = Database(
        app, config=sdict(
            uri='sqlite://dal.db', auto_connect=True, auto_migrate=True))
    db.define_models([
        Stuff, Person, Thing, Feature, Price, Doctor, Patient, Appointment,
        User, Organization, Membership, House, Mouse, NeedSplit, Zoo, Animal,
        Elephant, Dog, Subscription
    ])
    return db
示例#15
0
def test_step_one_drop_table(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepOneThing)
    ops = _make_ops(db)
    db2 = Database(app, auto_migrate=False)
    db2.define_models()
    ops2 = _make_ops(db2, ops)
    diffs = ops2.as_diffs()
    assert len(diffs) == 1 and diffs[0][0] == "remove_table"
    op = ops2.ops[0]
    sql = _make_sql(db2, op)
    assert sql == _step_one_sql_drop
示例#16
0
def test_step_one_drop_table(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepOneThing)
    ops = _make_ops(db)
    db2 = Database(app, auto_migrate=False)
    db2.define_models()
    ops2 = _make_ops(db2, ops)
    diffs = ops2.as_diffs()
    assert len(diffs) == 1 and diffs[0][0] == "remove_table"
    op = ops2.ops[0]
    sql = _make_sql(db2, op)
    assert sql == _step_one_sql_drop
示例#17
0
def test_step_five_indexes(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepFiveThing)
    ops = _make_ops(db)
    index_ops = ops.ops[1:]
    for op in index_ops:
        sql = _make_sql(db, op)
        assert sql in _step_five_sql_before
    db2 = Database(app, auto_migrate=False)
    db2.define_models(StepFiveThingEdit)
    ops2 = _make_ops(db2, ops)
    for op in ops2.ops:
        sql = _make_sql(db, op)
        assert sql in _step_five_sql_after
示例#18
0
def test_step_five_indexes(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepFiveThing)
    ops = _make_ops(db)
    index_ops = ops.ops[1:]
    for op in index_ops:
        sql = _make_sql(db, op)
        assert sql in _step_five_sql_before
    db2 = Database(app, auto_migrate=False)
    db2.define_models(StepFiveThingEdit)
    ops2 = _make_ops(db2, ops)
    for op in ops2.ops:
        sql = _make_sql(db, op)
        assert sql in _step_five_sql_after
    validation = {
        'station_id': {
            'presence': True
        },
        'date': {
            'presence': True
        },
        'temperature': {
            'presence': True
        }
    }


db = Database(app, auto_migrate=False)
db.define_models(Reading)

app.pipeline = [db.pipe]


@app.command('setup')
def setup():
    reading = Reading.create(station_id='XXX',
                             date=time.asctime(),
                             temperature=73.0)
    print(reading)
    db.commit()


@app.route("/")
def index():
示例#20
0
from redis import Redis

app = App(__name__)

app.config.static_version = '1.5.0'
app.config.static_version_urls = True
app.config.url_default_namespace = "main"
app.config_from_yaml('redis.yml', 'redis')
app.config_from_yaml('sentry.yml', 'Sentry')
app.config.Haml.set_as_default = True

app.use_extension(Haml)
app.use_extension(Sentry)

from .models import Version, Extension

db = Database(app, auto_migrate=True)
db.define_models(Version, Extension)

redis = Redis(**app.config.redis)
cache = Cache(redis=RedisCache(**app.config.redis))

app.pipeline = [db.pipe]

from .controllers import main, docs, extensions
from . import commands

#: ensure 'docs' folder presence
if not os.path.exists(os.path.join(app.root_path, "docs")):
    os.mkdir(os.path.join(app.root_path, "docs"))
示例#21
0
from tasks import increase_progress
from utils import CORS

app = App(__name__)
app.config.url_default_namespace = "main"
app.use_extension(BS3)
app.use_extension(REST)

app.config_from_yaml('db.yml', 'db')
db = Database(app, auto_migrate=True)
app.pipeline = [db.pipe, CORS()]

from models.hardware import SpectrumAnalyzer, FieldProbe
from models.scanning import Scan, ScanResult, XResultRow, ScanResultMat

db.define_models(SpectrumAnalyzer, FieldProbe, Scan, ScanResult, XResultRow,
                 ScanResultMat)
from controllers import main, hardware, scanning

analyzers = app.rest_module(__name__,
                            'spectrumanalyzer',
                            SpectrumAnalyzer,
                            serializer=SpectrumAnalyzerSerializer,
                            url_prefix='analyzers')
probes = app.rest_module(__name__,
                         'fieldprobe',
                         FieldProbe,
                         serializer=FieldProbeSerializer,
                         url_prefix='probes')

scans = app.rest_module(__name__,
                        'scan',
示例#22
0
def initialize_database():
    app = App('app')
    app.config_from_yaml('db.yml', 'db')
    db = Database(app)
    db.define_models(SpectrumAnalyzer, FieldProbe, Scan, ScanResult)
    return db
示例#23
0
class Comment(Model):
    belongs_to('user', 'post')

    text = Field('text')
    date = Field('datetime')

    default_values = {'user': lambda: session.auth.user.id, 'date': now}
    validation = {'text': {'presence': True}}
    fields_rw = {'user': False, 'post': False, 'date': False}


#: init db and auth
db = Database(app)
auth = Auth(app, db, user_model=User)
db.define_models(Post, Comment)


#: setup helping function
def setup_admin():
    # create the user
    user = User.create(email="*****@*****.**",
                       first_name="Walter",
                       last_name="Bishop",
                       password="******")
    # create an admin group
    admins = auth.create_group("admin")
    # add user to admins group
    auth.add_membership(admins, user.id)
    db.commit()
示例#24
0
app.languages = ['en', 'it']
app.language_default = 'en'
app.language_force_on_url = True
app.language_write = True

## init database and auth
from models.user import User
from models.campaign import Campaign
from models.donation import Donation
from models.cost import Cost
## init auth before passing db models due to dependencies
## on auth tables in the other models
db = Database(app, auto_migrate=True)
auth = Auth(app, db, user_model=User)
# auth.settings.update(download_url='/download')
db.define_models(Campaign, Donation, Cost)

## adding sessions and authorization handlers
app.pipeline = [
    SessionManager.cookies('verySecretKey'),
    db.pipe,
    auth.pipe
]

## add esxtensions
from weppy_haml import Haml
from weppy_assets import Assets
from weppy_bs3 import BS3
app.config.Haml.set_as_default = True
# app.config.Haml.auto_reload = True
app.use_extension(Haml)
示例#25
0
def test_step_one_no_diff_in_migration(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepOneThing)
    ops = _make_ops(db)
    ops2 = _make_ops(db, ops)
    assert len(ops2.as_diffs()) == 0
示例#26
0
def test_step_one_no_diff_in_migration(app):
    db = Database(app, auto_migrate=False)
    db.define_models(StepOneThing)
    ops = _make_ops(db)
    ops2 = _make_ops(db, ops)
    assert len(ops2.as_diffs()) == 0
示例#27
0
def db():
    app = App(__name__)
    db = Database(app, config=sdict(uri='sqlite:memory'))
    auth = Auth(app, db, usermodel=User)
    db.define_models(Thing)
    return db
示例#28
0
    @rowmethod('serialize')
    def _serialize(self, row):
        return {'id': row.id, 'message': row.message}


app.config.handle_static = False
app.config.db.adapter = 'postgres:psycopg2' \
    if not _is_pypy else 'postgres:pg8000'
app.config.db.host = DBHOSTNAME
app.config.db.user = '******'
app.config.db.password = '******'
app.config.db.database = 'hello_world'
app.config.db.pool_size = 100

db = Database(app, auto_migrate=False)
db.define_models(World, Fortune)


@app.route()
@service.json
def json():
    return {'message': 'Hello, World!'}


@app.route("/db", pipeline=[db.pipe])
@service.json
def get_random_world():
    return World.get(randint(1, 10000)).serialize()


def get_qparam():
示例#29
0
app.languages = ['en', 'it']
app.language_default = 'en'
app.language_force_on_url = True
app.language_write = True

## init database and auth
from models.user import User
from models.campaign import Campaign
from models.donation import Donation
from models.cost import Cost
## init auth before passing db models due to dependencies
## on auth tables in the other models
db = Database(app, auto_migrate=True)
auth = Auth(app, db, user_model=User)
# auth.settings.update(download_url='/download')
db.define_models(Campaign, Donation, Cost)

## adding sessions and authorization handlers
app.pipeline = [SessionManager.cookies('verySecretKey'), db.pipe, auth.pipe]

## add esxtensions
from weppy_haml import Haml
from weppy_assets import Assets
from weppy_bs3 import BS3
app.config.Haml.set_as_default = True
# app.config.Haml.auto_reload = True
app.use_extension(Haml)
app.config.Assets.out_folder = 'gen'
app.use_extension(Assets)
app.use_extension(BS3)
示例#30
0
from weppy import App
from weppy.orm import Database, Model, Field
from weppy.tools import service
from pymongo import MongoClient
from load import generate_load


class ExampleModel(Model):
    foo = Field.string()
    bar = Field.string()


app = App(__name__)
db = Database(app, auto_migrate=True)
db.define_models(ExampleModel)
app.pipeline = [db.pipe]

client = MongoClient()
db = client.test_database
foos = db.foos  # collection of foo objects


@app.route("/")
@service.json
def simple_json():
    return {'foo': 'bar'}


@app.route("/model")
@service.json
示例#31
0
import json

from weppy import App, abort
from weppy.tools import service
from weppy.orm import Database, Model, Field
from weppy.sessions import SessionCookieManager

from .build import build_all
from .keys import DB_PIPE_KEY
from .models import Character

app = App(__name__)

db = Database(app, auto_migrate=True)
db.define_models(Character)


@app.command('setup')
def setup():
    build_all(db)


app.pipeline = [SessionCookieManager(DB_PIPE_KEY), db.pipe]


@app.route('/')
def there_is_always_one_truth():
    return "真実はいつもひとつ!"


@app.route('/character/<int:character_id>', methods="get")
示例#32
0
    }
    validation = {
        'id': {
            'presence': True
        },
    }
    fields_rw = {'user': False, 'date': False}


class Comment(Model):
    belongs_to('user', 'image')

    text = Field('text')
    date = Field('datetime')

    default_values = {
        'user': lambda: session.auth.user.id,
        'date': lambda: now
    }
    validation = {'text': {'presence': True}}
    fields_rw = {'user': False, 'image': False, 'date': False}


db = Database(app, auto_migrate=True)
auth = Auth(app, db, user_model=User)
db.define_models(Image, Comment)

if __name__ == "__main__":
    app.run()
    hello()
示例#33
0
文件: bloggy.py 项目: gi0baro/weppy
        'date': now
    }
    validation = {
        'text': {'presence': True}
    }
    fields_rw = {
        'user': False,
        'post': False,
        'date': False
    }


#: init db and auth
db = Database(app, auto_migrate=True)
auth = Auth(app, db, user_model=User)
db.define_models(Post, Comment)


#: setup helping function
def setup_admin():
    # create the user
    user = User.create(
        email="*****@*****.**",
        first_name="Walter",
        last_name="Bishop",
        password="******"
    )
    # create an admin group
    admins = auth.create_group("admin")
    # add user to admins group
    auth.add_membership(admins, user.id)
示例#34
0
    @rowmethod('serialize')
    def _serialize(self, row):
        return {'id': row.id, 'message': row.message}


app.config.handle_static = False
app.config.db.adapter = 'postgres:psycopg2' \
    if not _is_pypy else 'postgres:pg8000'
app.config.db.host = DBHOSTNAME
app.config.db.user = '******'
app.config.db.password = '******'
app.config.db.database = 'hello_world'
app.config.db.pool_size = 100

db = Database(app, auto_migrate=False)
db.define_models(World, Fortune)


@app.route()
@service.json
def json():
    return {'message': 'Hello, World!'}


@app.route("/db", pipeline=[db.pipe])
@service.json
def get_random_world():
    return World.get(randint(1, 10000)).serialize()


def get_qparam():
示例#35
0
app = App(__name__)
app.config.db.uri = 'postgres://*****:*****@localhost/bazinga'

app.config.auth.single_template = True
app.config.auth.registration_verification = False
app.config.auth.hmac_key = "SomedayWholePeopleWillbeFucked"

db = Database(app, auto_migrate=True)
auth = Auth(app, db, user_model=User)

app.pipeline = [
    SessionManager.cookies('SomedayWholePeopleWillbeFucked'), db.pipe,
    auth.pipe
]

db.define_models(User, Issue)

auth_routes = auth.module(__name__)


def not_authorized():
    redirect(location='/system/login', status_code=302)


@app.route('/', methods=["get"], template='pages/index.html')
def index():
    response.meta.title = 'Bazinga Issue Tracker System'

    return dict(user={})