Commits

Andriy Kornatskyy  committed 6f72a24

Refactoring principal module tests.

  • Participants
  • Parent commits 23acff3

Comments (0)

Files changed (2)

File src/wheezy/security/principal.py

         self.extra = extra
 
     def dump(self):
-        """
-            >>> p = Principal()
-            >>> s = p.dump()
-            >>> assert 3 == len(s)
-            >>> s
-            '\\x1f\\x1f\\x1f'
-            >>> p = Principal(id='79053',
-            ...         roles=('a', 'b'),
-            ...         alias='John',
-            ...         extra='anything')
-            >>> p.dump()
-            '79053\\x1fa;b\\x1fJohn\\x1fanything'
+        """ Dump principal object.
         """
         return '\x1f'.join([
             self.id,
 
     @classmethod
     def load(cls, s):
-        """
-            >>> p = Principal.load('\x1f\x1f\x1f')
-            >>> assert p
-            >>> p = Principal.load('79053\\x1fa;b\x1fJohn\\x1fanything')
-            >>> p.id
-            '79053'
-            >>> p.roles
-            ('a', 'b')
-            >>> p.alias
-            'John'
-            >>> p.extra
-            'anything'
+        """ Load principal object from string.
         """
         id, roles, alias, extra = s.split('\x1f', 3)
         return cls(id, tuple(roles.split(';')), alias, extra)

File src/wheezy/security/tests/test_principal.py

+
+""" Unit tests for ``wheezy.security.principal``.
+"""
+
+import unittest
+
+
+class PrincipalTestCase(unittest.TestCase):
+
+    def test_dump(self):
+        """ Ensure the principal object is dumped correctly
+            with delimiters.
+        """
+        from wheezy.security.principal import Principal
+        p = Principal()
+        s = p.dump()
+        assert 3 == len(s)
+        assert '\x1f\x1f\x1f' == s
+
+        p = Principal(id='79053', roles=('a', 'b'),
+                      alias='John',
+                      extra='anything')
+        s = p.dump()
+        assert '79053\x1fa;b\x1fJohn\x1fanything' == s
+
+    def test_load(self):
+        """
+        """
+        from wheezy.security.principal import Principal
+        p = Principal.load('\x1f\x1f\x1f')
+        assert p
+        assert '' == p.id
+        assert ('', ) == p.roles
+        assert '' == p.alias
+        assert '' == p.extra
+
+        p = Principal.load('79053\x1fa;b\x1fJohn\x1fanything')
+        assert '79053' == p.id
+        assert ('a', 'b') == p.roles
+        assert 'John' == p.alias
+        assert 'anything' == p.extra