public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/webapp-config:master commit in: WebappConfig/tests/, WebappConfig/
@ 2015-06-19 19:52 Devan Franchini
  0 siblings, 0 replies; 4+ messages in thread
From: Devan Franchini @ 2015-06-19 19:52 UTC (permalink / raw
  To: gentoo-commits

commit:     bbf371a6dd55427e4a44b8566b63caa4b8507b32
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Sun Nov  2 05:56:40 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Fri Jun 19 19:48:33 2015 +0000
URL:        https://gitweb.gentoo.org/proj/webapp-config.git/commit/?id=bbf371a6

Adds DotConfig tests to external test suite

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

 WebappConfig/dotconfig.py      | 61 ------------------------------------------
 WebappConfig/tests/dtest.py    |  2 --
 WebappConfig/tests/external.py | 47 +++++++++++++++++++++++++++++---
 3 files changed, 43 insertions(+), 67 deletions(-)

diff --git a/WebappConfig/dotconfig.py b/WebappConfig/dotconfig.py
index 948fa90..0d5f661 100644
--- a/WebappConfig/dotconfig.py
+++ b/WebappConfig/dotconfig.py
@@ -35,63 +35,6 @@ class DotConfig:
     '''
     This class handles the dotconfig file that will be written to all
     virtual install locations.
-
-    A virtual install location has been prepared in the testfiles
-    directory:
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-    >>> a = DotConfig(here + '/tests/testfiles/htdocs/horde')
-    >>> a.has_dotconfig()
-    True
-
-    This directory contains no virtual install:
-
-    >>> b = DotConfig(here + '/tests/testfiles/htdocs/empty')
-    >>> b.has_dotconfig()
-    False
-
-    The horde install directory is empty:
-
-    >>> a.is_empty()
-
-    This install location has another web application installed::
-
-    >>> b = DotConfig(here + '/tests/testfiles/htdocs/complain')
-    >>> b.is_empty()
-    '!morecontents .webapp-cool-1.1.1'
-
-    This prints what is installed in the horde directory (and
-    tests the read() function):
-
-    >>> a.show_installed()
-    horde 3.0.5
-
-    This will pretend to write a .webapp file (this test has too many ellipsis):
-
-    >>> OUT.color_off() 
-    >>> a = DotConfig('/nowhere', pretend = True)
-    >>> a.write('www-apps', 'horde', '5.5.5', 'localhost', '/horde3', 'me:me') #doctest: +ELLIPSIS
-    * Would have written the following information into /nowhere/.webapp:
-    * # .webapp
-    ...
-    * 
-    * WEB_CATEGORY="www-apps"
-    * WEB_PN="horde"
-    * WEB_PVR="5.5.5"
-    * WEB_INSTALLEDBY="..."
-    * WEB_INSTALLEDDATE="..."
-    * WEB_INSTALLEDFOR="me:me"
-    * WEB_HOSTNAME="localhost"
-    * WEB_INSTALLDIR="/horde3"
-
-    Delete the .webapp file if possible:
-
-    >>> a = DotConfig(here + '/tests/testfiles/htdocs/horde', pretend = True)
-    >>> a.kill() #doctest: +ELLIPSIS
-    * Would have removed .../tests/testfiles/htdocs/horde/.webapp
-    True
-
     '''
 
     def __init__(self,
@@ -290,7 +233,3 @@ class DotConfig:
         else:
             OUT.notice('--- ' + empty)
             return False
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

diff --git a/WebappConfig/tests/dtest.py b/WebappConfig/tests/dtest.py
index 645aee7..8dab47a 100644
--- a/WebappConfig/tests/dtest.py
+++ b/WebappConfig/tests/dtest.py
@@ -8,7 +8,6 @@
 
 import unittest, doctest, sys
 
-import WebappConfig.dotconfig
 import WebappConfig.ebuild
 import WebappConfig.filetype
 import WebappConfig.protect
@@ -16,7 +15,6 @@ import WebappConfig.worker
 
 def test_suite():
     return unittest.TestSuite((
-        doctest.DocTestSuite(WebappConfig.dotconfig),
         doctest.DocTestSuite(WebappConfig.ebuild),
         doctest.DocTestSuite(WebappConfig.filetype),
         doctest.DocTestSuite(WebappConfig.protect),

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
index 3263c1a..ffe76e8 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -22,10 +22,11 @@ import os
 import unittest
 import sys
 
-from  WebappConfig.content import Contents
-from  WebappConfig.db      import WebappDB, WebappSource
-from  WebappConfig.debug   import OUT
-from  warnings             import filterwarnings, resetwarnings
+from  WebappConfig.content   import Contents
+from  WebappConfig.db        import WebappDB, WebappSource
+from  WebappConfig.debug     import OUT
+from  WebappConfig.dotconfig import DotConfig
+from  warnings               import filterwarnings, resetwarnings
 
 HERE = os.path.dirname(os.path.realpath(__file__))
 
@@ -253,6 +254,44 @@ class WebappSourceTest(unittest.TestCase):
             self.assertEqual(source.packageavail(), 1)
 
 
+class DotConfigTest(unittest.TestCase):
+    def test_has_dotconfig(self):
+        dotconf = DotConfig('/'.join((HERE, 'testfiles', 'htdocs', 'horde')))
+        self.assertTrue(dotconf.has_dotconfig())
+
+        dotconf = DotConfig('/'.join((HERE, 'testfiles', 'htdocs', 'empty')))
+        self.assertFalse(dotconf.has_dotconfig())
+
+    def test_is_empty(self):
+        dotconf = DotConfig('/'.join((HERE, 'testfiles', 'htdocs', 'horde')))
+        self.assertEqual(dotconf.is_empty(), None)
+
+        dotconf = DotConfig('/'.join((HERE, 'testfiles', 'htdocs', 'complain')))
+        self.assertEqual(dotconf.is_empty(), '!morecontents .webapp-cool-1.1.1')
+
+    def test_show_installed(self):
+        dotconf = DotConfig('/'.join((HERE, 'testfiles', 'htdocs', 'horde')))
+        dotconf.show_installed()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[0], 'horde 3.0.5')
+
+    def test_install(self):
+        dotconf = DotConfig('/nowhere', pretend=True)
+        dotconf.write('www-apps', 'horde', '5.5.5', 'localhost', '/horde3',
+                      'me:me')
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[14], '* WEB_INSTALLDIR="/horde3"')
+
+    def test_remove(self):
+        dotconf = DotConfig('/'.join((HERE, 'testfiles', 'htdocs', 'horde')),
+                            pretend=True)
+        self.assertTrue(dotconf.kill())
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[0], '* Would have removed ' +
+                         '/'.join((HERE, 'testfiles', 'htdocs', 'horde',
+                                   '.webapp')))
+
+
 if __name__ == '__main__':
     filterwarnings('ignore')
     unittest.main(module=__name__, buffer=True)


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [gentoo-commits] proj/webapp-config:master commit in: WebappConfig/tests/, WebappConfig/
@ 2015-06-19 19:52 Devan Franchini
  0 siblings, 0 replies; 4+ messages in thread
From: Devan Franchini @ 2015-06-19 19:52 UTC (permalink / raw
  To: gentoo-commits

commit:     4b2d150b36e01a6b11d714586f5e521db4d639e1
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Mon Nov  3 00:57:18 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Fri Jun 19 19:49:13 2015 +0000
URL:        https://gitweb.gentoo.org/proj/webapp-config.git/commit/?id=4b2d150b

Adds WebappAdd and WebappRemove tests to external test suite

tests/dtest.py: Deletes dtest.py
tests/external.py: Adds tests for WebappAdd and WebappRemove
worker.py: Removes doctests

 WebappConfig/tests/dtest.py    |  19 -------
 WebappConfig/tests/external.py |  81 +++++++++++++++++++++++++++
 WebappConfig/worker.py         | 122 -----------------------------------------
 3 files changed, 81 insertions(+), 141 deletions(-)

diff --git a/WebappConfig/tests/dtest.py b/WebappConfig/tests/dtest.py
deleted file mode 100644
index 6931dd8..0000000
--- a/WebappConfig/tests/dtest.py
+++ /dev/null
@@ -1,19 +0,0 @@
-################################################################################
-# KOLAB LIBRARY - TESTING "CONDITION.PY"
-################################################################################
-# test_condition.py -- Testing condition.py
-# Copyright 2005 Gunnar Wrobel
-# Distributed under the terms of the GNU General Public License v2
-# $Id$
-
-import unittest, doctest, sys
-
-import WebappConfig.worker
-
-def test_suite():
-    return unittest.TestSuite((
-        doctest.DocTestSuite(WebappConfig.worker),
-        ))
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
index 69fd912..a7ac5ff 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -31,6 +31,7 @@ from  WebappConfig.ebuild    import Ebuild
 from  WebappConfig.filetype  import FileType
 from  WebappConfig.protect   import Protection
 from  WebappConfig.server    import Basic
+from  WebappConfig.worker    import WebappAdd, WebappRemove
 from  warnings               import filterwarnings, resetwarnings
 
 HERE = os.path.dirname(os.path.realpath(__file__))
@@ -420,6 +421,86 @@ class ProtectTest(unittest.TestCase):
         self.assertEqual(output[8], '* etc-update')
         
 
+class WebappAddTest(unittest.TestCase):
+    def test_mk(self):
+        OUT.color_off()
+        contents = Contents('/'.join((HERE, 'testfiles', 'installtest')),
+                            pretend = True)
+        webrm = WebappRemove(contents, True, True)
+        protect = Protection('', 'horde', '3.0.5', 'portage')
+        source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                             'share-webapps')),
+                              category = '', package = 'installtest',
+                              version = '1.0')
+        source.read()
+        source.ignore = ['.svn']
+
+        webadd = WebappAdd('htdocs',
+                           '/'.join((HERE, 'testfiles', 'installtest')),
+                           {'dir': {'default-owned': ('root',
+                                                      'root',
+                                                      '0644')},
+                            'file': {'virtual':      ('root',
+                                                       'root',
+                                                       '0644'),
+                                     'server-owned': ('apache',
+                                                      'apache',
+                                                      '0660'),
+                                     'config-owned': ('nobody',
+                                                      'nobody',
+                                                      '0600')}
+                           },
+                           {'content': contents,
+                            'removal': webrm,
+                            'protect': protect,
+                            'source' : source},
+                           {'relative': 1,
+                            'upgrade' : False,
+                            'pretend' : True,
+                            'verbose' : False,
+                            'linktype': 'soft'})
+        webadd.mkfile('test1')
+        webadd.mkfile('test4')
+        webadd.mkfile('test2')
+        webadd.mkfile('test3')
+        webadd.mkdir('dir1')
+        webadd.mkdir('dir2')
+
+        output = sys.stdout.getvalue().split('\n')
+
+        self.assertEqual(output[0], '*     pretending to add: sym 1 virtual ' +
+                                    '"test1"')
+        self.assertEqual(output[1], '*     pretending to add: file 1 ' +
+                                    'server-owned "test4"')
+        self.assertEqual(output[3], '*     pretending to add: sym 1 virtual ' +
+                                    '"test2"')
+        self.assertEqual(output[4], '^o^ hiding test3')
+        self.assertEqual(output[6], '*     pretending to add: dir 1 ' +
+                                    'default-owned "dir1"')
+        self.assertEqual(output[8], '*     pretending to add: dir 1 ' +
+                                    'default-owned "dir2"')
+
+        # Now testing all of them combined:
+        webadd.mkdirs('')
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[20], '^o^ hiding /test3')
+
+
+class WebappRemoveTest(unittest.TestCase):
+    def test_remove_files(self):
+        OUT.color_off()
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents', 'app2')),
+                            package = 'test', version = '1.0', pretend = True)
+        contents.read()
+        webrm = WebappRemove(contents, True, True)
+        webrm.remove_files()
+
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[3], '*     pretending to remove: ' +
+                         '/'.join((HERE, 'testfiles', 'contents', 'app2',
+                                   'test3')))
+
+
 if __name__ == '__main__':
     filterwarnings('ignore')
     unittest.main(module=__name__, buffer=True)

