예제 #1
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
예제 #2
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
예제 #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 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
예제 #10
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
예제 #11
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
예제 #12
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
예제 #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 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
예제 #15
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
예제 #16
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
예제 #17
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
예제 #18
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
예제 #19
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
예제 #20
0
    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, 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")
예제 #21
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
예제 #22
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)
예제 #23
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
예제 #24
0
import json

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")
예제 #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
app.config.auth.single_template = True

## language settings
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'
예제 #27
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")
예제 #28
0
app.config.auth.single_template = True

## language settings
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
예제 #29
0
from weppy_bs3 import BS3
from weppy_rest import REST, serialize

from logic.scanning import begin_scan, scan_finished_callback
from serializers.hardware import SpectrumAnalyzerSerializer, FieldProbeSerializer
from serializers.scanning import ScanSerializer, ResultSerializer, ScanResultMatSerializer
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__,
예제 #30
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"))
예제 #31
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()

예제 #32
0
    temperature = Field.float()

    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("/")
예제 #33
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
예제 #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()

예제 #35
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)