Browse Source

Move e melhora listify de legacy p utils

pull/237/head
Marcio Mazza 9 years ago
parent
commit
89db1c0354
  1. 3
      legacy/scripts/scrap_original_forms.py
  2. 6
      legacy/scripts/utils.py
  3. 32
      sapl/settings.py
  4. 4
      sapl/test_general.py
  5. 11
      sapl/test_utils.py
  6. 22
      sapl/utils.py

3
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

6
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]]

32
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',)

4
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)

11
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()

22
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

Loading…
Cancel
Save