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
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
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
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
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
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
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
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
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
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
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')
def _parse(accepted_set, params): rv = sdict() for key in accepted_set & set(params): rv[key] = params[key] return rv
def test_computations(db): row = sdict(price=12.95, quantity=3) rv = db.Stuff.total.compute(row) assert rv == 12.95 * 3
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
def test_computations(db): row = sdict(price=12.95, quantity=3) rv = db.Stuff.total.compute(row) assert rv == 12.95*3
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()
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
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
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