Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_generate_password_hash_default():
from muffin.utils import generate_password_hash, check_password_hash
password = '#secret$'
password_hash = generate_password_hash(password, digestmod='sha1', salt_length=8)
assert password_hash.startswith('sha1')
assert len(password_hash.split('$')[1]) == 8
assert len(password_hash.split('$')[2]) == 40
assert check_password_hash(password, password_hash)
def test_generate_password_hash_sha256():
from muffin.utils import generate_password_hash, check_password_hash
password = '#secret$'
password_hash = generate_password_hash(password, digestmod='sha256', salt_length=20)
assert password_hash.startswith('sha256')
assert len(password_hash.split('$')[1]) == 20
assert len(password_hash.split('$')[2]) == 64
assert check_password_hash(password, password_hash)
def test_generate_password_hash_sha256():
from muffin.utils import generate_password_hash, check_password_hash
password = '#secret$'
password_hash = generate_password_hash(password, digestmod='sha256', salt_length=20)
assert password_hash.startswith('sha256')
assert len(password_hash.split('$')[1]) == 20
assert len(password_hash.split('$')[2]) == 64
assert check_password_hash(password, password_hash)
def test_generate_password_hash_default():
from muffin.utils import generate_password_hash, check_password_hash
password = '#secret$'
password_hash = generate_password_hash(password, digestmod='sha1', salt_length=8)
assert password_hash.startswith('sha1')
assert len(password_hash.split('$')[1]) == 8
assert len(password_hash.split('$')[2]) == 40
assert check_password_hash(password, password_hash)
async def test_static(aiohttp_client):
app = muffin.Application('test', STATIC_FOLDERS=[
'tests/static1',
'tests/static2',
])
client = await aiohttp_client(app)
resp = await client.get('/static/file1')
assert resp.status == 200
body = await resp.read()
assert body == b'content1\n'
resp = await client.get('/static/file2')
assert resp.status == 200
body = await resp.read()
assert body == b'content2\n'
with pytest.raises(PluginException):
BasePlugin()
class Plugin(BasePlugin):
name = 'plugin'
defaults = {
'debug': True
}
pl1 = Plugin(test=42)
pl2 = Plugin(test=24)
assert pl1 is pl2
assert pl1.cfg.test == 42
app = muffin.Application(__name__)
app.install(pl1)
assert pl1.name in app.ps
async def test_custom_methods(aiohttp_client):
app = muffin.Application('test')
@app.register('/caldav', methods='PROPFIND')
def propfind(request):
return b'PROPFIND'
client = await aiohttp_client(app)
resp = await client.request('PROPFIND', '/caldav')
assert resp.status == 200
text = await resp.text()
assert text == 'PROPFIND'
resp.close()
async def test_base(aiohttp_client):
app = muffin.Application('admin')
app.install('muffin_jinja2')
admin = app.install('muffin_admin')
@app.register
class Test(admin.Handler):
columns = 'id', 'name'
def load_one(self, request):
resource = request.match_info.get(self.name)
if resource:
return self.collection[int(resource) - 1]
def load_many(self, request):
return [
muffin.utils.Struct(id=1, name='test1'),
async def test_handler_func(aiohttp_client):
"""Test convert functions to Muffin's Handlers."""
app = muffin.Application('test')
@app.register('/test1')
def test1(request):
return 'test1 passed'
assert 'test1' in app.router
@app.register('/test2', methods='put')
def test2(request):
return 'test2 passed'
@app.register('/test3', methods=('get', 'post'))
def test2(request):
return 'test3 passed'
@app.register('/test4', methods='*')
async def test_responses(aiohttp_client):
app = muffin.Application('test')
@app.register('/none')
def none(request):
return None
@app.register('/str')
def str(request):
return 'str'
@app.register('/bytes')
def bytes(request):
return b'bytes'
@app.register('/json')
def json(request):
return {'test': 'passed'}