1
0
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:
Kostis Anagnostopoulos 2016-03-22 09:56:52 +01:00
commit 5d2e56a529
2 changed files with 46 additions and 7 deletions

@ -131,13 +131,13 @@ def app(**kwds):
def str2bool(s, default): def str2bool(s, default):
if s is not None and s != '': if s is not None and s != '':
return s.lower() not in ("no", "off", "0", "false") return s.lower() not in ("no", "off", "0", "false")
return default return default
def paste_app_factory(global_config, **local_conf): def paste_app_factory(global_config, **local_conf):
import os import os
def upd_bool_attr_from_dict_str_item(conf, attr, sdict): def upd_conf_with_bool_item(conf, attr, sdict):
setattr(conf, attr, str2bool(sdict.pop(attr, None), getattr(conf, attr))) conf[attr] = str2bool(sdict.pop(attr, None), conf[attr])
def _make_root(root): def _make_root(root):
root = root.strip() root = root.strip()
@ -149,12 +149,12 @@ def paste_app_factory(global_config, **local_conf):
root = local_conf.get("root") root = local_conf.get("root")
if 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_conf_with_bool_item(c, 'redirect_to_fallback', local_conf)
upd_bool_attr_from_dict_str_item(c, 'overwrite', local_conf) upd_conf_with_bool_item(c, 'overwrite', local_conf)
return app(**vars(c)) return app(**c)
def _logwrite(logger, level, msg): def _logwrite(logger, level, msg):
if msg: if msg:

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)