Commits

Andriy Kornatskyy  committed 18efa63

Added test cases for ErrorMixin.

  • Participants
  • Parent commits 3e1d5be

Comments (0)

Files changed (1)

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

 
 import unittest
 
+from wheezy.validation.mixin import ErrorsMixin
 from wheezy.validation.mixin import ValidationMixin
 
 
-class MyService(ValidationMixin):
+class MyServiceA(ErrorsMixin):
+
+    def __init__(self):
+        self.errors = {}
+
+
+class MyServiceB(ValidationMixin):
 
     def __init__(self):
         self.errors = {}
         self.translations = {'validation': None}
 
 
-class ValidationMixinTestCase(unittest.TestCase):
+class ErrorMixinTestCase(unittest.TestCase):
 
     def test_errors(self):
         """ Ensure error summary.
         """
-        s = MyService()
+        s = MyServiceA()
         s.error('error-message-1')
         assert {'__ERROR__': ['error-message-1']} == s.errors
 
             'error-message-1',
             'error-message-2'])] == sorted(s.errors.items())
 
+        s.error('error-message-3', 'name')
+        assert ['__ERROR__', 'name'] == sorted(s.errors.keys())
+
+
+class ValidationMixinTestCase(unittest.TestCase):
+
+    def test_errors(self):
+        """ Ensure error summary.
+        """
+        s = MyServiceB()
+        s.error('error-message-1')
+        assert {'__ERROR__': ['error-message-1']} == s.errors
+
+        s.error('error-message-2')
+        assert [('__ERROR__', [
+            'error-message-1',
+            'error-message-2'])] == sorted(s.errors.items())
+
+        s.error('error-message-3', 'name')
+        assert ['__ERROR__', 'name'] == sorted(s.errors.keys())
+
     def test_validate(self):
         """ Ensure errors is updated by validator.
         """
             'name': [required]
         })
         user = {'name': 'john'}
-        s = MyService()
+        s = MyServiceB()
         assert s.validate(user, v)
         assert not s.errors