diff --git a/WebappConfig/worker.py b/WebappConfig/worker.py
index 5b10060..8b10253 100644
--- a/WebappConfig/worker.py
+++ b/WebappConfig/worker.py
@@ -44,27 +44,6 @@ class WebappRemove:
     '''
     This is the handler for removal of web applications from their virtual
     install locations.
-
-    For removal of files a content handler is sufficient:
-
-    >>> OUT.color_off()
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-    >>> from WebappConfig.content import Contents
-    >>> a = Contents(here + '/tests/testfiles/contents/app2',
-    ...              package = 'test', version = '1.0', pretend = True)
-    >>> a.read()
-    >>> b = WebappRemove(a, True, True)
-
-    # Pretend to remove files:
-
-    # b.remove_files() #doctest: +ELLIPSIS
-
-    # Deleted the test since this will almost certainly fail because
-    # of the modification time.
-
-    Deleted test for removal of directories. They are always reported as 'not
-    empty' in case I am working in the subversion repository.
     '''
 
     def __init__(self,
@@ -168,102 +147,6 @@ class WebappAdd:
     '''
     This is the class that handles the actual transfer of files from
     the web application source directory to the virtual install location.
-
-    The setup of the class is rather complex since a lot of different
-    handlers are needed for the task.
-
-    >>> OUT.color_off()
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-
-    The content handler points to the virtual install directory:
-
-    >>> from WebappConfig.content import Contents
-    >>> a = Contents(here + '/tests/testfiles/installtest', pretend = True)
-
-    Removal of files will be necessary while upgrading :
-
-    >>> b = WebappRemove(a, True, True)
-
-    The handler for protected files is simple:
-
-    >>> import WebappConfig.protect
-    >>> c = WebappConfig.protect.Protection('','horde','3.0.5','portage')
-
-    And finally a fully initialized source is needed:
-
-    >>> from WebappConfig.db import WebappSource
-    >>> d = WebappSource(root=here + '/tests/testfiles/share-webapps',
-    ...             category='', package='installtest', version='1.0')
-    >>> d.read()
-    >>> d.ignore = ['.svn']
-
-    >>> e = WebappAdd('htdocs',
-    ...               here + '/tests/testfiles/installtest',
-    ...               {'dir'  : {
-    ...                          'default-owned': ('root', 'root', '0644'),
-    ...                         },
-    ...                'file' : {
-    ...                          'virtual' : ('root', 'root', '0644'),
-    ...                          'server-owned' : ('apache', 'apache', '0660'),
-    ...                          'config-owned' : ('nobody', 'nobody', '0600'),
-    ...                         }},
-    ...               {'content': a,
-    ...                'removal': b,
-    ...                'protect': c,
-    ...                'source' : d},
-    ...               {'relative': 1,
-    ...                'upgrade':  False,
-    ...                'pretend':  True,
-    ...                'verbose':  False,
-    ...                'linktype': 'soft'})
-
-    Installing a standard file:
-
-    >>> e.mkfile('test1')
-    *     pretending to add: sym 1 virtual "test1"
-    >>> e.mkfile('test4')
-    *     pretending to add: file 1 server-owned "test4"
-
-    This location is already occupied. But since the file is not
-    known, it will be deleted:
-
-    >>> e.mkfile('test2') #doctest: +ELLIPSIS
-    *     would have removed ".../tests/testfiles/installtest/test2" since it is in the way for the current install. It should not be present in that location!
-    *     pretending to add: sym 1 virtual "test2"
-
-    This location is also occupied but it it is a config protected
-    file so it may not be removed:
-
-    >>> e.mkfile('test3') #doctest: 
-    ^o^ hiding test3
-    *     pretending to add: file 1 config-owned "test3"
-    
-    >>> e.mkdir('dir1') 
-    *     pretending to add: dir 1 default-owned "dir1"
-    
-    >>> e.mkdir('dir2') #doctest: +ELLIPSIS
-    *     .../tests/testfiles/installtest/dir2 already exists, but is not a directory - removing
-    *     pretending to add: dir 1 default-owned "dir2"
-
-    And finally everything combined:
-
-    >>> e.mkdirs('') #doctest: +ELLIPSIS
-    *     Installing from .../tests/testfiles/share-webapps/installtest/1.0/htdocs/
-    *     pretending to add: dir 1 default-owned "dir1"
-    *     Installing from .../tests/testfiles/share-webapps/installtest/1.0/htdocs/dir1
-    *     pretending to add: sym 1 virtual "dir1/webapp_test"
-    *     .../tests/testfiles/installtest//dir2 already exists, but is not a directory - removing
-    *     pretending to add: dir 1 default-owned "dir2"
-    *     Installing from .../tests/testfiles/share-webapps/installtest/1.0/htdocs/dir2
-    *     pretending to add: sym 1 virtual "dir2/webapp_test"
-    *     pretending to add: sym 1 virtual "test1"
-    *     would have removed ".../tests/testfiles/installtest//test2" since it is in the way for the current install. It should not be present in that location!
-    *     pretending to add: sym 1 virtual "test2"
-    ^o^ hiding /test3
-    *     pretending to add: file 1 config-owned "test3"
-    *     pretending to add: file 1 server-owned "test4"
-
     '''
 
     def __init__(self,
@@ -593,8 +476,3 @@ class WebappAdd:
                            filename,
                            dst_name,
                            self.__relative)
-
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [gentoo-commits] proj/webapp-config:master commit in: WebappConfig/tests/, WebappConfig/
@ 2015-06-19 19:52 Devan Franchini
  0 siblings, 0 replies; 4+ messages in thread
From: Devan Franchini @ 2015-06-19 19:52 UTC (permalink / raw
  To: gentoo-commits

commit:     15149d31eaaca1a97c83adc437505210bfdd467c
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Sun Nov  2 08:15:18 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Fri Jun 19 19:48:55 2015 +0000
URL:        https://gitweb.gentoo.org/proj/webapp-config.git/commit/?id=15149d31

Adds FileType tests to external test suite

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

 WebappConfig/filetype.py       | 79 ------------------------------------------
 WebappConfig/tests/dtest.py    |  2 --
 WebappConfig/tests/external.py | 37 ++++++++++++++++++++
 3 files changed, 37 insertions(+), 81 deletions(-)

diff --git a/WebappConfig/filetype.py b/WebappConfig/filetype.py
index 63d7e5f..d677189 100644
--- a/WebappConfig/filetype.py
+++ b/WebappConfig/filetype.py
@@ -36,80 +36,6 @@ class FileType:
 
     - a list of all files and directories owned by the config user
     - a list of all files and directories owned by the server user
-
-    This creates such lists:
-
-    >>> config_owned = [ 'a', 'a/b/c/d', '/e', '/f/', '/g/h/', 'i\\n']
-    >>> server_owned = [ 'j', 'k/l/m/n', '/o', '/p/', '/q/r/', 's\\n']
-
-    The class is initialized with these two arrays:
-
-    >>> a = FileType(config_owned, server_owned)
-
-    This class provides three functions to retrieve information about
-    the file or directory type.
-
-    File types
-    ----------
-
-    >>> a.filetype('a')
-    'config-owned'
-    >>> a.filetype('a/b/c/d')
-    'config-owned'
-
-    >>> a.filetype('j')
-    'server-owned'
-    >>> a.filetype('/o')
-    'server-owned'
-
-    File names - whether specified as input in the
-    {config,server}_owned lists or as key for retrieving the type - may
-    have leading or trailing whitespace. It will be removed. Trailing
-
-    >>> a.filetype('\\n s')
-    'server-owned'
-    >>> a.filetype('/g/h\\n')
-    'config-owned'
-
-    Unspecified files will result in a virtual type:
-
-    >>> a.filetype('unspecified.txt')
-    'virtual'
-
-    This behaviour can be influenced by setting the 'virtual_files'
-    option for the class (which corresponds to the --virtual-files command
-    line option):
-
-    >>> b = FileType(config_owned, server_owned,
-    ...              virtual_files = 'server-owned')
-    >>> b.filetype('unspecified.txt')
-    'server-owned'
-
-    Directory types
-    ---------------
-
-    The class does not know if the given keys are files or directories.
-    This is specified using the correct function for them. So the same
-    keys that were used above can also be used here:
-
-    >>> a.dirtype('a')
-    'config-owned'
-    >>> a.dirtype('j')
-    'server-owned'
-
-    The same whitespace and trailing slash fixing rules apply for
-    directory names:
-
-    >>> a.dirtype('\\n s')
-    'server-owned'
-    >>> a.dirtype('/g/h\\n')
-    'config-owned'
-
-    Unspecified directories are 'default-owned' and not marked 'virtual':
-
-    >>> a.dirtype('unspecified.txt')
-    'default-owned'
-
     '''
 
     def __init__(self,
@@ -224,8 +150,3 @@ class FileType:
         filename = re.compile('/+').sub('/', filename) 
 
         return filename
-
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

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

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
index 88b98c8..c8b0646 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -28,6 +28,7 @@ from  WebappConfig.db        import WebappDB, WebappSource
 from  WebappConfig.debug     import OUT
 from  WebappConfig.dotconfig import DotConfig
 from  WebappConfig.ebuild    import Ebuild
+from  WebappConfig.filetype  import FileType
 from  WebappConfig.server    import Basic
 from  warnings               import filterwarnings, resetwarnings
 
@@ -329,6 +330,42 @@ class EbuildTest(unittest.TestCase):
                                                                  'hostroot')))
 
 
+class FileTypeTest(unittest.TestCase):
+    def test_filetypes(self):
+        config_owned = ('a', 'a/b/c/d', '/e', '/f/', '/g/h/', 'i\\n')
+        server_owned = ('j', 'k/l/m/n', '/o', '/p/', '/q/r/', 's\\n')
+
+        types = FileType(config_owned, server_owned)
+
+        self.assertEqual(types.filetype('a'),       'config-owned')
+        self.assertEqual(types.filetype('a/b/c/d'), 'config-owned')
+        self.assertEqual(types.filetype('j'),       'server-owned')
+        self.assertEqual(types.filetype('/o'),      'server-owned')
+
+        # It will always remove leading spaces or whitespace:
+        self.assertEqual(types.filetype('\t s\\n'), 'server-owned')
+        # Unspecified files will be set as virtual:
+        self.assertEqual(types.filetype('foo.txt'), 'virtual')
+        # However, you can set what you want your virtual-files to be:
+        types = FileType(config_owned, server_owned,
+                         virtual_files='server-owned')
+        self.assertEqual(types.filetype('foo.txt'), 'server-owned')
+
+    def test_dirtypes(self):
+        config_owned = ('a', 'a/b/c/d', '/e', '/f/', '/g/h/', 'i\\n')
+        server_owned = ('j', 'k/l/m/n', '/o', '/p/', '/q/r/', 's\\n')
+
+        types = FileType(config_owned, server_owned)
+
+        self.assertEqual(types.dirtype('a'),       'config-owned')
+        self.assertEqual(types.dirtype('j'),       'server-owned')
+
+        # Same whitespace rules apply for dirtype():
+        self.assertEqual(types.dirtype('\t s\\n'), 'server-owned')
+        # Unspecified dirs will be set as default-owned:
+        self.assertEqual(types.dirtype('foo.txt'), 'default-owned')
+
+
 if __name__ == '__main__':
     filterwarnings('ignore')
     unittest.main(module=__name__, buffer=True)


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [gentoo-commits] proj/webapp-config:master commit in: WebappConfig/tests/, WebappConfig/
@ 2015-06-19 19:52 Devan Franchini
  0 siblings, 0 replies; 4+ messages in thread
From: Devan Franchini @ 2015-06-19 19:52 UTC (permalink / raw
  To: gentoo-commits

commit:     9b10c59abfc75813670eea42a3ebdb6337265960
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: Fri Jun 19 19:49:05 2015 +0000
URL:        https://gitweb.gentoo.org/proj/webapp-config.git/commit/?id=9b10c59a

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 c8b0646..69fd912 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
 
@@ -366,7 +367,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()


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-19 19:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-19 19:52 [gentoo-commits] proj/webapp-config:master commit in: WebappConfig/tests/, WebappConfig/ Devan Franchini
  -- strict thread matches above, loose matches on Subject: below --
2015-06-19 19:52 Devan Franchini
2015-06-19 19:52 Devan Franchini
2015-06-19 19:52 Devan Franchini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox