commit:     f255d5faa7fea2e47cbab42898b3918062252efd
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Sun Nov  2 23:50:23 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Mon Nov 17 23:42:41 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=f255d5fa

Adds Protection tests to external test suite

tests/dtest.py: Removes WebappConfig.protect from doctest listing
tests/external.py: Adds tests for Protection class
protect.py: Removes doctests

---
 WebappConfig/protect.py        | 80 ------------------------------------------
 WebappConfig/tests/dtest.py    |  2 --
 WebappConfig/tests/external.py | 55 +++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/WebappConfig/protect.py b/WebappConfig/protect.py
index 4a24d55..6055d17 100644
--- a/WebappConfig/protect.py
+++ b/WebappConfig/protect.py
@@ -64,25 +64,6 @@ class Protection:
         Inputs:
           destination -  the directory that the file is being installed into
           filename    - the original name of the file
-
-        Let's test the code on some examples:
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        >>> a = Protection('','horde','3.0.5','portage')
-        >>> a.get_protectedname(here + '/tests/testfiles/protect/empty',
-        ...                     'test')#doctest: +ELLIPSIS
-        '.../tests/testfiles/protect/empty//._cfg0000_test'
-
-        >>> a.get_protectedname(here + '/tests/testfiles/protect/simple',
-        ...                     'test')#doctest: +ELLIPSIS
-        '.../tests/testfiles/protect/simple//._cfg0001_test'
-
-        >>> a.get_protectedname(here + '/tests/testfiles/protect/complex',
-        ...                     'test')#doctest: +ELLIPSIS
-        '.../tests/testfiles/protect/complex//._cfg0801_test'
-
         '''
 
         my_file    = os.path.basename(filename)
@@ -117,30 +98,6 @@ class Protection:
         Traverses the path of parent directories for the
         given install dir and checks if any matches the list
         of config protected files.
-
-        >>> a = Protection('','horde','3.0.5','portage')
-
-        Add a virtual config protected directory:
-
-        >>> a.config_protect += ' /my/strange/htdocs/'
-        >>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x')
-        True
-        >>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x/')
-        True
-        >>> a.config_protect += ' /my/strange/htdocs'
-        >>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x')
-        True
-        >>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x/')
-        True
-
-        >>> a.config_protect += ' bad_user /my/strange/htdocs'
-        >>> a.dirisconfigprotected('/my/bad_user/htdocs/where/i/installed/x')
-        False
-        >>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x/')
-        True
-
-        >>> a.dirisconfigprotected('/')
-        False
         '''
 
         my_master = []
@@ -176,39 +133,6 @@ class Protection:
     def how_to_update(self, dirs):
         '''
         Instruct the user how to update the application.
-
-        >>> OUT.color_off()
-        >>> a = Protection('','horde','3.0.5','portage')
-
-        >>> a.how_to_update(['/my/strange/htdocs/where/i/installed/x'])
-        * One or more files have been config protected
-        * To complete your install, you need to run the following command(s):
-        * 
-        * CONFIG_PROTECT="/my/strange/htdocs/where/i/installed/x" etc-update
-        * 
-        >>> a.how_to_update(['/a/','/c/'])
-        * One or more files have been config protected
-        * To complete your install, you need to run the following command(s):
-        * 
-        * CONFIG_PROTECT="/a/" etc-update
-        * CONFIG_PROTECT="/c/" etc-update
-        * 
-        >>> a.how_to_update(['/a//test3','/a//test3/abc', '/c/'])
-        * One or more files have been config protected
-        * To complete your install, you need to run the following command(s):
-        * 
-        * CONFIG_PROTECT="/a//test3" etc-update
-        * CONFIG_PROTECT="/c/" etc-update
-        * 
-
-        Add a virtual config protected directory:
-
-        >>> a.config_protect += ' /my/strange/htdocs/'
-        >>> a.how_to_update(['/my/strange/htdocs/where/i/installed/x'])
-        * One or more files have been config protected
-        * To complete your install, you need to run the following command(s):
-        * 
-        * etc-update
         '''
         my_command = self.update_command
 
@@ -237,7 +161,3 @@ class Protection:
         OUT.warn('One or more files have been config protected\nTo comple'
                  'te your install, you need to run the following 
command(s):\n\n'
                  + my_command_list)
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

diff --git a/WebappConfig/tests/dtest.py b/WebappConfig/tests/dtest.py
index bfb82fa..6931dd8 100644
--- a/WebappConfig/tests/dtest.py
+++ b/WebappConfig/tests/dtest.py
@@ -8,12 +8,10 @@
 
 import unittest, doctest, sys
 
-import WebappConfig.protect
 import WebappConfig.worker
 
 def test_suite():
     return unittest.TestSuite((
-        doctest.DocTestSuite(WebappConfig.protect),
         doctest.DocTestSuite(WebappConfig.worker),
         ))
 

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
index 0919d80..3216dd5 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -29,6 +29,7 @@ from  WebappConfig.debug     import OUT
 from  WebappConfig.dotconfig import DotConfig
 from  WebappConfig.ebuild    import Ebuild
 from  WebappConfig.filetype  import FileType
+from  WebappConfig.protect   import Protection
 from  WebappConfig.server    import Basic
 from  warnings               import filterwarnings, resetwarnings
 
@@ -367,7 +368,61 @@ class FileTypeTest(unittest.TestCase):
         self.assertEqual(types.dirtype('foo.txt'), 'default-owned')
 
 
+class ProtectTest(unittest.TestCase):
+    def test_getprotectedname(self):
+        pro = Protection('', 'horde', '3.0.5', 'portage')
+        self.assertEqual(pro.get_protectedname('/'.join((HERE,
+                                                         'testfiles',
+                                                         'protect',
+                                                         'empty')),
+                                               'test'),
+                        '/'.join((HERE, 'testfiles', 'protect', 'empty',
+                                  '/._cfg0000_test')))
+
+    def test_dirisconfprotected(self):
+        pro = Protection('', 'horde', '3.0.5', 'portage')
+        strange_htdocs = '/'.join(('/my', 'strange', 'htdocs'))
+        pro.config_protect += ' ' + strange_htdocs
+
+        self.assertTrue(pro.dirisconfigprotected(strange_htdocs))
+        self.assertTrue(pro.dirisconfigprotected('/'.join((strange_htdocs,
+                                                           'where', 'i',
+                                                           'installed', 'x'))))
+        self.assertTrue(pro.dirisconfigprotected('/'.join((strange_htdocs,
+                                                           'where', 'i',
+                                                           'installed', 
'x/'))))
+
+        pro.config_protect += ' bad_user' + strange_htdocs
+        self.assertFalse(pro.dirisconfigprotected('/'.join(('/my', 'bad_user',
+                                                            'htdocs', 'where',
+                                                            'i', 'installed',
+                                                            'x'))))
+        self.assertFalse(pro.dirisconfigprotected('/'))
+
+
+    def test_how_to_update(self):
+        OUT.color_off()
+        pro = Protection('', 'horde', '3.0.5', 'portage')
+        strange_htdocs = '/'.join(('/my', 'strange', 'htdocs', 'where', 'i',
+                                   'installed', 'x'))
+        pro.how_to_update([strange_htdocs])
+        output = sys.stdout.getvalue().split('\n')
+
+        self.assertEqual(output[3], '* CONFIG_PROTECT="' + strange_htdocs +
+                                    '" etc-update')
+
+        # Adding a virtual config protected directory:
+        i = strange_htdocs.replace('/where/i/instaled/x', '')
+        pro.config_protect += ' ' + i
+
+        pro.how_to_update([strange_htdocs])
+        output = sys.stdout.getvalue().split('\n')
+
+        self.assertEqual(output[8], '* etc-update')
+        
+
 if __name__ == '__main__':
     filterwarnings('ignore')
     unittest.main(module=__name__, buffer=True)
+    
     resetwarnings()

Reply via email to