Example #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
Example #2
0
def db():
    app = App(__name__)
    db = DAL(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 #3
0
def test_user_assign_invaild_level():
    app = App(__name__)
    app.config.logging.pytest = sdict(
        level='invalid'
    )
    result = _call_create_logger(app)
    assert result.handlers[-1].level == logging.WARNING
Example #4
0
def db():
    app = App(__name__)
    db = DAL(app, config=sdict(uri='sqlite://dal.db'))
    db.define_models([
        Stuff, Person, Thing, Feature, Price, Doctor, Patient, Appointment,
        House, Mouse, NeedSplit, Zoo, Animal, Elephant
    ])
    return db
Example #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
Example #6
0
def db():
    app = App(__name__)
    db = DAL(app, config=sdict(uri='sqlite://dal.db'))
    db.define_models([
        Stuff, Person, Thing, Feature, Price, Doctor, Patient, Appointment,
        House, Mouse, NeedSplit, Zoo, Animal, Elephant
    ])
    return db
Example #7
0
def db():
    app = App(__name__)
    db = DAL(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 = DAL(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 #9
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 #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
Example #11
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
Example #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
Example #13
0
from weppy import response
from weppy import sdict
from weppy.cache import DiskCache

from apiv2_frodo import id_url
from apiv2_frodo import isbn_url
from apiv2_frodo import get_info as get_info_byurl

from apiv2 import get_info as get_info_byid
from search import search_pc

from const import const

app = App(__name__)

app.config.logging.logfile = sdict(level="debug", max_size=100 * 1024 * 1024)

cache = Cache(disk=DiskCache())
cache.clear = cache.disk.clear


def vjson(version):
    def jsonresp(func):
        @functools.wraps(func)
        def dumpjson(*args, **kwargs):
            response.headers[
                'Content-Type'] = 'application/json; charset=utf-8'
            obj = func(*args, **kwargs)
            obj['version'] = version
            return json.dumps(obj, ensure_ascii=False).encode('utf-8')
Example #14
0
def _parse(accepted_set, params):
    rv = sdict()
    for key in accepted_set & set(params):
        rv[key] = params[key]
    return rv
Example #15
0
def test_computations(db):
    row = sdict(price=12.95, quantity=3)
    rv = db.Stuff.total.compute(row)
    assert rv == 12.95 * 3
Example #16
0
def db():
    app = App(__name__)
    db = DAL(app, config=sdict(uri='sqlite:memory'))
    auth = Auth(app, db, usermodel=User)
    db.define_models(Thing)
    return db
Example #17
0
def test_computations(db):
    row = sdict(price=12.95, quantity=3)
    rv = db.Stuff.total.compute(row)
    assert rv == 12.95*3
Example #18
0
 def __init__(
         self,
         app,
         name,
         import_name,
         model,
         serializer=None,
         parser=None,
         enabled_methods=['index', 'create', 'read', 'update', 'delete'],
         disabled_methods=[],
         list_envelope='data',
         single_envelope=None,
         use_envelope_on_parsing=False,
         url_prefix=None,
         hostname=None,
         pipeline=[]):
     self._fetcher_method = self._get_dbset
     self._select_method = self._get_row
     self._after_parse = self._after_parse_params
     self.error_404 = self.build_error_404
     self.error_422 = self.build_error_422
     add_service_pipe = True
     super_pipeline = list(pipeline)
     for pipe in super_pipeline:
         if isinstance(pipe, ServicePipe):
             add_service_pipe = False
             break
     if add_service_pipe:
         super_pipeline.insert(0, ServicePipe('json'))
     super(RESTModule, self).__init__(app,
                                      name,
                                      import_name,
                                      url_prefix=url_prefix,
                                      hostname=hostname,
                                      pipeline=super_pipeline)
     self.ext = self.app.ext.REST
     self._pagination = sdict()
     for key in ('page_param', 'pagesize_param', 'min_pagesize',
                 'max_pagesize', 'default_pagesize'):
         self._pagination[key] = self.ext.config[key]
     self._path_base = self.ext.config.base_path
     self._path_rid = self.ext.config.base_id_path
     self._serializer_class = serializer or \
         self.ext.config.default_serializer
     self._parser_class = parser or self.ext.config.default_parser
     self._parsing_params_kwargs = {}
     self.model = model
     self.serializer = self._serializer_class(self.model)
     self.parser = self._parser_class(self.model)
     self.enabled_methods = enabled_methods
     self.disabled_methods = disabled_methods
     self.list_envelope = list_envelope
     self.use_envelope_on_parsing = use_envelope_on_parsing
     self.single_envelope = single_envelope
     self.index_pipeline = [SetFetcher(self)]
     self.create_pipeline = []
     self.read_pipeline = [SetFetcher(self), RecordFetcher(self)]
     self.update_pipeline = [SetFetcher(self)]
     self.delete_pipeline = [SetFetcher(self)]
     self.init()
     self._after_initialize()
Example #19
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
Example #20
0
def test_user_no_assign_level():
    app = App(__name__)
    app.config.logging.pytest = sdict()
    result = _call_create_logger(app)
    assert result.handlers[-1].level == logging.WARNING
Example #21
0
def test_user_assign_valid_level():
    app = App(__name__)
    app.config.logging.pytest = sdict(level='info')
    result = _call_create_logger(app)
    assert result.handlers[-1].level == logging.INFO