diff --git a/lib/forms.py b/core/forms.py similarity index 98% rename from lib/forms.py rename to core/forms.py index ca6bd747c19677691660957187f3068917bfd59c..4ab3ac9ae685aecfb387f1a734cc96132d725108 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 6671d8f723af137428bdd4dcb8ee2cce4286e166..f80841fe3261f1329931c2be0f0c45dff305f1f3 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 b649615c8cf4869b5891ec63a79bde16285bd97c..65ff5d98f731b055f7966ac98feeee513c77a4ee 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 30853d98a9a992fae6e77733ecfb8b960fc04371..90ede1917b1ea02b7cb6f7f4386ab79d967cea10 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 0000000000000000000000000000000000000000..a796820b6502f3f83b87df8055fcabf9530a1f53 --- /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