mirror of
https://github.com/pypiserver/pypiserver
synced 2024-11-09 16:45:51 +01:00
Merge pull request #128 from mplanchard/mp_fixpaste
FIX #124: Convert forgotten attr-access-->dict-access & TCs for paste-factory
This commit is contained in:
commit
5d2e56a529
@ -131,13 +131,13 @@ def app(**kwds):
|
||||
def str2bool(s, default):
|
||||
if s is not None and s != '':
|
||||
return s.lower() not in ("no", "off", "0", "false")
|
||||
return default
|
||||
return default
|
||||
|
||||
def paste_app_factory(global_config, **local_conf):
|
||||
import os
|
||||
|
||||
def upd_bool_attr_from_dict_str_item(conf, attr, sdict):
|
||||
setattr(conf, attr, str2bool(sdict.pop(attr, None), getattr(conf, attr)))
|
||||
def upd_conf_with_bool_item(conf, attr, sdict):
|
||||
conf[attr] = str2bool(sdict.pop(attr, None), conf[attr])
|
||||
|
||||
def _make_root(root):
|
||||
root = root.strip()
|
||||
@ -149,12 +149,12 @@ def paste_app_factory(global_config, **local_conf):
|
||||
|
||||
root = local_conf.get("root")
|
||||
if root:
|
||||
c.root = [_make_root(x) for x in root.split("\n") if x.strip()]
|
||||
c['root'] = [_make_root(x) for x in root.split("\n") if x.strip()]
|
||||
|
||||
upd_bool_attr_from_dict_str_item(c, 'redirect_to_fallback', local_conf)
|
||||
upd_bool_attr_from_dict_str_item(c, 'overwrite', local_conf)
|
||||
upd_conf_with_bool_item(c, 'redirect_to_fallback', local_conf)
|
||||
upd_conf_with_bool_item(c, 'overwrite', local_conf)
|
||||
|
||||
return app(**vars(c))
|
||||
return app(**c)
|
||||
|
||||
def _logwrite(logger, level, msg):
|
||||
if msg:
|
||||
|
39
tests/test_init.py
Normal file
39
tests/test_init.py
Normal file
@ -0,0 +1,39 @@
|
||||
"""
|
||||
Test module for . . .
|
||||
"""
|
||||
# Standard library imports
|
||||
from __future__ import (absolute_import, division,
|
||||
print_function, unicode_literals)
|
||||
import logging
|
||||
from os.path import abspath, dirname, join, realpath, relpath
|
||||
from sys import path
|
||||
|
||||
# Third party imports
|
||||
import pytest
|
||||
|
||||
# Local imports
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
test_dir = realpath(dirname(__file__))
|
||||
src_dir = abspath(join(test_dir, '..'))
|
||||
path.append(src_dir)
|
||||
print(path)
|
||||
|
||||
import pypiserver
|
||||
|
||||
|
||||
@pytest.mark.parametrize('conf_options', [
|
||||
{},
|
||||
{'root': '~/stable_packages'},
|
||||
{'root': '~/unstable_packages', 'authenticated': 'upload',
|
||||
'passwords': '~/htpasswd'}
|
||||
])
|
||||
def test_paste_app_factory(conf_options, monkeypatch):
|
||||
"""Test the paste_app_factory method"""
|
||||
monkeypatch.setattr('pypiserver.core.configure',
|
||||
lambda **x: (x, [x.keys()]))
|
||||
pypiserver.paste_app_factory({}, **conf_options)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user