File: test_inheritance.py

package info (click to toggle)
wtforms-alchemy 0.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 492 kB
  • sloc: python: 3,955; makefile: 119; sh: 11
file content (40 lines) | stat: -rw-r--r-- 1,069 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from wtforms import Form
from wtforms_test import FormTestCase

from wtforms_alchemy import model_form_factory, ModelForm


class TestInheritance(FormTestCase):
    class Base(Form):
        @classmethod
        def get_session(self):
            return "TestSession"

    def test_default_base(self):
        assert ModelForm.get_session is None

    def test_custom_base_without_session(self):
        cls = model_form_factory(Form)
        assert cls.get_session is None

    def test_custom_base_with_session(self):
        cls = model_form_factory(self.Base)
        assert cls.get_session() == "TestSession"

    def test_inherit_with_new_session(self):
        cls = model_form_factory(self.Base)

        class Sub(cls):
            @classmethod
            def get_session(self):
                return "SubTestSession"

        assert Sub.get_session() == "SubTestSession"

    def test_inherit_without_new_session(self):
        cls = model_form_factory(self.Base)

        class Sub(cls):
            pass

        assert Sub.get_session() == "TestSession"