1. Andriy Kornatskyy
  2. wheezy.validation

Commits

Andriy Kornatskyy  committed 3f40b47

Added test case for checker model.

  • Participants
  • Parent commits 8634229
  • Branches default

Comments (0)

Files changed (2)

File src/wheezy/validation/checker.py

View file
  • Ignore whitespace
 # region: internal details
 
 class Model(dict):
+    """ Simulate plain python class, read-only dictionary access
+        through attributes.
+    """
     __slots__ = ()
 
-    def __setattr__(self, key, value):
-        return super(Model, self).__setitem__(key, value)
-
     def __getattr__(self, name):
         try:
             return super(Model, self).__getitem__(name)

File src/wheezy/validation/tests/test_checker.py

View file
  • Ignore whitespace
                 'Required to be a minimum of 6 characters in length.',
                 'Required to be a valid email address.'
                 ] == self.c.errors(email='')
+
+
+class ModelTestCase(unittest.TestCase):
+
+    def test_items(self):
+        from wheezy.validation.checker import Model
+        m = Model(a=1, b=2)
+        assert [('a', 1), ('b', 2)] == sorted(m.items())
+        assert 1 == m.a
+        assert 2 == m.b
+        self.assertRaises(AttributeError, lambda: m.c)