Exemplo n.º 1
0
Arquivo: test.py Projeto: 5l1v3r1/slim
def new_app(permission=ALL_PERMISSION,
            log_level=logging.WARN,
            **kwargs) -> Application:
    """
    Get application instance
    :param permission:
    :param log_level:
    :param kwargs:
    :return:
    """
    app = Application(cookies_secret=b'123456',
                      permission=permission,
                      log_level=log_level,
                      **kwargs)
    return app
Exemplo n.º 2
0
import time

import pytest
from slim.support.peewee import PeeweeView
from peewee import *
from slim import Application, ALL_PERMISSION
from slim.utils import get_ioloop
from slim.tools.test import make_mocked_view_instance


pytestmark = [pytest.mark.asyncio]
app = Application(cookies_secret=b'123456', permission=ALL_PERMISSION)
db = SqliteDatabase(":memory:")


class ATestModel(Model):
    info = BlobField()

    class Meta:
        table_name = 'test'
        database = db


db.create_tables([ATestModel])


@app.route.view('test')
class ATestView(PeeweeView):
    LIST_PAGE_SIZE = -1

    model = ATestModel
Exemplo n.º 3
0
Arquivo: app.py Projeto: 5l1v3r1/slim
from slim import Application, CORSOptions, ALL_PERMISSION, EMPTY_PERMISSION, ApplicationDocInfo
import config

app = Application(log_level=config.DEBUG_LEVEL,
                  cookies_secret=config.COOKIE_SECRET,
                  permission=EMPTY_PERMISSION,
                  doc_enable=config.DOC_ENABLE,
                  doc_info=ApplicationDocInfo(title=config.PROJECT_NAME,
                                              description=config.DESC,
                                              version=config.VERSION),
                  cors_options=CORSOptions('*',
                                           allow_credentials=True,
                                           expose_headers="*",
                                           allow_headers="*"))
Exemplo n.º 4
0
from slim import Application, CORSOptions, ALL_PERMISSION, NO_PERMISSION
import config

app = Application(log_level=config.DEBUG,
                  cookies_secret=config.COOKIE_SECRET,
                  permission=ALL_PERMISSION,
                  cors_options=CORSOptions('*',
                                           allow_credentials=True,
                                           expose_headers="*",
                                           allow_headers="*"))
Exemplo n.º 5
0
import json

import pytest
from unittest import mock
from aiohttp.test_utils import make_mocked_request
from multidict import MultiDict

from slim.retcode import RETCODE
from slim.support.peewee import PeeweeView
from peewee import *
from slim import Application

pytestmark = [pytest.mark.asyncio]
app = Application(cookies_secret=b'123456')
db = SqliteDatabase(":memory:")


class ATestModel(Model):
    info = BlobField()

    class Meta:
        db_table = 'test'
        database = db


@app.route('test')
class ATestView(PeeweeView):
    model = ATestModel


db.create_tables([ATestModel])
import pytest
from peewee import Model, BlobField
from playhouse.postgres_ext import ArrayField

from slim import Application, ALL_PERMISSION
from slim.base.permission import Ability
from slim.base.sqlquery import SQLQueryInfo, SQL_OP
from slim.exception import InvalidParams
from slim.support.peewee import PeeweeView

pytestmark = [pytest.mark.asyncio]
app = Application(cookies_secret=b'123456')

app.permission.add(None, Ability({'*': '*'}))


class ATestModel(Model):
    name = ArrayField(BlobField)

    class Meta:
        table_name = 'topic'


@app.route.view('test1')
class ATestView(PeeweeView):
    model = ATestModel


ATestView.ability = Ability({'*': '*'})
app._prepare()
Exemplo n.º 7
0
from slim import Application, CORSOptions
from slim.base.session import MemoryHeaderKeySession
import config

app = Application(cookies_secret=config.COOKIES_SECRET,
                  session_cls=MemoryHeaderKeySession,
                  log_level=config.DEBUG_LEVEL,
                  cors_options=CORSOptions('*',
                                           allow_credentials=True,
                                           expose_headers="*",
                                           allow_headers="*"))
Exemplo n.º 8
0
    to_sign = [1, timestamp, 'test name', 'test value 中文', {'asd': '测试'}]
    value = create_signed_value(secret, to_sign)

    decode_data = decode_signed_value(secret, value)
    assert decode_data == to_sign

    # 篡改数据测试
    s = _value_decode(base64.b64decode(bytes(value, 'utf-8')))
    s[3] = 'test value'
    val_changed = str(base64.b64encode(_value_encode(s)), 'utf-8')

    decode_data = decode_signed_value(secret, val_changed)
    assert decode_data is None


app = Application(cookies_secret=secret)


class FakeRequest:
    app = app
    cookies = {}


@app.route('/')
class CookiesView(BaseView):
    pass


cookies_view = CookiesView(app, FakeRequest())

Exemplo n.º 9
0
from slim import Application, CORSOptions
from slim.base.session import MemoryHeaderKeySession
import config

app = Application(cookies_secret=config.COOKIES_SECRET,
                  session_cls=MemoryHeaderKeySession,
                  log_level=config.DEBUG_LEVEL,
                  cors_options=config.CORS_OPTIONS)
Exemplo n.º 10
0
import time

import pytest

from slim.base.permission import Ability, A
from slim.retcode import RETCODE
from slim.support.peewee import PeeweeView
from peewee import *
from slim import Application, ALL_PERMISSION, EMPTY_PERMISSION
from slim.tools.test import invoke_interface

pytestmark = [pytest.mark.asyncio]
app = Application(cookies_secret=b'123456', permission=EMPTY_PERMISSION)
db = SqliteDatabase(":memory:")


class Topic(Model):
    title = CharField(index=True, max_length=255)
    time = BigIntegerField(index=True, default=time.time)
    content = TextField()

    class Meta:
        table_name = 'topic'
        database = db


class Article(Model):
    name = CharField(index=True, max_length=255)
    content = TextField()

    class Meta:
Exemplo n.º 11
0
    to_sign = [1, timestamp, 'test name', 'test value 中文', {'asd': '测试'}]
    value = create_signed_value(secret, to_sign)

    decode_data = decode_signed_value(secret, value)
    assert decode_data == to_sign

    # 篡改数据测试
    s = _value_decode(base64.b64decode(bytes(value, 'utf-8')))
    s[3] = 'test value'
    val_changed = str(base64.b64encode(_value_encode(s)), 'utf-8')

    decode_data = decode_signed_value(secret, val_changed)
    assert decode_data is None


app = Application(cookies_secret=secret, permission=ALL_PERMISSION)


class FakeRequest:
    app = app
    cookies = {}


@app.route.view('/')
class CookiesView(BaseView):
    pass


cookies_view = CookiesView(app, FakeRequest())