How to use emmett - 10 common examples

To help you get started, we’ve selected a few emmett examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emmett-framework / emmett / tests / test_migrations.py View on Github external
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


class StepFiveThing(Model):
    name = Field()
    value = Field.int()
    created_at = Field.datetime()

    indexes = {
        'name': True,
        ('name', 'value'): True
    }


class StepFiveThingEdit(StepFiveThing):
    tablename = "step_five_things"

    indexes = {
        'name': False,
        'name_created': {
            'fields': 'name',
            'expressions': lambda m: m.created_at.coalesce(None)}
github emmett-framework / emmett / tests / test_migrations.py View on Github external
ops2 = _make_ops(db2, ops)
    op = ops2.ops[0]
    sql = _make_sql(db, op)
    assert sql == _step_three_sql_drop


class StepFourThing(Model):
    name = Field(notnull=True)
    value = Field.float(default=8.8)
    available = Field.bool(default=True)
    asd = Field()


class StepFourThingEdit(Model):
    tablename = "step_four_things"
    name = Field()
    value = Field.float()
    available = Field.bool(default=True)
    asd = Field.int()

_step_four_sql = """ALTER TABLE "step_four_things" ALTER COLUMN "name" DROP NOT NULL;
ALTER TABLE "step_four_things" ALTER COLUMN "value" DROP DEFAULT;
ALTER TABLE "step_four_things" ALTER COLUMN "asd" TYPE INTEGER;"""


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)
github emmett-framework / emmett / tests / test_migrations.py View on Github external
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


class StepFourThing(Model):
    name = Field(notnull=True)
    value = Field.float(default=8.8)
    available = Field.bool(default=True)
    asd = Field()


class StepFourThingEdit(Model):
    tablename = "step_four_things"
    name = Field()
    value = Field.float()
    available = Field.bool(default=True)
    asd = Field.int()

_step_four_sql = """ALTER TABLE "step_four_things" ALTER COLUMN "name" DROP NOT NULL;
ALTER TABLE "step_four_things" ALTER COLUMN "value" DROP DEFAULT;
ALTER TABLE "step_four_things" ALTER COLUMN "asd" TYPE INTEGER;"""


def test_step_four_alter_table(app):
    db = Database(app, auto_migrate=False)
github emmett-framework / emmett / tests / test_migrations.py View on Github external
assert sql == _step_three_sql


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


class StepFourThing(Model):
    name = Field(notnull=True)
    value = Field.float(default=8.8)
    available = Field.bool(default=True)
    asd = Field()


class StepFourThingEdit(Model):
    tablename = "step_four_things"
    name = Field()
    value = Field.float()
    available = Field.bool(default=True)
    asd = Field.int()

_step_four_sql = """ALTER TABLE "step_four_things" ALTER COLUMN "name" DROP NOT NULL;
ALTER TABLE "step_four_things" ALTER COLUMN "value" DROP DEFAULT;
ALTER TABLE "step_four_things" ALTER COLUMN "asd" TYPE INTEGER;"""
github emmett-framework / emmett / tests / test_migrations.py View on Github external
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


class StepFiveThing(Model):
    name = Field()
    value = Field.int()
    created_at = Field.datetime()

    indexes = {
        'name': True,
        ('name', 'value'): True
    }


class StepFiveThingEdit(StepFiveThing):
    tablename = "step_five_things"

    indexes = {
        'name': False,
        'name_created': {
github emmett-framework / emmett / tests / test_migrations.py View on Github external
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


class StepFourThing(Model):
    name = Field(notnull=True)
    value = Field.float(default=8.8)
    available = Field.bool(default=True)
    asd = Field()


class StepFourThingEdit(Model):
    tablename = "step_four_things"
    name = Field()
    value = Field.float()
    available = Field.bool(default=True)
    asd = Field.int()

_step_four_sql = """ALTER TABLE "step_four_things" ALTER COLUMN "name" DROP NOT NULL;
ALTER TABLE "step_four_things" ALTER COLUMN "value" DROP DEFAULT;
ALTER TABLE "step_four_things" ALTER COLUMN "asd" TYPE INTEGER;"""


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)
github emmett-framework / emmett / tests / test_routing.py View on Github external
def test_module_url(app):
    with current_ctx(app, '/') as ctx:
        ctx.request.language = 'it'
        link = url('test_route')
        assert link == '/it/test_route'
        link = url('test_route2')
        assert link == '/it/test2'
        link = url('test_route2', [2])
        assert link == '/it/test2/2'
        link = url('test_route2', [2, 'foo'])
        assert link == '/it/test2/2/foo'
        link = url('test_route3')
        assert link == '/it/test3'
        link = url('test_route3', [2])
        assert link == '/it/test3/2/foo'
        link = url('test_route3', [2, 'bar'])
        assert link == '/it/test3/2/foo/bar'
        link = url('test_route3', [2, 'bar', 'json'])
        assert link == '/it/test3/2/foo/bar.json'
        link = url(
            'test_route3', [2, 'bar', 'json'], {'foo': 'bar', 'bar': 'foo'})
        lsplit = link.split('?')
        assert lsplit[0] == '/it/test3/2/foo/bar.json'
        assert lsplit[1] in ['foo=bar&bar=foo', 'bar=foo&foo=bar']
github emmett-framework / emmett / tests / test_routing.py View on Github external
assert link == '/it/test_route'
        link = url('test_route2')
        assert link == '/it/test2'
        link = url('test_route2', [2])
        assert link == '/it/test2/2'
        link = url('test_route2', [2, 'foo'])
        assert link == '/it/test2/2/foo'
        link = url('test_route3')
        assert link == '/it/test3'
        link = url('test_route3', [2])
        assert link == '/it/test3/2/foo'
        link = url('test_route3', [2, 'bar'])
        assert link == '/it/test3/2/foo/bar'
        link = url('test_route3', [2, 'bar', 'json'])
        assert link == '/it/test3/2/foo/bar.json'
        link = url(
            'test_route3', [2, 'bar', 'json'], {'foo': 'bar', 'bar': 'foo'})
        lsplit = link.split('?')
        assert lsplit[0] == '/it/test3/2/foo/bar.json'
        assert lsplit[1] in ['foo=bar&bar=foo', 'bar=foo&foo=bar']
github emmett-framework / emmett / tests / test_routing.py View on Github external
def test_module_url(app):
    with current_ctx(app, '/') as ctx:
        ctx.request.language = 'it'
        link = url('test_route')
        assert link == '/it/test_route'
        link = url('test_route2')
        assert link == '/it/test2'
        link = url('test_route2', [2])
        assert link == '/it/test2/2'
        link = url('test_route2', [2, 'foo'])
        assert link == '/it/test2/2/foo'
        link = url('test_route3')
        assert link == '/it/test3'
        link = url('test_route3', [2])
        assert link == '/it/test3/2/foo'
        link = url('test_route3', [2, 'bar'])
        assert link == '/it/test3/2/foo/bar'
        link = url('test_route3', [2, 'bar', 'json'])
        assert link == '/it/test3/2/foo/bar.json'
        link = url(
            'test_route3', [2, 'bar', 'json'], {'foo': 'bar', 'bar': 'foo'})
        lsplit = link.split('?')
        assert lsplit[0] == '/it/test3/2/foo/bar.json'
        assert lsplit[1] in ['foo=bar&bar=foo', 'bar=foo&foo=bar']
github emmett-framework / emmett / tests / test_routing.py View on Github external
def current_ctx(app, path):
    builder = ScopeBuilder(path)
    token = current._init_(FakeRequestContext, app, builder.get_data()[0])
    yield current
    current._close_(token)