From 89db1c03543d505d761cd9436220d1acfae23bac Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Wed, 24 Feb 2016 09:14:17 -0300 Subject: [PATCH] Move e melhora listify de legacy p utils --- legacy/scripts/scrap_original_forms.py | 3 ++- legacy/scripts/utils.py | 6 ----- sapl/settings.py | 32 +++++++++++++------------- sapl/test_general.py | 4 +++- sapl/test_utils.py | 11 ++++++++- sapl/utils.py | 22 ++++++++---------- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/legacy/scripts/scrap_original_forms.py b/legacy/scripts/scrap_original_forms.py index f1a47c87f..767f2b204 100644 --- a/legacy/scripts/scrap_original_forms.py +++ b/legacy/scripts/scrap_original_forms.py @@ -10,7 +10,8 @@ from bs4.element import NavigableString, Tag from django.apps.config import AppConfig from legacy.migration import appconfs, get_renames -from legacy.scripts.utils import getsourcelines, listify +from legacy.scripts.utils import getsourcelines +from sapl.utils import listify # to prevent removal by automatic organize imports on this file assert appconfs diff --git a/legacy/scripts/utils.py b/legacy/scripts/utils.py index cc9ba1181..6e2e03723 100644 --- a/legacy/scripts/utils.py +++ b/legacy/scripts/utils.py @@ -1,12 +1,6 @@ import inspect -def listify(function): - def f(*args, **kwargs): - return list(function(*args, **kwargs)) - return f - - def getsourcelines(model): return [line.rstrip('\n').decode('utf-8') for line in inspect.getsourcelines(model)[0]] diff --git a/sapl/settings.py b/sapl/settings.py index 92a03d278..866354e43 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -28,7 +28,19 @@ DEBUG = True ALLOWED_HOSTS = ['*'] -# Application definition +# SAPL business apps in dependency order +SAPL_APPS = ( + 'base', + 'parlamentares', + 'comissoes', + 'materia', + 'norma', + 'sessao', + 'lexml', + 'painel', + 'protocoloadm', + 'compilacao', +) INSTALLED_APPS = ( 'django_admin_bootstrapped', # must come before django.contrib.admin @@ -39,27 +51,15 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', - 'rest_framework', - - # sapl modules - 'base', - 'parlamentares', - 'comissoes', - 'compilacao', - 'sessao', - 'materia', - 'norma', - 'lexml', - 'painel', - 'protocoloadm', - # more 'django_extensions', 'djangobower', 'bootstrap3', # basically for django_admin_bootstrapped 'crispy_forms', 'sass_processor', -) + 'rest_framework', + +) + SAPL_APPS if DEBUG: INSTALLED_APPS += ('debug_toolbar',) diff --git a/sapl/test_general.py b/sapl/test_general.py index 5c2e0bf9b..a093b53ea 100644 --- a/sapl/test_general.py +++ b/sapl/test_general.py @@ -1,7 +1,8 @@ import pytest +from django.apps import apps from model_mommy import mommy -from .utils import sapl_appconfs +from .settings import SAPL_APPS pytestmark = pytest.mark.django_db @@ -9,6 +10,7 @@ pytestmark = pytest.mark.django_db def test_str_sanity(): # this simply a sanity check # __str__ semantics is not considered and should be tested separetely + sapl_appconfs = [apps.get_app_config(n) for n in SAPL_APPS] for app in sapl_appconfs: for model in app.get_models(): obj = mommy.prepare(model) diff --git a/sapl/test_utils.py b/sapl/test_utils.py index 5e4e59b81..d76d19f9d 100644 --- a/sapl/test_utils.py +++ b/sapl/test_utils.py @@ -1,6 +1,6 @@ from pytest import mark -from .utils import make_choices +from .utils import listify, make_choices @mark.parametrize("choice_pairs, result", [ @@ -11,3 +11,12 @@ from .utils import make_choices ]) def test_make_choices(choice_pairs, result): assert list(make_choices(*choice_pairs)) == result + + +def test_listify(): + + @listify + def gen(): + yield 1 + yield 2 + assert [1, 2] == gen() diff --git a/sapl/utils.py b/sapl/utils.py index 0d8dfa904..d86c59616 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,20 +1,9 @@ +from functools import wraps + from django.apps import apps from django.contrib import admin from django.utils.translation import ugettext_lazy as _ -# SAPL business apps in dependency order -# (each entry depends only on previous ones) -sapl_appconfs = [apps.get_app_config(n) for n in [ - 'parlamentares', - 'comissoes', - 'materia', - 'norma', - 'sessao', - 'lexml', - 'protocoloadm', - 'compilacao', -]] - def register_all_models_in_admin(module_name): appname = module_name.split('.')[0] @@ -58,3 +47,10 @@ def make_choices(*choice_pairs): yield key YES_NO_CHOICES = [(True, _('Sim')), (False, _('Não'))] + + +def listify(function): + @wraps(function) + def f(*args, **kwargs): + return list(function(*args, **kwargs)) + return f