From 8ed02a577e1535b1abda6d8ca243780ec75f0320 Mon Sep 17 00:00:00 2001 From: kk Date: Fri, 6 Sep 2019 12:19:41 +0300 Subject: [PATCH] move lib/forms to core/forms --- {lib => core}/forms.py | 2 +- lib/app/application.py | 6 ++-- services/web/apps/ip/tools/views.py | 4 +-- services/web/apps/main/checkpoint/views.py | 4 +-- tests/test_forms.py | 37 ++++++++++++++++++++++ 5 files changed, 45 insertions(+), 8 deletions(-) rename {lib => core}/forms.py (98%) create mode 100644 tests/test_forms.py diff --git a/lib/forms.py b/core/forms.py similarity index 98% rename from lib/forms.py rename to core/forms.py index ca6bd747c1..4ab3ac9ae6 100644 --- a/lib/forms.py +++ b/core/forms.py @@ -43,7 +43,7 @@ class NOCForm(forms.Form): Form wrapper returning NOCBoundField items """ - class Media: + class Media(object): css = {"all": ["/ui/pkg/django-media/admin/css/forms.css"]} def __init__(self, *args, **kwargs): diff --git a/lib/app/application.py b/lib/app/application.py index 6671d8f723..f80841fe32 100644 --- a/lib/app/application.py +++ b/lib/app/application.py @@ -35,7 +35,7 @@ import six import jinja2 # NOC modules -from noc.lib.forms import NOCForm +from noc.core.forms import NOCForm from noc import settings from noc.sa.interfaces.base import DictParameter from noc.core.cache.base import cache @@ -104,8 +104,8 @@ class ApplicationBase(type): Application metaclass. Registers application class to site """ - def __new__(cls, name, bases, attrs): - m = type.__new__(cls, name, bases, attrs) + def __new__(mcs, name, bases, attrs): + m = type.__new__(mcs, name, bases, attrs) for name in attrs: m.add_to_class(name, attrs[name]) if "apps" in m.__module__: diff --git a/services/web/apps/ip/tools/views.py b/services/web/apps/ip/tools/views.py index b649615c8c..65ff5d98f7 100644 --- a/services/web/apps/ip/tools/views.py +++ b/services/web/apps/ip/tools/views.py @@ -2,7 +2,7 @@ # --------------------------------------------------------------------- # Tools # --------------------------------------------------------------------- -# Copyright (C) 2007-2018 The NOC Project +# Copyright (C) 2007-2019 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -20,7 +20,7 @@ from noc.core.ip import IP, IPv4 from noc.ip.models.address import Address from noc.ip.models.prefix import Prefix from noc.ip.models.vrf import VRF -from noc.lib.forms import NOCForm +from noc.core.forms import NOCForm from noc.config import config from noc.core.translation import ugettext as _ diff --git a/services/web/apps/main/checkpoint/views.py b/services/web/apps/main/checkpoint/views.py index 30853d98a9..90ede1917b 100644 --- a/services/web/apps/main/checkpoint/views.py +++ b/services/web/apps/main/checkpoint/views.py @@ -2,7 +2,7 @@ # --------------------------------------------------------------------- # Checkpoint manager # --------------------------------------------------------------------- -# Copyright (C) 2007-2018 The NOC Project +# Copyright (C) 2007-2019 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -14,7 +14,7 @@ from django import forms # NOC modules from noc.lib.app.application import Application, view, HasPerm -from noc.lib.forms import NOCForm +from noc.core.forms import NOCForm from noc.main.models.checkpoint import Checkpoint from noc.core.translation import ugettext as _ diff --git a/tests/test_forms.py b/tests/test_forms.py new file mode 100644 index 0000000000..a796820b65 --- /dev/null +++ b/tests/test_forms.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# ---------------------------------------------------------------------- +# noc.core.forms unittests +# ---------------------------------------------------------------------- +# Copyright (C) 2007-2019 The NOC Project +# See LICENSE for details +# ---------------------------------------------------------------------- + +# Third-party modules +import pytest +from django import forms +from django.core.wsgi import get_wsgi_application + +# NOC modules +from noc.core.forms import NOCForm + +app = get_wsgi_application() + + +class TestF(NOCForm): + charf = forms.CharField(required=True) + intf = forms.IntegerField(min_value=18) + + +@pytest.mark.parametrize( + "charf, intf, expected", + [ + ("field1", 18, True), + ("field2", 17, False), + ("field3", None, False), + ("", 18, False), + (None, 18, False), + ], +) +def test_f(charf, intf, expected): + f = TestF(data={"charf": charf, "intf": intf}) + assert f.is_valid() is expected -- GitLab