Example #1
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
Example #2
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
Example #3
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
Example #4
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
Example #5
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
Example #6
0
def _db(app):
    try:
        shutil.rmtree(os.path.join(app.root_path, 'databases'))
    except:
        pass
    db = Database(app)
    app.pipeline.append(db.pipe)
    return db
Example #7
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
Example #8
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
Example #9
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
Example #10
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
Example #11
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
Example #12
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
Example #13
0
    fields_rw = {'user': False, 'date': False}


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)
Example #14
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()

Example #15
0
from weppy import App, session, redirect, url, response, request
from weppy.sessions import SessionManager, current
from weppy.tools import service

from weppy.orm import Database
from weppy.tools import Auth, requires
from models.Models import User, Issue

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)
Example #16
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