public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:42 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:42 UTC (permalink / raw
  To: gentoo-commits

commit:     56636b1fe3891e0b7ee6e8e6e3f4b8e9f68a9db6
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Sun Nov  2 07:29:05 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Mon Nov 17 23:42:40 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=56636b1f

Adds Ebuild tests to external test suite

tests/dtest.py: Removes WebappConfig.ebuild from doctest listing
tests/external.py: Adds tests for Ebuild class
ebuild.py: Removes doctests, the tests used for testing run_hooks()
were not added to the external test suite due to the fact that there
is no return to check against, just output.

---
 WebappConfig/ebuild.py         | 141 -----------------------------------------
 WebappConfig/tests/dtest.py    |   2 -
 WebappConfig/tests/external.py |  37 +++++++++++
 3 files changed, 37 insertions(+), 143 deletions(-)

diff --git a/WebappConfig/ebuild.py b/WebappConfig/ebuild.py
index 24ef0d6..fecbe44 100644
--- a/WebappConfig/ebuild.py
+++ b/WebappConfig/ebuild.py
@@ -35,69 +35,6 @@ class Ebuild:
     This class handles all ebuild related task. Currently this includes
     displaying the post install instruction as well as running hooks
     provided by the ebuild.
-
-    This creates the basic configuration defaults:
-
-    >>> import WebappConfig.config
-    >>> config = WebappConfig.config.Config()
-
-    This needs to be completed with some parameters
-    that would be usually provided when parsing the
-    commandline:
-
-    >>> config.config.set('USER', 'my_htdocsbase',  'htdocs')
-    >>> config.config.set('USER', 'pn',   'horde')
-    >>> config.config.set('USER', 'pvr',  '3.0.5')
-    >>> config.config.set('USER', 'vhost_server_uid', 'apache')
-    >>> config.config.set('USER', 'vhost_server_gid', 'apache')
-
-    And the application directory needs to be set
-    to the testfile reporitory
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-    >>> config.config.set('USER', 'my_approot', here +
-    ...                   '/tests/testfiles/share-webapps')
-
-    Time to create the ebuild handler:
-
-    >>> my_approot = config.config.get('USER', 'my_approot')
-    >>> my_appdir = my_approot + "/horde/3.0.5"
-    >>> config.config.set('USER', 'my_appdir', my_appdir)
-    >>> config.config.set('USER', 'my_hookscriptsdir', my_appdir + '/hooks')
-    >>> config.config.set('USER', 'my_cgibinbase', 'cgi-bin')
-    >>> config.config.set('USER', 'my_errorsbase', 'error')
-    >>> config.config.set('USER', 'my_iconsbase', 'icons')
-    >>> config.config.set('USER', 'my_serverconfigdir', '/'.join([my_appdir,'conf']))
-    >>> config.config.set('USER', 'my_hostrootdir', '/'.join([my_appdir,'hostroot']))
-    >>> config.config.set('USER', 'my_htdocsdir', '/'.join([my_appdir,'htdocs']))
-    >>> config.config.set('USER', 'my_sqlscriptsdir', '/'.join([my_appdir,'sqlscripts']))
-    >>> a = Ebuild(config)
-
-    Run a hook script:
-
-    >>> from WebappConfig.server import Basic
-    >>> basic = Basic({'source': '', 'destination': '', 'hostroot': '', 'vhostroot':''},
-    ...               config.create_permissions(),
-    ...               {'source':'','content':'','protect':'','dotconfig':'','ebuild':'','db':''},
-    ...               {'verbose':False,'pretend':True}, 'portage')
-    >>> a.run_hooks('test', basic)
-
-    The same on a directory that misses a hook dir:
-
-    >>> config.config.set('USER', 'pn',   'empty')
-    >>> config.config.set('USER', 'pvr',  '1.0')
-    >>> a = Ebuild(config)
-    >>> a.run_hooks('test', basic)
-
-    This app has a hook dir but no script:
-
-    >>> config.config.set('USER', 'pn',   'uninstalled')
-    >>> config.config.set('USER', 'pvr',  '6.6.6')
-    >>> a = Ebuild(config)
-    >>> a.run_hooks('test', basic)
-
-
     '''
 
     def __init__(self, config):
@@ -197,80 +134,6 @@ class Ebuild:
         This function exports the necessary variables to the shell
         environment so that they are accessible within the shell scripts
         and/or files provided by the ebuild.
-
-        The procedure from above is repeated to set up the default
-        environment:
-
-        ">>> import WebappConfig.config"
-        ">>> config = WebappConfig.config.Config()"
-        ">>> config.config.set('USER', 'my_htdocsbase',  'htdocs')"
-        ">>> config.config.set('USER', 'pn',   'horde')"
-        ">>> config.config.set('USER', 'pvr',  '3.0.5')"
-        ">>> import os.path"
-        ">>> here = os.path.dirname(os.path.realpath(__file__))"
-        ">>> config.config.set('USER', 'my_approot', here +"
-        "...                   '/tests/testfiles/share-webapps')"
-        ">>> my_approot = config.config.get('USER', 'my_approot')"
-        ">>> my_appdir = my_approot + "/horde/3.0.5""
-        ">>> config.config.set('USER', 'my_appdir', my_appdir)"
-        ">>> config.config.set('USER', 'my_hookscriptsdir', my_appdir + '/hooks')"
-        ">>> config.config.set('USER', 'my_cgibinbase', 'cgi-bin')"
-        ">>> config.config.set('USER', 'my_errorsbase', 'error')"
-        ">>> config.config.set('USER', 'my_iconsbase', 'icons')"
-        ">>> config.config.set('USER', 'my_serverconfigdir', '/'.join([my_appdir,'conf']))"
-        ">>> config.config.set('USER', 'my_hostrootdir', '/'.join([my_appdir,'hostroot']))"
-        ">>> config.config.set('USER', 'my_htdocsdir', '/'.join([my_appdir,'htdocs']))"
-        ">>> config.config.set('USER', 'my_sqlscriptsdir', '/'.join([my_appdir,'sqlscripts']))"
-
-        Time to create the ebuild handler:
-
-        ">>> a = Ebuild(config)"
-
-        The dummy post-install file should display all the variables
-        that are exported here:
-
-        ">>> a.show_postinst() #doctest: +ELLIPSIS
-        <BLANKLINE>
-        =================================================================
-        POST-INSTALL INSTRUCTIONS
-        =================================================================
-        <BLANKLINE>
-        MY_HOSTROOTDIR: .../tests/testfiles/share-webapps/horde/3.0.5/hostroot
-        MY_HTDOCSDIR: .../tests/testfiles/share-webapps/horde/3.0.5/htdocs
-        MY_CGIBINDIR: .../tests/testfiles/share-webapps/horde/3.0.5/hostroot/cgi-bin
-        MY_INSTALLDIR: /
-        MY_ICONSDIR: .../tests/testfiles/share-webapps/horde/3.0.5/hostroot/icons
-        MY_SERVERCONFIGDIR: .../tests/testfiles/share-webapps/horde/3.0.5/conf
-        MY_ERRORSDIR: .../tests/testfiles/share-webapps/horde/3.0.5/hostroot/error
-        MY_SQLSCRIPTSDIR: .../tests/testfiles/share-webapps/horde/3.0.5/sqlscripts
-        VHOST_ROOT: /var/www/...
-        VHOST_HTDOCSDIR: /var/www/.../htdocs
-        VHOST_CGIBINDIR: /var/www/.../cgi-bin
-        VHOST_CONFDIR: /var/www/.../
-        VHOST_ERRORSDIR: /var/www/.../error
-        VHOST_ICONSDIR: /var/www/.../icons
-        VHOST_HOSTNAME: ...
-        VHOST_SERVER: apache
-        VHOST_APPDIR: /
-        VHOST_CONFIG_UID: ...
-        VHOST_CONFIG_GID: ...
-        VHOST_SERVER_UID: ...
-        VHOST_SERVER_GID: ...
-        VHOST_DEFAULT_UID: 0
-        VHOST_DEFAULT_GID: 0
-        VHOST_PERMS_SERVEROWNED_DIR: 0775
-        VHOST_PERMS_SERVEROWNED_FILE: 0664
-        VHOST_PERMS_CONFIGOWNED_DIR: 0755
-        VHOST_PERMS_CONFIGOWNED_FILE: 0644
-        VHOST_PERMS_DEFAULTOWNED_DIR: 0755
-        VHOST_PERMS_VIRTUALOWNED_FILE: o-w
-        VHOST_PERMS_INSTALLDIR: 0755
-        ROOT: /
-        PN: horde
-        PVR: 3.0.5
-        <BLANKLINE>
-        =================================================================
-        <BLANKLINE>"
         '''
 
         v_root = self.get_config('vhost_root')
@@ -337,7 +200,3 @@ class Ebuild:
             result[i] = str(value)
 
         return result
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

diff --git a/WebappConfig/tests/dtest.py b/WebappConfig/tests/dtest.py
index 8dab47a..a46be2c 100644
--- a/WebappConfig/tests/dtest.py
+++ b/WebappConfig/tests/dtest.py
@@ -8,14 +8,12 @@
 
 import unittest, doctest, sys
 
-import WebappConfig.ebuild
 import WebappConfig.filetype
 import WebappConfig.protect
 import WebappConfig.worker
 
 def test_suite():
     return unittest.TestSuite((
-        doctest.DocTestSuite(WebappConfig.ebuild),
         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 75c2eb6..6c0fa3a 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -22,10 +22,13 @@ import os
 import unittest
 import sys
 
+from  WebappConfig.config    import Config
 from  WebappConfig.content   import Contents
 from  WebappConfig.db        import WebappDB, WebappSource
 from  WebappConfig.debug     import OUT
 from  WebappConfig.dotconfig import DotConfig
+from  WebappConfig.ebuild    import Ebuild
+from  WebappConfig.server    import Basic
 from  warnings               import filterwarnings, resetwarnings
 
 HERE = os.path.dirname(os.path.realpath(__file__))
@@ -293,6 +296,40 @@ class DotConfigTest(unittest.TestCase):
                                    '.webapp')))
 
 
+
+class EbuildTest(unittest.TestCase):
+    def test_showpostinst(self):
+        config = Config()
+        approot = '/'.join((HERE, 'testfiles', 'share-webapps'))
+        appdir  = '/'.join((approot, 'horde', '3.0.5'))
+        conf   = {'my_htdocsbase': 'htdocs', 'pn': 'horde', 'pvr': '3.0.5',
+                  'vhost_server_uid': 'apache', 'vhost_server_git': 'apache',
+                  'my_approot': approot,
+                  'my_appdir': appdir,
+                  'my_hookscriptsdir': '/'.join((appdir, 'hooks')),
+                  'my_cgibinbase': 'cgi-bin', 'my_errorsbase': 'error',
+                  'my_iconsbase': 'icons',
+                  'my_serverconfigdir': '/'.join((appdir, 'conf')),
+                  'my_hostrootdir': '/'.join((appdir, 'hostroot')),
+                  'my_htdocsdir': '/'.join((appdir, 'htdocs')),
+                  'my_sqlscriptsdir': '/'.join((appdir, 'sqlscripts')),
+                 }
+
+        for key in conf.keys():
+            config.config.set('USER', key, conf[key])
+
+        ebuild = Ebuild(config)
+        ebuild.show_postinst()
+        output = sys.stdout.getvalue().split('\n')
+
+        self.assertEqual(output[5], 'MY_HOSTROOTDIR: ' + '/'.join((HERE,
+                                                                 'testfiles',
+                                                                 'share-webapps',
+                                                                 'horde',
+                                                                 '3.0.5',
+                                                                 'hostroot')))
+
+
 if __name__ == '__main__':
     filterwarnings('ignore')
     unittest.main(module=__name__, buffer=True)


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

commit:     e1fdc8fadbe900f40b0ea99a95ff94ac08827636
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:19:14 2015 +0000
URL:        https://gitweb.gentoo.org/proj/webapp-config.git/commit/?id=e1fdc8fa

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] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:58 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:58 UTC (permalink / raw
  To: gentoo-commits

commit:     cf462b9bbab21fc0b7ddf3488dd997ddd3c8e3c1
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: Mon Nov 17 23:57:54 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=cf462b9b

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] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:58 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:58 UTC (permalink / raw
  To: gentoo-commits

commit:     e3d73e36bee5421a01b079b6db484b88e5899cbb
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: Mon Nov 17 23:57:54 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=e3d73e36

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] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:58 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:58 UTC (permalink / raw
  To: gentoo-commits

commit:     dca8798885a2f93bb738a226aeaed5e289bd5486
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 30 15:54:47 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Mon Nov 17 23:57:53 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=dca87988

Adds beginning stages of external test suite

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

---
 WebappConfig/content.py        | 165 -----------------------------------------
 WebappConfig/tests/dtest.py    |   2 -
 WebappConfig/tests/external.py | 138 ++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+), 167 deletions(-)

diff --git a/WebappConfig/content.py b/WebappConfig/content.py
index e157d23..a582396 100644
--- a/WebappConfig/content.py
+++ b/WebappConfig/content.py
@@ -131,58 +131,6 @@ class Contents:
     def read(self):
         '''
         Reads the contents database.
-
-        Some content files have been provided for test purposes:
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        This one should succeed:
-
-        >>> a = Contents(here + '/tests/testfiles/contents/',
-        ...              package = 'test', version = '1.0')
-        >>> a.read()
-        >>> a.db_print()
-        file 1 virtual util/icon_browser.php 1124612216 9ffb2ca9ccd2db656b97cd26a1b06010 
-        file 1 config-owned inc/prefs.php 1124612215 ffae752dba7092cd2d1553d04a0f0045 
-        file 1 virtual lib/prefs.php 1124612215 ffae752dba7092cd2d1553d04a0f0045 
-        file 1 virtual signup.php 1124612220 dc838bc375b3d02dafc414f8e71a2aec 
-        file 1 server-owned data.php 1117009618 0 
-        sym 1 virtual test 1124612220 dc838bc375b3d02dafc414f8e71a2aec /I link / to a very / strange location
-        dir 1 default-owned util 1117009618 0 
-        dir 1 config-owned inc 1117009618 0 
-        dir 1 default-owned lib 1117009618 0 
-        dir 0 default-owned /var/www/localhost/cgi-bin 1124577741 0 
-        dir 0 default-owned /var/www/localhost/error 1124577740 0 
-        dir 0 default-owned /var/www/localhost/icons 1124577741 0 
-        
-        >>> a.get_directories() #doctest: +ELLIPSIS
-        ['.../contents//util', '.../contents//inc', '.../contents//lib', '/var/www/localhost/cgi-bin', '/var/www/localhost/error', '/var/www/localhost/icons']
-
-        This is a corrupted file that checks all fail safes:
-
-        >>> OUT.color_off()
-        >>> a = Contents(here + '/tests/testfiles/contents/',
-        ...              package = 'test', version = '1.1')
-        >>> a.read() #doctest: +ELLIPSIS
-        * Invalid line in content file (dir 1 default-owned). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * dir 1 nobody-owned  1117009618 0
-        * Invalid owner: nobody-owned
-        * Invalid line in content file (dir 1 nobody-owned  1117009618 0). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * garbage 1 virtual  1124612215 ffae752dba7092cd2d1553d04a0f0045
-        * Invalid file type: garbage
-        * Invalid line in content file (garbage 1 virtual  1124612215 ffae752dba7092cd2d1553d04a0f0045). Ignoring!
-        * Invalid line in content file (file 1 virtual). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * file 1 virtual 
-        * Not enough entries.
-        * Invalid line in content file (file 1 virtual ). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * file 31 config-owned  1124612215 ffae752dba7092cd2d1553d04a0f0045
-        * Invalid relative flag: 31
-        * Invalid line in content file (file 31 config-owned  1124612215 ffae752dba7092cd2d1553d04a0f0045). Ignoring!
         '''
 
         dbpath = self.appdb()
@@ -270,18 +218,6 @@ class Contents:
     def write(self):
         '''
         Write the contents file.
-
-        A short test:
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = Contents(here + '/tests/testfiles/contents/',
-        ...              package = 'test', version = '1.0',
-        ...              pretend = True)
-        >>> a.read()
-        >>> OUT.color_off()
-        >>> a.write() #doctest: +ELLIPSIS
-        * Would have written content file .../tests/testfiles/contents//.webapp-test-1.0!
         '''
 
         dbpath = self.appdb()
@@ -378,77 +314,6 @@ class Contents:
           real_path   - for config-protected files realpath =! path
                         (and this is important for md5)
           relative    - 1 for storing a relative filename, 0 otherwise
-
-        OUT.color_off()
-        import os.path
-        here = os.path.dirname(os.path.realpath(__file__))
-
-        One for pretending:
-
-        a = Contents(here + '/tests/testfiles/contents/app/',
-        ...              package = 'test', version = '1.0',
-        ...              pretend = True)
-
-        And this one is for real:
-
-        b = Contents(here + '/tests/testfiles/contents/app/',
-        ...              package = 'test', version = '1.0')
-
-        Pretend to add a file:
-
-        a.add('file', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test1', relative = True)
-        *     pretending to add: file 1 config-owned "test1"
-
-        Lets not pretend this time:
-
-        b.add('file', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test1', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/test1') #doctest: +ELLIPSIS
-        'file 1 config-owned "test1" ... d8e8fca2dc0f896fd7cb4cb0031ba249 '
-
-        Lets produce an error with a file that does not exist:
-
-        b.add('file', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/nothere', relative = True) #doctest: +ELLIPSIS
-        * Cannot access file .../tests/testfiles/contents/app/nothere to add it as installation content. This should not happen!
-
-        Other file types:
-
-        b.add('hardlink', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test2', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/test2') #doctest: +ELLIPSIS
-        'file 1 config-owned "test2" ... d8e8fca2dc0f896fd7cb4cb0031ba249 '
-        b.add('dir', 'default-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/dir1', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/dir1') #doctest: +ELLIPSIS
-        'dir 1 default-owned "dir1" ... 0 '
-        b.add('dir', 'default-owned', destination = here + '/tests/testfiles/contents/app',
-        ...       path = '/dir1',
-        ...       relative = False)
-        b.entry(here + '/tests/testfiles/contents/app/dir1') #doctest: +ELLIPSIS
-        'dir 0 default-owned ".../tests/testfiles/contents/app/dir1" ... 0 '
-
-        Q: Is the full link to the target what we want?
-        A: Yes, since the link will still be ok even if we move the directory.
-
-        b.add('sym', 'virtual',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test3', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/test3') #doctest: +ELLIPSIS
-        'sym 1 virtual "test3" ... 0 .../tests/testfiles/contents/app/test1'
-
-        b.db_print() #doctest: +ELLIPSIS
-        file 1 config-owned "test1" ... d8e8fca2dc0f896fd7cb4cb0031ba249 
-        file 1 config-owned "test2" ... d8e8fca2dc0f896fd7cb4cb0031ba249 
-        sym 1 virtual "test3" ... 0 .../tests/testfiles/contents/app/test1
-        dir 0 default-owned ".../tests/testfiles/contents/app/dir1" ... 0 
-
         '''
 
         OUT.debug('Adding entry to content dictionary', 6)
@@ -574,32 +439,6 @@ class Contents:
 
         In case the entry can be removed nothing will be
         returned.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        Trying to remove the contents:
-
-        >>> a = Contents(here + '/tests/testfiles/contents/app/',
-        ...              package = 'test', version = '1.0')
-        >>> a.read()
-        >>> a.ignore += ['.svn']
-        >>> for i in a.get_directories():
-        ...     a.get_canremove(i)
-        '!dir test7'
-        '!empty dir1'
-
-        >>> for i in a.get_files():
-        ...     a.get_canremove(i)
-        '!time test2'
-        '!time test4'
-        '!found test6'
-        '!sym dir3'
-        '!file dir4'
-
-        # Disabled 
-        #'!target test3'
-
         '''
 
         OUT.debug('Checking if the file can be removed', 6)
@@ -746,7 +585,3 @@ class Contents:
             return self.__content[entry][6]
         else:
             raise Exception('Unknown file "' + entry + '"')
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

diff --git a/WebappConfig/tests/dtest.py b/WebappConfig/tests/dtest.py
index 8ad3188..61d3f89 100644
--- a/WebappConfig/tests/dtest.py
+++ b/WebappConfig/tests/dtest.py
@@ -8,7 +8,6 @@
 
 import unittest, doctest, sys
 
-import WebappConfig.content
 import WebappConfig.db
 import WebappConfig.dotconfig
 import WebappConfig.ebuild
@@ -18,7 +17,6 @@ import WebappConfig.worker
 
 def test_suite():
     return unittest.TestSuite((
-        doctest.DocTestSuite(WebappConfig.content),
         doctest.DocTestSuite(WebappConfig.db),
         doctest.DocTestSuite(WebappConfig.dotconfig),
         doctest.DocTestSuite(WebappConfig.ebuild),

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
new file mode 100755
index 0000000..7d8bbdc
--- /dev/null
+++ b/WebappConfig/tests/external.py
@@ -0,0 +1,138 @@
+# -*- coding: utf-8 -*-
+################################################################################
+# EXTERNAL WEBAPP-CONFIG TESTS
+################################################################################
+# File:       external.py
+#
+#             Runs external (non-doctest) test cases.
+#
+# Copyright:
+#             (c) 2014        Devan Franchini
+#             Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+#             Devan Franchini <twitch153@gentoo.org>
+#
+
+from __future__ import print_function
+
+'''Runs external (non-doctest) test cases.'''
+
+import os
+import unittest
+import sys
+
+from  WebappConfig.content import Contents
+from  WebappConfig.debug   import OUT
+from  warnings             import filterwarnings, resetwarnings
+
+HERE = os.path.dirname(os.path.realpath(__file__))
+
+class ContentsTest(unittest.TestCase):
+    def test_add_pretend(self):
+        loc = '/'.join((HERE, 'testfiles', 'contents', 'app'))
+        contents = Contents(loc, package = 'test', version = '1.0',
+                            pretend = True)
+        OUT.color_off()
+        contents.add('file', 'config_owned', destination = loc, path = '/test1',
+                     real_path = loc + '/test1', relative = True)
+
+        output = sys.stdout.getvalue().strip('\n')
+        self.assertEqual(output,
+                       '*     pretending to add: file 1 config_owned "test1"')
+
+    def test_add(self):
+        loc = '/'.join((HERE, 'testfiles', 'contents', 'app'))
+        contents = Contents(loc, package = 'test', version = '1.0')
+        OUT.color_off()
+        contents.add('file', 'config_owned', destination = loc, path = '/test1',
+                     real_path = loc + '/test1', relative = True)
+
+        # Now trigger an error by adding a file that doesn't exist!
+        contents.add('file', 'config_owned', destination = loc, path = '/test0',
+                     real_path = loc + '/test0', relative = True)
+
+        output = sys.stdout.getvalue().strip('\n')
+
+        self.assertTrue('WebappConfig/tests/testfiles/contents/app/test0 to '\
+                        'add it as installation content. This should not '\
+                        'happen!' in output)
+
+        # Test adding hardlinks:
+        contents.add('hardlink', 'config_owned', destination = loc,
+                     path = '/test2', real_path = loc + '/test2', relative = True)
+        self.assertTrue('file 1 config_owned "test2" ' in contents.entry(loc +
+                                                                      '/test2'))
+        # Test adding dirs:
+        contents.add('dir', 'default_owned', destination = loc, path = '/dir1',
+                     real_path = loc + '/dir1', relative = True)
+        self.assertTrue('dir 1 default_owned "dir1" ' in contents.entry(loc +
+                                                                       '/dir1'))
+
+        # Test adding symlinks:
+        contents.add('sym', 'virtual', destination = loc, path = '/test3',
+                     real_path = loc + '/test3', relative = True)
+        self.assertTrue('sym 1 virtual "test3" ' in contents.entry(loc +
+                                                                   '/test3'))
+
+        # Printing out the db after adding these entries:
+        contents.db_print()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertTrue('file 1 config_owned "test1" ' in output[1])
+
+    def test_can_rm(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.0')
+        contents.read()
+        contents.ignore += ['.svn']
+
+        self.assertEqual(contents.get_canremove('/'.join((HERE, 'testfiles',
+                         'contents', 'inc'))), '!found inc')
+
+        self.assertEqual(contents.get_canremove('/'.join((HERE, 'testfiles',
+                         'contents', 'inc', 'prefs.php'))),
+                         '!found inc/prefs.php')
+
+    def test_read_clean(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.0')
+        contents.read()
+        contents.db_print()
+
+        output = sys.stdout.getvalue().split('\n')
+
+        self.assertTrue('file 1 virtual signup.php ' in output[3])
+        self.assertEqual(contents.get_directories()[1], '/'.join((HERE,
+                                                                  'testfiles',
+                                                                  'contents',
+                                                                  'inc')))
+
+    def test_read_corrupt(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.1')
+
+        OUT.color_off()
+        contents.read()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[12], '* Not enough entries.')
+
+    def test_write(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.0', pretend = True)
+        OUT.color_off()
+        contents.read()
+
+        contents.write()
+        output = sys.stdout.getvalue().split('\n')
+
+        expected = '* Would have written content file ' + '/'.join((HERE,
+                                                          'testfiles',
+                                                          'contents',
+                                                          '.webapp-test-1.0!'))
+        self.assertEqual(output[0], expected)
+
+
+if __name__ == '__main__':
+    filterwarnings('ignore')
+    unittest.main(module=__name__, buffer=True)
+    resetwarnings()


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:58 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:58 UTC (permalink / raw
  To: gentoo-commits

commit:     025f3f1647b4612f3673dd4d6bdc6e86bc4388e8
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 31 14:11:20 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Mon Nov 17 23:57:54 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=025f3f16

Adds WebappDB and WebappSource tests to external test suite

tests/dtest.py: Removes WebappConfig.db from doctest listing
tests/external.py: Adds tests for WebappDB and WebappSource classes
db.py: Removes doctests

---
 WebappConfig/db.py             | 174 -----------------------------------------
 WebappConfig/tests/dtest.py    |   2 -
 WebappConfig/tests/external.py | 121 ++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 176 deletions(-)

diff --git a/WebappConfig/db.py b/WebappConfig/db.py
index aa33ac5..0fbd34a 100644
--- a/WebappConfig/db.py
+++ b/WebappConfig/db.py
@@ -162,100 +162,6 @@ class WebappDB(AppHierarchy):
     '''
     The DataBase class handles a file-oriented data base that stores
     information about virtual installs of web applications.
-
-    Some test files are needed to test the functionality. This localizes
-    the current position:
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-
-    Deactivates color output which is bad for the doctest
-
-    >>> OUT.color_off()
-
-    Initialize the class:
-
-    >>> a = WebappDB(root = here + '/tests/testfiles/webapps')
-
-    This lists the database:
-    >>> a.listinstalls()
-    /var/www/localhost/htdocs/gallery
-    /var/www/localhost/htdocs/horde
-    /var/www/localhost/htdocs/phpldapadmin
-
-    Which is also possible in a more user friendly way:
-
-    >>> b = WebappDB(root = here + '/tests/testfiles/webapps', verbose = True)
-    >>> b.listinstalls()
-    * Installs for gallery-1.4.4_p6
-    *   /var/www/localhost/htdocs/gallery
-    * Installs for horde-3.0.5
-    *   /var/www/localhost/htdocs/horde
-    * Installs for phpldapadmin-0.9.7_alpha4
-    *   /var/www/localhost/htdocs/phpldapadmin
-
-    The function 'get_inst_files' handles the file locations within the
-    database. If no package has been specified while initializing
-    the database, the funtion will return all files available:
-
-    (code will only return package and varsion since the actual path
-     varies whith your code location)
-
-    >>> sb = [i[1] for i in b.list_locations().items()]
-    >>> sb.sort(key=lambda x: x[0]+x[1]+x[2])
-    >>> sb
-    [['', 'gallery', '1.4.4_p6'], ['', 'gallery', '2.0_rc2'], ['', 'horde', '3.0.5'], ['', 'phpldapadmin', '0.9.7_alpha4']]
-
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'horde', version = '3.0.5')
-    >>> [i[1] for i in c.list_locations().items()]
-    [['', 'horde', '3.0.5']]
-
-    Package specifiers that do not map to an install file will yield
-    an empty result and a warning.
-
-    The warning is turned off for the example:
-    >>> OUT.warn_off()
-
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'garbish', version = '3.0.5')
-    >>> [i[1] for i in c.list_locations().items()]
-    []
-
-    Package specifiers that do not map to an install file will yield
-    an empty result and a warning:
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'horde', version = '8.1.1')
-    >>> [i[1] for i in c.list_locations().items()]
-    []
-
-    The warning is turned off for the example:
-    >>> OUT.warn_on()
-
-    Virtual installs can be added or removed using the corresponding
-    functions (the example will just pretend to write):
-
-    >>> d = WebappDB(root = here + '/tests/testfiles/webapps', pretend = True,
-    ...              package = 'horde', version = '3.0.5')
-    >>> d.add('/my/really/weird/hierarchy/for/horde', #doctest: +ELLIPSIS
-    ...       user = 'me', group = 'me')
-    * Pretended to append installation /my/really/weird/hierarchy/for/horde
-    * Entry:
-    * ... me me /my/really/weird/hierarchy/for/horde
-    * 
-    >>> d.remove('/var/www/localhost/htdocs/horde')
-    * Pretended to remove installation /var/www/localhost/htdocs/horde
-    * Final DB content:
-    * 
-    * 
-
-    >>> d.remove('/my/really/weird/hierarchy/for/horde')  #doctest: +ELLIPSIS
-    * Installation at "/my/really/weird/hierarchy/for/horde" could not be found in the database file. Check the entries in ".../tests/testfiles/webapps/horde/3.0.5/installs"!
-    * Pretended to remove installation /my/really/weird/hierarchy/for/horde
-    * Final DB content:
-    * 1124612110 root root /var/www/localhost/htdocs/horde
-    * 
-
     '''
 
     def __init__(self,
@@ -507,28 +413,6 @@ class WebappSource(AppHierarchy):
     '''
     The WebappSource class handles a web application hierarchy under
     /usr/share/webapps.
-
-    Some test files are needed to test the functionality. This localizes
-    the current position:
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-
-    Initialize the class:
-
-    >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',)
-
-    A WebappDB class is needed to retrive information about installed
-    packages:
-    >>> b = WebappDB(root = here + '/tests/testfiles/webapps')
-
-    This lists the database:
-    >>> a.listunused(b)
-    share-webapps/horde-3.0.5
-    share-webapps/installtest-1.0
-    share-webapps/uninstalled-6.6.6
-
-
     '''
 
     def __init__(self,
@@ -561,19 +445,6 @@ class WebappSource(AppHierarchy):
              default_dirs  = 'default-owned'):
         '''
         Initialize the type cache.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root=here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-
-        >>> a.read()
-        >>> a.filetype('test1')
-        'config-owned'
-
-        >>> a.filetype('test2')
-        'server-owned'
-
         '''
         import WebappConfig.filetype
 
@@ -621,17 +492,6 @@ class WebappSource(AppHierarchy):
         '''
         Checks if the specified source directory exists within the
         application directory.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-
-        >>> a.source_exists('htdocs')
-        True
-
-        >>> a.source_exists('test')
-        False
         '''
         if self.appdir() and os.path.isdir(self.appdir()
                                             + '/' + directory):
@@ -642,14 +502,6 @@ class WebappSource(AppHierarchy):
         '''
         Lists the directories provided by the source directory
         'directory'
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-        >>> d = a.get_source_directories('htdocs')
-        >>> [i for i in d if i != '.svn']
-        ['dir1', 'dir2']
         '''
         dirs = []
 
@@ -675,13 +527,6 @@ class WebappSource(AppHierarchy):
         '''
         Lists the files provided by the source directory
         'directory'
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-        >>> a.get_source_files('htdocs')
-        ['test1', 'test2']
         '''
 
         files = []
@@ -743,20 +588,6 @@ class WebappSource(AppHierarchy):
             1       - package not found
             2       - no package to find
             3       - package isn't webapp-config compatible          '
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        Does not exist:
-
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='www-apps',package='nothere', version='1',pm='portage')
-        >>> a.packageavail()
-        1
-
-        Incompatible cannot be tested since that would require a
-        oackage (including version number) that is installed on
-        all systems.
         '''
 
         OUT.debug('Verifying package ' + self.package_name(), 6)
@@ -768,7 +599,6 @@ class WebappSource(AppHierarchy):
             package = self.category + '/' + self.pn
 
         # not using self.package_name() here as we don't need pvr
-        if not wrapper.package_installed(package, self.pm):
             return 1
 
         # unfortunately, just because a package has been installed, it
@@ -802,7 +632,3 @@ class WebappSource(AppHierarchy):
             OUT.die('  ' + self.package_name() + ' is not compatible with '
                     'webapp-config.\nIf it should be, report this at '
                     + wrapper.bugs_link)
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

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

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
index 7d8bbdc..3263c1a 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -23,6 +23,7 @@ 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
 
@@ -131,6 +132,126 @@ class ContentsTest(unittest.TestCase):
                                                           '.webapp-test-1.0!'))
         self.assertEqual(output[0], expected)
 
+class WebappDBTest(unittest.TestCase):
+    def test_list_installs(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+
+        db.listinstalls()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[1], '/var/www/localhost/htdocs/horde')
+
+        # Now test the verbosity:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      verbose = True)
+        db.listinstalls()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[5], '* Installs for horde-3.0.5')
+
+    def test_list_locations(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        sorted_db.sort(key=lambda x: x[0]+x[1]+x[2])
+
+        self.assertEqual(sorted_db[1], ['', 'gallery', '2.0_rc2'])
+
+        # Now test with a specific package and version:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      package = 'horde', version = '3.0.5')
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        self.assertEqual(sorted_db, [['', 'horde', '3.0.5']])
+
+        # Now test with an install file that doesn't exist:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      package = 'nihil', version = '3.0.5')
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        self.assertEqual(sorted_db, [])
+        
+    def test_add_rm(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      pretend = True, package = 'horde', version = '3.0.5')
+        # Test adding:
+        db.add('/'.join(('/screwy', 'wonky', 'foobar', 'horde', 'hierarchy')),
+               user = 'me', group = 'me')
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[0], '* Pretended to append installation '\
+                                    '/screwy/wonky/foobar/horde/hierarchy')
+
+        # Test deleting a webapp that is actually in the database:
+        db.remove('/'.join(('/var', 'www', 'localhost', 'htdocs', 'horde')))
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[6], '* ')
+
+        # And now test deleting one that isn't:
+        db.remove('/'.join(('/screwy', 'wonky', 'foobar', 'horde', 'hierarchy')))
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[11], '* 1124612110 root root '\
+                                     '/var/www/localhost/htdocs/horde')
+
+
+class WebappSourceTest(unittest.TestCase):
+        SHARE = '/'.join((HERE, 'testfiles', 'share-webapps'))
+        def test_list_unused(self):
+            source = WebappSource(root = '/'.join((HERE,
+                                                  'testfiles',
+                                                  'share-webapps')))
+            db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+            source.listunused(db)
+            output = sys.stdout.getvalue().split('\n')
+            self.assertEqual(output[2], 'share-webapps/uninstalled-6.6.6')
+
+        def test_read(self):
+            source = WebappSource(root = '/'.join((HERE,
+                                                   'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+
+            source.read()
+            self.assertEqual(source.filetype('test1'), 'config-owned')
+            self.assertEqual(source.filetype('test2'), 'server-owned')
+
+        def test_src_exists(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            self.assertTrue(source.source_exists('htdocs'))
+            self.assertFalse(source.source_exists('foobar'))
+
+        def test_get_src_dirs(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            dirs = source.get_source_directories('htdocs')
+            dirs = [i for i in dirs if i != '.svn']
+            self.assertEqual(dirs, ['dir1', 'dir2'])
+
+        def test_get_src_files(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            files = source.get_source_files('htdocs')
+            self.assertEqual(files, ['test1', 'test2'])
+
+        def test_pkg_avail(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'nihil',
+                                  version = '3.0.5',
+                                  pm = 'portage')
+            self.assertEqual(source.packageavail(), 1)
+
 
 if __name__ == '__main__':
     filterwarnings('ignore')


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:42 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:42 UTC (permalink / raw
  To: gentoo-commits

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()


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:42 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:42 UTC (permalink / raw
  To: gentoo-commits

commit:     4cd947392b9885ffa702e45782be776835948e76
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: Mon Nov 17 23:42:41 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=4cd94739

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 3216dd5..3ad53e5 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__))
@@ -421,6 +422,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] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:42 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:42 UTC (permalink / raw
  To: gentoo-commits

commit:     e7783e2f47a0a5b7757488d2f1868b57075cf184
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 30 15:54:47 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Mon Nov 17 23:42:39 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=e7783e2f

Adds beginning stages of external test suite

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

---
 WebappConfig/content.py        | 165 -----------------------------------------
 WebappConfig/tests/dtest.py    |   2 -
 WebappConfig/tests/external.py | 139 ++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+), 167 deletions(-)

diff --git a/WebappConfig/content.py b/WebappConfig/content.py
index e157d23..a582396 100644
--- a/WebappConfig/content.py
+++ b/WebappConfig/content.py
@@ -131,58 +131,6 @@ class Contents:
     def read(self):
         '''
         Reads the contents database.
-
-        Some content files have been provided for test purposes:
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        This one should succeed:
-
-        >>> a = Contents(here + '/tests/testfiles/contents/',
-        ...              package = 'test', version = '1.0')
-        >>> a.read()
-        >>> a.db_print()
-        file 1 virtual util/icon_browser.php 1124612216 9ffb2ca9ccd2db656b97cd26a1b06010 
-        file 1 config-owned inc/prefs.php 1124612215 ffae752dba7092cd2d1553d04a0f0045 
-        file 1 virtual lib/prefs.php 1124612215 ffae752dba7092cd2d1553d04a0f0045 
-        file 1 virtual signup.php 1124612220 dc838bc375b3d02dafc414f8e71a2aec 
-        file 1 server-owned data.php 1117009618 0 
-        sym 1 virtual test 1124612220 dc838bc375b3d02dafc414f8e71a2aec /I link / to a very / strange location
-        dir 1 default-owned util 1117009618 0 
-        dir 1 config-owned inc 1117009618 0 
-        dir 1 default-owned lib 1117009618 0 
-        dir 0 default-owned /var/www/localhost/cgi-bin 1124577741 0 
-        dir 0 default-owned /var/www/localhost/error 1124577740 0 
-        dir 0 default-owned /var/www/localhost/icons 1124577741 0 
-        
-        >>> a.get_directories() #doctest: +ELLIPSIS
-        ['.../contents//util', '.../contents//inc', '.../contents//lib', '/var/www/localhost/cgi-bin', '/var/www/localhost/error', '/var/www/localhost/icons']
-
-        This is a corrupted file that checks all fail safes:
-
-        >>> OUT.color_off()
-        >>> a = Contents(here + '/tests/testfiles/contents/',
-        ...              package = 'test', version = '1.1')
-        >>> a.read() #doctest: +ELLIPSIS
-        * Invalid line in content file (dir 1 default-owned). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * dir 1 nobody-owned  1117009618 0
-        * Invalid owner: nobody-owned
-        * Invalid line in content file (dir 1 nobody-owned  1117009618 0). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * garbage 1 virtual  1124612215 ffae752dba7092cd2d1553d04a0f0045
-        * Invalid file type: garbage
-        * Invalid line in content file (garbage 1 virtual  1124612215 ffae752dba7092cd2d1553d04a0f0045). Ignoring!
-        * Invalid line in content file (file 1 virtual). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * file 1 virtual 
-        * Not enough entries.
-        * Invalid line in content file (file 1 virtual ). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * file 31 config-owned  1124612215 ffae752dba7092cd2d1553d04a0f0045
-        * Invalid relative flag: 31
-        * Invalid line in content file (file 31 config-owned  1124612215 ffae752dba7092cd2d1553d04a0f0045). Ignoring!
         '''
 
         dbpath = self.appdb()
@@ -270,18 +218,6 @@ class Contents:
     def write(self):
         '''
         Write the contents file.
-
-        A short test:
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = Contents(here + '/tests/testfiles/contents/',
-        ...              package = 'test', version = '1.0',
-        ...              pretend = True)
-        >>> a.read()
-        >>> OUT.color_off()
-        >>> a.write() #doctest: +ELLIPSIS
-        * Would have written content file .../tests/testfiles/contents//.webapp-test-1.0!
         '''
 
         dbpath = self.appdb()
@@ -378,77 +314,6 @@ class Contents:
           real_path   - for config-protected files realpath =! path
                         (and this is important for md5)
           relative    - 1 for storing a relative filename, 0 otherwise
-
-        OUT.color_off()
-        import os.path
-        here = os.path.dirname(os.path.realpath(__file__))
-
-        One for pretending:
-
-        a = Contents(here + '/tests/testfiles/contents/app/',
-        ...              package = 'test', version = '1.0',
-        ...              pretend = True)
-
-        And this one is for real:
-
-        b = Contents(here + '/tests/testfiles/contents/app/',
-        ...              package = 'test', version = '1.0')
-
-        Pretend to add a file:
-
-        a.add('file', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test1', relative = True)
-        *     pretending to add: file 1 config-owned "test1"
-
-        Lets not pretend this time:
-
-        b.add('file', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test1', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/test1') #doctest: +ELLIPSIS
-        'file 1 config-owned "test1" ... d8e8fca2dc0f896fd7cb4cb0031ba249 '
-
-        Lets produce an error with a file that does not exist:
-
-        b.add('file', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/nothere', relative = True) #doctest: +ELLIPSIS
-        * Cannot access file .../tests/testfiles/contents/app/nothere to add it as installation content. This should not happen!
-
-        Other file types:
-
-        b.add('hardlink', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test2', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/test2') #doctest: +ELLIPSIS
-        'file 1 config-owned "test2" ... d8e8fca2dc0f896fd7cb4cb0031ba249 '
-        b.add('dir', 'default-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/dir1', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/dir1') #doctest: +ELLIPSIS
-        'dir 1 default-owned "dir1" ... 0 '
-        b.add('dir', 'default-owned', destination = here + '/tests/testfiles/contents/app',
-        ...       path = '/dir1',
-        ...       relative = False)
-        b.entry(here + '/tests/testfiles/contents/app/dir1') #doctest: +ELLIPSIS
-        'dir 0 default-owned ".../tests/testfiles/contents/app/dir1" ... 0 '
-
-        Q: Is the full link to the target what we want?
-        A: Yes, since the link will still be ok even if we move the directory.
-
-        b.add('sym', 'virtual',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test3', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/test3') #doctest: +ELLIPSIS
-        'sym 1 virtual "test3" ... 0 .../tests/testfiles/contents/app/test1'
-
-        b.db_print() #doctest: +ELLIPSIS
-        file 1 config-owned "test1" ... d8e8fca2dc0f896fd7cb4cb0031ba249 
-        file 1 config-owned "test2" ... d8e8fca2dc0f896fd7cb4cb0031ba249 
-        sym 1 virtual "test3" ... 0 .../tests/testfiles/contents/app/test1
-        dir 0 default-owned ".../tests/testfiles/contents/app/dir1" ... 0 
-
         '''
 
         OUT.debug('Adding entry to content dictionary', 6)
@@ -574,32 +439,6 @@ class Contents:
 
         In case the entry can be removed nothing will be
         returned.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        Trying to remove the contents:
-
-        >>> a = Contents(here + '/tests/testfiles/contents/app/',
-        ...              package = 'test', version = '1.0')
-        >>> a.read()
-        >>> a.ignore += ['.svn']
-        >>> for i in a.get_directories():
-        ...     a.get_canremove(i)
-        '!dir test7'
-        '!empty dir1'
-
-        >>> for i in a.get_files():
-        ...     a.get_canremove(i)
-        '!time test2'
-        '!time test4'
-        '!found test6'
-        '!sym dir3'
-        '!file dir4'
-
-        # Disabled 
-        #'!target test3'
-
         '''
 
         OUT.debug('Checking if the file can be removed', 6)
@@ -746,7 +585,3 @@ class Contents:
             return self.__content[entry][6]
         else:
             raise Exception('Unknown file "' + entry + '"')
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

diff --git a/WebappConfig/tests/dtest.py b/WebappConfig/tests/dtest.py
index 8ad3188..61d3f89 100644
--- a/WebappConfig/tests/dtest.py
+++ b/WebappConfig/tests/dtest.py
@@ -8,7 +8,6 @@
 
 import unittest, doctest, sys
 
-import WebappConfig.content
 import WebappConfig.db
 import WebappConfig.dotconfig
 import WebappConfig.ebuild
@@ -18,7 +17,6 @@ import WebappConfig.worker
 
 def test_suite():
     return unittest.TestSuite((
-        doctest.DocTestSuite(WebappConfig.content),
         doctest.DocTestSuite(WebappConfig.db),
         doctest.DocTestSuite(WebappConfig.dotconfig),
         doctest.DocTestSuite(WebappConfig.ebuild),

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
new file mode 100755
index 0000000..be536df
--- /dev/null
+++ b/WebappConfig/tests/external.py
@@ -0,0 +1,139 @@
+# -*- coding: utf-8 -*-
+################################################################################
+# EXTERNAL WEBAPP-CONFIG TESTS
+################################################################################
+# File:       external.py
+#
+#             Runs external (non-doctest) test cases.
+#
+# Copyright:
+#             (c) 2014        Devan Franchini
+#             Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+#             Devan Franchini <twitch153@gentoo.org>
+#
+
+from __future__ import print_function
+
+'''Runs external (non-doctest) test cases.'''
+
+import os
+import unittest
+import sys
+
+from  WebappConfig.content import Contents
+from  WebappConfig.debug   import OUT
+from  warnings             import filterwarnings, resetwarnings
+
+HERE = os.path.dirname(os.path.realpath(__file__))
+
+class ContentsTest(unittest.TestCase):
+    def test_add_pretend(self):
+        loc = '/'.join((HERE, 'testfiles', 'contents', 'app'))
+        contents = Contents(loc, package = 'test', version = '1.0',
+                            pretend = True)
+        OUT.color_off()
+        contents.add('file', 'config_owned', destination = loc, path = '/test1',
+                     real_path = loc + '/test1', relative = True)
+
+        output = sys.stdout.getvalue().strip('\n')
+        self.assertEqual(output,
+                       '*     pretending to add: file 1 config_owned "test1"')
+
+    def test_add(self):
+        loc = '/'.join((HERE, 'testfiles', 'contents', 'app'))
+        contents = Contents(loc, package = 'test', version = '1.0')
+        OUT.color_off()
+        contents.add('file', 'config_owned', destination = loc, path = '/test1',
+                     real_path = loc + '/test1', relative = True)
+
+        # Now trigger an error by adding a file that doesn't exist!
+        contents.add('file', 'config_owned', destination = loc, path = '/test0',
+                     real_path = loc + '/test0', relative = True)
+
+        output = sys.stdout.getvalue().strip('\n')
+
+        self.assertTrue('workspace/webapp-config/WebappConfig'\
+                        '/tests/testfiles/contents/app/test0 to add '\
+                        'it as installation content. This should not '\
+                        'happen!' in output)
+
+        # Test adding hardlinks:
+        contents.add('hardlink', 'config_owned', destination = loc,
+                     path = '/test2', real_path = loc + '/test2', relative = True)
+        self.assertTrue('file 1 config_owned "test2" ' in contents.entry(loc +
+                                                                      '/test2'))
+        # Test adding dirs:
+        contents.add('dir', 'default_owned', destination = loc, path = '/dir1',
+                     real_path = loc + '/dir1', relative = True)
+        self.assertTrue('dir 1 default_owned "dir1" ' in contents.entry(loc +
+                                                                       '/dir1'))
+
+        # Test adding symlinks:
+        contents.add('sym', 'virtual', destination = loc, path = '/test3',
+                     real_path = loc + '/test3', relative = True)
+        self.assertTrue('sym 1 virtual "test3" ' in contents.entry(loc +
+                                                                   '/test3'))
+
+        # Printing out the db after adding these entries:
+        contents.db_print()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertTrue('file 1 config_owned "test1" ' in output[1])
+
+    def test_can_rm(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.0')
+        contents.read()
+        contents.ignore += ['.svn']
+
+        self.assertEqual(contents.get_canremove('/'.join((HERE, 'testfiles',
+                         'contents', 'inc'))), '!found inc')
+
+        self.assertEqual(contents.get_canremove('/'.join((HERE, 'testfiles',
+                         'contents', 'inc', 'prefs.php'))),
+                         '!found inc/prefs.php')
+
+    def test_read_clean(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.0')
+        contents.read()
+        contents.db_print()
+
+        output = sys.stdout.getvalue().split('\n')
+
+        self.assertTrue('file 1 virtual signup.php ' in output[3])
+        self.assertEqual(contents.get_directories()[1], '/'.join((HERE,
+                                                                  'testfiles',
+                                                                  'contents',
+                                                                  'inc')))
+
+    def test_read_corrupt(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.1')
+
+        OUT.color_off()
+        contents.read()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[12], '* Not enough entries.')
+
+    def test_write(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.0', pretend = True)
+        OUT.color_off()
+        contents.read()
+
+        contents.write()
+        output = sys.stdout.getvalue().split('\n')
+
+        expected = '* Would have written content file ' + '/'.join((HERE,
+                                                          'testfiles',
+                                                          'contents',
+                                                          '.webapp-test-1.0!'))
+        self.assertEqual(output[0], expected)
+
+
+if __name__ == '__main__':
+    filterwarnings('ignore')
+    unittest.main(module=__name__, buffer=True)
+    resetwarnings()


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:42 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:42 UTC (permalink / raw
  To: gentoo-commits

commit:     be9bf4998f74961d43028bf9fa69916b220e879d
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 31 14:11:20 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Mon Nov 17 23:42:40 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=be9bf499

Adds WebappDB and WebappSource tests to external test suite

tests/dtest.py: Removes WebappConfig.db from doctest listing
tests/external.py: Adds tests for WebappDB and WebappSource classes
db.py: Removes doctests

---
 WebappConfig/db.py             | 174 -----------------------------------------
 WebappConfig/tests/dtest.py    |   2 -
 WebappConfig/tests/external.py | 121 ++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 176 deletions(-)

diff --git a/WebappConfig/db.py b/WebappConfig/db.py
index aa33ac5..0fbd34a 100644
--- a/WebappConfig/db.py
+++ b/WebappConfig/db.py
@@ -162,100 +162,6 @@ class WebappDB(AppHierarchy):
     '''
     The DataBase class handles a file-oriented data base that stores
     information about virtual installs of web applications.
-
-    Some test files are needed to test the functionality. This localizes
-    the current position:
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-
-    Deactivates color output which is bad for the doctest
-
-    >>> OUT.color_off()
-
-    Initialize the class:
-
-    >>> a = WebappDB(root = here + '/tests/testfiles/webapps')
-
-    This lists the database:
-    >>> a.listinstalls()
-    /var/www/localhost/htdocs/gallery
-    /var/www/localhost/htdocs/horde
-    /var/www/localhost/htdocs/phpldapadmin
-
-    Which is also possible in a more user friendly way:
-
-    >>> b = WebappDB(root = here + '/tests/testfiles/webapps', verbose = True)
-    >>> b.listinstalls()
-    * Installs for gallery-1.4.4_p6
-    *   /var/www/localhost/htdocs/gallery
-    * Installs for horde-3.0.5
-    *   /var/www/localhost/htdocs/horde
-    * Installs for phpldapadmin-0.9.7_alpha4
-    *   /var/www/localhost/htdocs/phpldapadmin
-
-    The function 'get_inst_files' handles the file locations within the
-    database. If no package has been specified while initializing
-    the database, the funtion will return all files available:
-
-    (code will only return package and varsion since the actual path
-     varies whith your code location)
-
-    >>> sb = [i[1] for i in b.list_locations().items()]
-    >>> sb.sort(key=lambda x: x[0]+x[1]+x[2])
-    >>> sb
-    [['', 'gallery', '1.4.4_p6'], ['', 'gallery', '2.0_rc2'], ['', 'horde', '3.0.5'], ['', 'phpldapadmin', '0.9.7_alpha4']]
-
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'horde', version = '3.0.5')
-    >>> [i[1] for i in c.list_locations().items()]
-    [['', 'horde', '3.0.5']]
-
-    Package specifiers that do not map to an install file will yield
-    an empty result and a warning.
-
-    The warning is turned off for the example:
-    >>> OUT.warn_off()
-
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'garbish', version = '3.0.5')
-    >>> [i[1] for i in c.list_locations().items()]
-    []
-
-    Package specifiers that do not map to an install file will yield
-    an empty result and a warning:
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'horde', version = '8.1.1')
-    >>> [i[1] for i in c.list_locations().items()]
-    []
-
-    The warning is turned off for the example:
-    >>> OUT.warn_on()
-
-    Virtual installs can be added or removed using the corresponding
-    functions (the example will just pretend to write):
-
-    >>> d = WebappDB(root = here + '/tests/testfiles/webapps', pretend = True,
-    ...              package = 'horde', version = '3.0.5')
-    >>> d.add('/my/really/weird/hierarchy/for/horde', #doctest: +ELLIPSIS
-    ...       user = 'me', group = 'me')
-    * Pretended to append installation /my/really/weird/hierarchy/for/horde
-    * Entry:
-    * ... me me /my/really/weird/hierarchy/for/horde
-    * 
-    >>> d.remove('/var/www/localhost/htdocs/horde')
-    * Pretended to remove installation /var/www/localhost/htdocs/horde
-    * Final DB content:
-    * 
-    * 
-
-    >>> d.remove('/my/really/weird/hierarchy/for/horde')  #doctest: +ELLIPSIS
-    * Installation at "/my/really/weird/hierarchy/for/horde" could not be found in the database file. Check the entries in ".../tests/testfiles/webapps/horde/3.0.5/installs"!
-    * Pretended to remove installation /my/really/weird/hierarchy/for/horde
-    * Final DB content:
-    * 1124612110 root root /var/www/localhost/htdocs/horde
-    * 
-
     '''
 
     def __init__(self,
@@ -507,28 +413,6 @@ class WebappSource(AppHierarchy):
     '''
     The WebappSource class handles a web application hierarchy under
     /usr/share/webapps.
-
-    Some test files are needed to test the functionality. This localizes
-    the current position:
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-
-    Initialize the class:
-
-    >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',)
-
-    A WebappDB class is needed to retrive information about installed
-    packages:
-    >>> b = WebappDB(root = here + '/tests/testfiles/webapps')
-
-    This lists the database:
-    >>> a.listunused(b)
-    share-webapps/horde-3.0.5
-    share-webapps/installtest-1.0
-    share-webapps/uninstalled-6.6.6
-
-
     '''
 
     def __init__(self,
@@ -561,19 +445,6 @@ class WebappSource(AppHierarchy):
              default_dirs  = 'default-owned'):
         '''
         Initialize the type cache.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root=here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-
-        >>> a.read()
-        >>> a.filetype('test1')
-        'config-owned'
-
-        >>> a.filetype('test2')
-        'server-owned'
-
         '''
         import WebappConfig.filetype
 
@@ -621,17 +492,6 @@ class WebappSource(AppHierarchy):
         '''
         Checks if the specified source directory exists within the
         application directory.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-
-        >>> a.source_exists('htdocs')
-        True
-
-        >>> a.source_exists('test')
-        False
         '''
         if self.appdir() and os.path.isdir(self.appdir()
                                             + '/' + directory):
@@ -642,14 +502,6 @@ class WebappSource(AppHierarchy):
         '''
         Lists the directories provided by the source directory
         'directory'
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-        >>> d = a.get_source_directories('htdocs')
-        >>> [i for i in d if i != '.svn']
-        ['dir1', 'dir2']
         '''
         dirs = []
 
@@ -675,13 +527,6 @@ class WebappSource(AppHierarchy):
         '''
         Lists the files provided by the source directory
         'directory'
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-        >>> a.get_source_files('htdocs')
-        ['test1', 'test2']
         '''
 
         files = []
@@ -743,20 +588,6 @@ class WebappSource(AppHierarchy):
             1       - package not found
             2       - no package to find
             3       - package isn't webapp-config compatible          '
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        Does not exist:
-
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='www-apps',package='nothere', version='1',pm='portage')
-        >>> a.packageavail()
-        1
-
-        Incompatible cannot be tested since that would require a
-        oackage (including version number) that is installed on
-        all systems.
         '''
 
         OUT.debug('Verifying package ' + self.package_name(), 6)
@@ -768,7 +599,6 @@ class WebappSource(AppHierarchy):
             package = self.category + '/' + self.pn
 
         # not using self.package_name() here as we don't need pvr
-        if not wrapper.package_installed(package, self.pm):
             return 1
 
         # unfortunately, just because a package has been installed, it
@@ -802,7 +632,3 @@ class WebappSource(AppHierarchy):
             OUT.die('  ' + self.package_name() + ' is not compatible with '
                     'webapp-config.\nIf it should be, report this at '
                     + wrapper.bugs_link)
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

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

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
index be536df..0ca39f2 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -23,6 +23,7 @@ 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
 
@@ -132,6 +133,126 @@ class ContentsTest(unittest.TestCase):
                                                           '.webapp-test-1.0!'))
         self.assertEqual(output[0], expected)
 
+class WebappDBTest(unittest.TestCase):
+    def test_list_installs(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+
+        db.listinstalls()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[1], '/var/www/localhost/htdocs/horde')
+
+        # Now test the verbosity:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      verbose = True)
+        db.listinstalls()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[5], '* Installs for horde-3.0.5')
+
+    def test_list_locations(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        sorted_db.sort(key=lambda x: x[0]+x[1]+x[2])
+
+        self.assertEqual(sorted_db[1], ['', 'gallery', '2.0_rc2'])
+
+        # Now test with a specific package and version:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      package = 'horde', version = '3.0.5')
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        self.assertEqual(sorted_db, [['', 'horde', '3.0.5']])
+
+        # Now test with an install file that doesn't exist:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      package = 'nihil', version = '3.0.5')
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        self.assertEqual(sorted_db, [])
+        
+    def test_add_rm(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      pretend = True, package = 'horde', version = '3.0.5')
+        # Test adding:
+        db.add('/'.join(('/screwy', 'wonky', 'foobar', 'horde', 'hierarchy')),
+               user = 'me', group = 'me')
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[0], '* Pretended to append installation '\
+                                    '/screwy/wonky/foobar/horde/hierarchy')
+
+        # Test deleting a webapp that is actually in the database:
+        db.remove('/'.join(('/var', 'www', 'localhost', 'htdocs', 'horde')))
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[6], '* ')
+
+        # And now test deleting one that isn't:
+        db.remove('/'.join(('/screwy', 'wonky', 'foobar', 'horde', 'hierarchy')))
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[11], '* 1124612110 root root '\
+                                     '/var/www/localhost/htdocs/horde')
+
+
+class WebappSourceTest(unittest.TestCase):
+        SHARE = '/'.join((HERE, 'testfiles', 'share-webapps'))
+        def test_list_unused(self):
+            source = WebappSource(root = '/'.join((HERE,
+                                                  'testfiles',
+                                                  'share-webapps')))
+            db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+            source.listunused(db)
+            output = sys.stdout.getvalue().split('\n')
+            self.assertEqual(output[2], 'share-webapps/uninstalled-6.6.6')
+
+        def test_read(self):
+            source = WebappSource(root = '/'.join((HERE,
+                                                   'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+
+            source.read()
+            self.assertEqual(source.filetype('test1'), 'config-owned')
+            self.assertEqual(source.filetype('test2'), 'server-owned')
+
+        def test_src_exists(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            self.assertTrue(source.source_exists('htdocs'))
+            self.assertFalse(source.source_exists('foobar'))
+
+        def test_get_src_dirs(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            dirs = source.get_source_directories('htdocs')
+            dirs = [i for i in dirs if i != '.svn']
+            self.assertEqual(dirs, ['dir1', 'dir2'])
+
+        def test_get_src_files(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            files = source.get_source_files('htdocs')
+            self.assertEqual(files, ['test1', 'test2'])
+
+        def test_pkg_avail(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'nihil',
+                                  version = '3.0.5',
+                                  pm = 'portage')
+            self.assertEqual(source.packageavail(), 1)
+
 
 if __name__ == '__main__':
     filterwarnings('ignore')


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-17 23:42 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-17 23:42 UTC (permalink / raw
  To: gentoo-commits

commit:     b533f3593795ce9f95656d18e48ca40dd9a77764
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: Mon Nov 17 23:42:40 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=b533f359

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 0ca39f2..75c2eb6 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__))
 
@@ -254,6 +255,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] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-03  0:02 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-03  0:02 UTC (permalink / raw
  To: gentoo-commits

commit:     54ec4c878f63a3c40d0ba83926315882c28f97d4
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  3 00:01:56 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=54ec4c87

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 fc5b627..0c77683 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()


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-03  0:02 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-03  0:02 UTC (permalink / raw
  To: gentoo-commits

commit:     fa9b7583dafa3ef31ece23a87c8d8837f5440c9f
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 30 15:54:47 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Sun Nov  2 23:59:58 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=fa9b7583

Adds beginning stages of external test suite

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

---
 WebappConfig/content.py        | 165 -----------------------------------------
 WebappConfig/tests/dtest.py    |   2 -
 WebappConfig/tests/external.py | 139 ++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+), 167 deletions(-)

diff --git a/WebappConfig/content.py b/WebappConfig/content.py
index e157d23..a582396 100644
--- a/WebappConfig/content.py
+++ b/WebappConfig/content.py
@@ -131,58 +131,6 @@ class Contents:
     def read(self):
         '''
         Reads the contents database.
-
-        Some content files have been provided for test purposes:
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        This one should succeed:
-
-        >>> a = Contents(here + '/tests/testfiles/contents/',
-        ...              package = 'test', version = '1.0')
-        >>> a.read()
-        >>> a.db_print()
-        file 1 virtual util/icon_browser.php 1124612216 9ffb2ca9ccd2db656b97cd26a1b06010 
-        file 1 config-owned inc/prefs.php 1124612215 ffae752dba7092cd2d1553d04a0f0045 
-        file 1 virtual lib/prefs.php 1124612215 ffae752dba7092cd2d1553d04a0f0045 
-        file 1 virtual signup.php 1124612220 dc838bc375b3d02dafc414f8e71a2aec 
-        file 1 server-owned data.php 1117009618 0 
-        sym 1 virtual test 1124612220 dc838bc375b3d02dafc414f8e71a2aec /I link / to a very / strange location
-        dir 1 default-owned util 1117009618 0 
-        dir 1 config-owned inc 1117009618 0 
-        dir 1 default-owned lib 1117009618 0 
-        dir 0 default-owned /var/www/localhost/cgi-bin 1124577741 0 
-        dir 0 default-owned /var/www/localhost/error 1124577740 0 
-        dir 0 default-owned /var/www/localhost/icons 1124577741 0 
-        
-        >>> a.get_directories() #doctest: +ELLIPSIS
-        ['.../contents//util', '.../contents//inc', '.../contents//lib', '/var/www/localhost/cgi-bin', '/var/www/localhost/error', '/var/www/localhost/icons']
-
-        This is a corrupted file that checks all fail safes:
-
-        >>> OUT.color_off()
-        >>> a = Contents(here + '/tests/testfiles/contents/',
-        ...              package = 'test', version = '1.1')
-        >>> a.read() #doctest: +ELLIPSIS
-        * Invalid line in content file (dir 1 default-owned). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * dir 1 nobody-owned  1117009618 0
-        * Invalid owner: nobody-owned
-        * Invalid line in content file (dir 1 nobody-owned  1117009618 0). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * garbage 1 virtual  1124612215 ffae752dba7092cd2d1553d04a0f0045
-        * Invalid file type: garbage
-        * Invalid line in content file (garbage 1 virtual  1124612215 ffae752dba7092cd2d1553d04a0f0045). Ignoring!
-        * Invalid line in content file (file 1 virtual). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * file 1 virtual 
-        * Not enough entries.
-        * Invalid line in content file (file 1 virtual ). Ignoring!
-        * Content file .../tests/testfiles/contents//.webapp-test-1.1 has an invalid line:
-        * file 31 config-owned  1124612215 ffae752dba7092cd2d1553d04a0f0045
-        * Invalid relative flag: 31
-        * Invalid line in content file (file 31 config-owned  1124612215 ffae752dba7092cd2d1553d04a0f0045). Ignoring!
         '''
 
         dbpath = self.appdb()
@@ -270,18 +218,6 @@ class Contents:
     def write(self):
         '''
         Write the contents file.
-
-        A short test:
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = Contents(here + '/tests/testfiles/contents/',
-        ...              package = 'test', version = '1.0',
-        ...              pretend = True)
-        >>> a.read()
-        >>> OUT.color_off()
-        >>> a.write() #doctest: +ELLIPSIS
-        * Would have written content file .../tests/testfiles/contents//.webapp-test-1.0!
         '''
 
         dbpath = self.appdb()
@@ -378,77 +314,6 @@ class Contents:
           real_path   - for config-protected files realpath =! path
                         (and this is important for md5)
           relative    - 1 for storing a relative filename, 0 otherwise
-
-        OUT.color_off()
-        import os.path
-        here = os.path.dirname(os.path.realpath(__file__))
-
-        One for pretending:
-
-        a = Contents(here + '/tests/testfiles/contents/app/',
-        ...              package = 'test', version = '1.0',
-        ...              pretend = True)
-
-        And this one is for real:
-
-        b = Contents(here + '/tests/testfiles/contents/app/',
-        ...              package = 'test', version = '1.0')
-
-        Pretend to add a file:
-
-        a.add('file', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test1', relative = True)
-        *     pretending to add: file 1 config-owned "test1"
-
-        Lets not pretend this time:
-
-        b.add('file', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test1', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/test1') #doctest: +ELLIPSIS
-        'file 1 config-owned "test1" ... d8e8fca2dc0f896fd7cb4cb0031ba249 '
-
-        Lets produce an error with a file that does not exist:
-
-        b.add('file', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/nothere', relative = True) #doctest: +ELLIPSIS
-        * Cannot access file .../tests/testfiles/contents/app/nothere to add it as installation content. This should not happen!
-
-        Other file types:
-
-        b.add('hardlink', 'config-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test2', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/test2') #doctest: +ELLIPSIS
-        'file 1 config-owned "test2" ... d8e8fca2dc0f896fd7cb4cb0031ba249 '
-        b.add('dir', 'default-owned',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/dir1', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/dir1') #doctest: +ELLIPSIS
-        'dir 1 default-owned "dir1" ... 0 '
-        b.add('dir', 'default-owned', destination = here + '/tests/testfiles/contents/app',
-        ...       path = '/dir1',
-        ...       relative = False)
-        b.entry(here + '/tests/testfiles/contents/app/dir1') #doctest: +ELLIPSIS
-        'dir 0 default-owned ".../tests/testfiles/contents/app/dir1" ... 0 '
-
-        Q: Is the full link to the target what we want?
-        A: Yes, since the link will still be ok even if we move the directory.
-
-        b.add('sym', 'virtual',
-        ...       destination = here + '/tests/testfiles/contents/app/',
-        ...       path = '/test3', relative = True)
-        b.entry(here + '/tests/testfiles/contents/app/test3') #doctest: +ELLIPSIS
-        'sym 1 virtual "test3" ... 0 .../tests/testfiles/contents/app/test1'
-
-        b.db_print() #doctest: +ELLIPSIS
-        file 1 config-owned "test1" ... d8e8fca2dc0f896fd7cb4cb0031ba249 
-        file 1 config-owned "test2" ... d8e8fca2dc0f896fd7cb4cb0031ba249 
-        sym 1 virtual "test3" ... 0 .../tests/testfiles/contents/app/test1
-        dir 0 default-owned ".../tests/testfiles/contents/app/dir1" ... 0 
-
         '''
 
         OUT.debug('Adding entry to content dictionary', 6)
@@ -574,32 +439,6 @@ class Contents:
 
         In case the entry can be removed nothing will be
         returned.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        Trying to remove the contents:
-
-        >>> a = Contents(here + '/tests/testfiles/contents/app/',
-        ...              package = 'test', version = '1.0')
-        >>> a.read()
-        >>> a.ignore += ['.svn']
-        >>> for i in a.get_directories():
-        ...     a.get_canremove(i)
-        '!dir test7'
-        '!empty dir1'
-
-        >>> for i in a.get_files():
-        ...     a.get_canremove(i)
-        '!time test2'
-        '!time test4'
-        '!found test6'
-        '!sym dir3'
-        '!file dir4'
-
-        # Disabled 
-        #'!target test3'
-
         '''
 
         OUT.debug('Checking if the file can be removed', 6)
@@ -746,7 +585,3 @@ class Contents:
             return self.__content[entry][6]
         else:
             raise Exception('Unknown file "' + entry + '"')
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

diff --git a/WebappConfig/tests/dtest.py b/WebappConfig/tests/dtest.py
index 8ad3188..61d3f89 100644
--- a/WebappConfig/tests/dtest.py
+++ b/WebappConfig/tests/dtest.py
@@ -8,7 +8,6 @@
 
 import unittest, doctest, sys
 
-import WebappConfig.content
 import WebappConfig.db
 import WebappConfig.dotconfig
 import WebappConfig.ebuild
@@ -18,7 +17,6 @@ import WebappConfig.worker
 
 def test_suite():
     return unittest.TestSuite((
-        doctest.DocTestSuite(WebappConfig.content),
         doctest.DocTestSuite(WebappConfig.db),
         doctest.DocTestSuite(WebappConfig.dotconfig),
         doctest.DocTestSuite(WebappConfig.ebuild),

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
new file mode 100755
index 0000000..6296a34
--- /dev/null
+++ b/WebappConfig/tests/external.py
@@ -0,0 +1,139 @@
+# -*- coding: utf-8 -*-
+################################################################################
+# EXTERNAL WEBAPP-CONFIG TESTS
+################################################################################
+# File:       external.py
+#
+#             Runs external (non-doctest) test cases.
+#
+# Copyright:
+#             (c) 2014        Devan Franchini
+#             Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+#             Devan Franchini <twitch153@gentoo.org>
+#
+
+from __future__ import print_function
+
+'''Runs external (non-doctest) test cases.'''
+
+import os
+import unittest
+import sys
+
+from  WebappConfig.content import Contents
+from  WebappConfig.debug   import OUT
+from  warnings             import filterwarnings, resetwarnings
+
+HERE = os.path.dirname(os.path.realpath(__file__))
+
+class ContentsTest(unittest.TestCase):
+    def test_add_pretend(self):
+        loc = '/'.join((HERE, 'testfiles', 'contents', 'app'))
+        contents = Contents(loc, package = 'test', version = '1.0',
+                            pretend = True)
+        OUT.color_off()
+        contents.add('file', 'config_owned', destination = loc, path = '/test1',
+                     real_path = loc + '/test1', relative = True)
+
+        output = sys.stdout.getvalue().strip('\n')
+        self.assertEqual(output,
+                       '*     pretending to add: file 1 config_owned "test1"')
+
+    def test_add(self):
+        loc = '/'.join((HERE, 'testfiles', 'contents', 'app'))
+        contents = Contents(loc, package = 'test', version = '1.0')
+        OUT.color_off()
+        contents.add('file', 'config_owned', destination = loc, path = '/test1',
+                     real_path = loc + '/test1', relative = True)
+
+        # Now trigger an error by adding a file that doesn't exist!
+        contents.add('file', 'config_owned', destination = loc, path = '/test0',
+                     real_path = loc + '/test0', relative = True)
+
+        output = sys.stdout.getvalue().strip('\n')
+
+        self.assertEqual(output, '* Cannot access file /home/twitch153/'\
+                                 'workspace/webapp-config/WebappConfig'\
+                                 '/tests/testfiles/contents/app/test0 to add '\
+                                 'it as installation content. This should not '\
+                                 'happen!')
+        # Test adding hardlinks:
+        contents.add('hardlink', 'config_owned', destination = loc,
+                     path = '/test2', real_path = loc + '/test2', relative = True)
+        self.assertTrue('file 1 config_owned "test2" ' in contents.entry(loc +
+                                                                      '/test2'))
+        # Test adding dirs:
+        contents.add('dir', 'default_owned', destination = loc, path = '/dir1',
+                     real_path = loc + '/dir1', relative = True)
+        self.assertTrue('dir 1 default_owned "dir1" ' in contents.entry(loc +
+                                                                       '/dir1'))
+
+        # Test adding symlinks:
+        contents.add('sym', 'virtual', destination = loc, path = '/test3',
+                     real_path = loc + '/test3', relative = True)
+        self.assertTrue('sym 1 virtual "test3" ' in contents.entry(loc +
+                                                                   '/test3'))
+
+        # Printing out the db after adding these entries:
+        contents.db_print()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertTrue('file 1 config_owned "test1" ' in output[1])
+
+    def test_can_rm(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.0')
+        contents.read()
+        contents.ignore += ['.svn']
+
+        self.assertEqual(contents.get_canremove('/'.join((HERE, 'testfiles',
+                         'contents', 'inc'))), '!found inc')
+
+        self.assertEqual(contents.get_canremove('/'.join((HERE, 'testfiles',
+                         'contents', 'inc', 'prefs.php'))),
+                         '!found inc/prefs.php')
+
+    def test_read_clean(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.0')
+        contents.read()
+        contents.db_print()
+
+        output = sys.stdout.getvalue().split('\n')
+
+        self.assertTrue('file 1 virtual signup.php ' in output[3])
+        self.assertEqual(contents.get_directories()[1], '/'.join((HERE,
+                                                                  'testfiles',
+                                                                  'contents',
+                                                                  'inc')))
+
+    def test_read_corrupt(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.1')
+
+        OUT.color_off()
+        contents.read()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[12], '* Not enough entries.')
+
+    def test_write(self):
+        contents = Contents('/'.join((HERE, 'testfiles', 'contents')),
+                            package = 'test', version = '1.0', pretend = True)
+        OUT.color_off()
+        contents.read()
+
+        contents.write()
+        output = sys.stdout.getvalue().split('\n')
+
+        expected = '* Would have written content file ' + '/'.join((HERE,
+                                                          'testfiles',
+                                                          'contents',
+                                                          '.webapp-test-1.0!'))
+        self.assertEqual(output[0], expected)
+
+
+if __name__ == '__main__':
+    filterwarnings('ignore')
+    unittest.main(module=__name__, buffer=True)
+    resetwarnings()


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-02  8:27 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-02  8:27 UTC (permalink / raw
  To: gentoo-commits

commit:     161b1cc82ccbdf848bb9a41594e65ac9e3d2b0f2
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: Sun Nov  2 08:25:37 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=161b1cc8

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 5035c06..86afe18 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
 
@@ -334,6 +335,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] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-02  7:37 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-02  7:37 UTC (permalink / raw
  To: gentoo-commits

commit:     7f2d7cfe1559793415cc9041fb88a7d56bb638cb
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 31 14:11:20 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Sun Nov  2 07:34:34 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=7f2d7cfe

Adds WebappDB and WebappSource tests to external test suite

tests/dtest.py: Removes WebappConfig.db from doctest listing
tests/external.py: Adds tests for WebappDB and WebappSource classes
db.py: Removes doctests

---
 WebappConfig/db.py             | 174 -----------------------------------------
 WebappConfig/tests/dtest.py    |   2 -
 WebappConfig/tests/external.py | 121 ++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 176 deletions(-)

diff --git a/WebappConfig/db.py b/WebappConfig/db.py
index aa33ac5..0fbd34a 100644
--- a/WebappConfig/db.py
+++ b/WebappConfig/db.py
@@ -162,100 +162,6 @@ class WebappDB(AppHierarchy):
     '''
     The DataBase class handles a file-oriented data base that stores
     information about virtual installs of web applications.
-
-    Some test files are needed to test the functionality. This localizes
-    the current position:
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-
-    Deactivates color output which is bad for the doctest
-
-    >>> OUT.color_off()
-
-    Initialize the class:
-
-    >>> a = WebappDB(root = here + '/tests/testfiles/webapps')
-
-    This lists the database:
-    >>> a.listinstalls()
-    /var/www/localhost/htdocs/gallery
-    /var/www/localhost/htdocs/horde
-    /var/www/localhost/htdocs/phpldapadmin
-
-    Which is also possible in a more user friendly way:
-
-    >>> b = WebappDB(root = here + '/tests/testfiles/webapps', verbose = True)
-    >>> b.listinstalls()
-    * Installs for gallery-1.4.4_p6
-    *   /var/www/localhost/htdocs/gallery
-    * Installs for horde-3.0.5
-    *   /var/www/localhost/htdocs/horde
-    * Installs for phpldapadmin-0.9.7_alpha4
-    *   /var/www/localhost/htdocs/phpldapadmin
-
-    The function 'get_inst_files' handles the file locations within the
-    database. If no package has been specified while initializing
-    the database, the funtion will return all files available:
-
-    (code will only return package and varsion since the actual path
-     varies whith your code location)
-
-    >>> sb = [i[1] for i in b.list_locations().items()]
-    >>> sb.sort(key=lambda x: x[0]+x[1]+x[2])
-    >>> sb
-    [['', 'gallery', '1.4.4_p6'], ['', 'gallery', '2.0_rc2'], ['', 'horde', '3.0.5'], ['', 'phpldapadmin', '0.9.7_alpha4']]
-
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'horde', version = '3.0.5')
-    >>> [i[1] for i in c.list_locations().items()]
-    [['', 'horde', '3.0.5']]
-
-    Package specifiers that do not map to an install file will yield
-    an empty result and a warning.
-
-    The warning is turned off for the example:
-    >>> OUT.warn_off()
-
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'garbish', version = '3.0.5')
-    >>> [i[1] for i in c.list_locations().items()]
-    []
-
-    Package specifiers that do not map to an install file will yield
-    an empty result and a warning:
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'horde', version = '8.1.1')
-    >>> [i[1] for i in c.list_locations().items()]
-    []
-
-    The warning is turned off for the example:
-    >>> OUT.warn_on()
-
-    Virtual installs can be added or removed using the corresponding
-    functions (the example will just pretend to write):
-
-    >>> d = WebappDB(root = here + '/tests/testfiles/webapps', pretend = True,
-    ...              package = 'horde', version = '3.0.5')
-    >>> d.add('/my/really/weird/hierarchy/for/horde', #doctest: +ELLIPSIS
-    ...       user = 'me', group = 'me')
-    * Pretended to append installation /my/really/weird/hierarchy/for/horde
-    * Entry:
-    * ... me me /my/really/weird/hierarchy/for/horde
-    * 
-    >>> d.remove('/var/www/localhost/htdocs/horde')
-    * Pretended to remove installation /var/www/localhost/htdocs/horde
-    * Final DB content:
-    * 
-    * 
-
-    >>> d.remove('/my/really/weird/hierarchy/for/horde')  #doctest: +ELLIPSIS
-    * Installation at "/my/really/weird/hierarchy/for/horde" could not be found in the database file. Check the entries in ".../tests/testfiles/webapps/horde/3.0.5/installs"!
-    * Pretended to remove installation /my/really/weird/hierarchy/for/horde
-    * Final DB content:
-    * 1124612110 root root /var/www/localhost/htdocs/horde
-    * 
-
     '''
 
     def __init__(self,
@@ -507,28 +413,6 @@ class WebappSource(AppHierarchy):
     '''
     The WebappSource class handles a web application hierarchy under
     /usr/share/webapps.
-
-    Some test files are needed to test the functionality. This localizes
-    the current position:
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-
-    Initialize the class:
-
-    >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',)
-
-    A WebappDB class is needed to retrive information about installed
-    packages:
-    >>> b = WebappDB(root = here + '/tests/testfiles/webapps')
-
-    This lists the database:
-    >>> a.listunused(b)
-    share-webapps/horde-3.0.5
-    share-webapps/installtest-1.0
-    share-webapps/uninstalled-6.6.6
-
-
     '''
 
     def __init__(self,
@@ -561,19 +445,6 @@ class WebappSource(AppHierarchy):
              default_dirs  = 'default-owned'):
         '''
         Initialize the type cache.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root=here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-
-        >>> a.read()
-        >>> a.filetype('test1')
-        'config-owned'
-
-        >>> a.filetype('test2')
-        'server-owned'
-
         '''
         import WebappConfig.filetype
 
@@ -621,17 +492,6 @@ class WebappSource(AppHierarchy):
         '''
         Checks if the specified source directory exists within the
         application directory.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-
-        >>> a.source_exists('htdocs')
-        True
-
-        >>> a.source_exists('test')
-        False
         '''
         if self.appdir() and os.path.isdir(self.appdir()
                                             + '/' + directory):
@@ -642,14 +502,6 @@ class WebappSource(AppHierarchy):
         '''
         Lists the directories provided by the source directory
         'directory'
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-        >>> d = a.get_source_directories('htdocs')
-        >>> [i for i in d if i != '.svn']
-        ['dir1', 'dir2']
         '''
         dirs = []
 
@@ -675,13 +527,6 @@ class WebappSource(AppHierarchy):
         '''
         Lists the files provided by the source directory
         'directory'
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-        >>> a.get_source_files('htdocs')
-        ['test1', 'test2']
         '''
 
         files = []
@@ -743,20 +588,6 @@ class WebappSource(AppHierarchy):
             1       - package not found
             2       - no package to find
             3       - package isn't webapp-config compatible          '
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        Does not exist:
-
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='www-apps',package='nothere', version='1',pm='portage')
-        >>> a.packageavail()
-        1
-
-        Incompatible cannot be tested since that would require a
-        oackage (including version number) that is installed on
-        all systems.
         '''
 
         OUT.debug('Verifying package ' + self.package_name(), 6)
@@ -768,7 +599,6 @@ class WebappSource(AppHierarchy):
             package = self.category + '/' + self.pn
 
         # not using self.package_name() here as we don't need pvr
-        if not wrapper.package_installed(package, self.pm):
             return 1
 
         # unfortunately, just because a package has been installed, it
@@ -802,7 +632,3 @@ class WebappSource(AppHierarchy):
             OUT.die('  ' + self.package_name() + ' is not compatible with '
                     'webapp-config.\nIf it should be, report this at '
                     + wrapper.bugs_link)
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

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

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
index d4b3aa4..4aa93cf 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -23,6 +23,7 @@ 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
 
@@ -136,6 +137,126 @@ class ContentsTest(unittest.TestCase):
                                                           '.webapp-test-1.0!'))
         self.assertEqual(output[0], expected)
 
+class WebappDBTest(unittest.TestCase):
+    def test_list_installs(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+
+        db.listinstalls()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[1], '/var/www/localhost/htdocs/horde')
+
+        # Now test the verbosity:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      verbose = True)
+        db.listinstalls()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[5], '* Installs for horde-3.0.5')
+
+    def test_list_locations(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        sorted_db.sort(key=lambda x: x[0]+x[1]+x[2])
+
+        self.assertEqual(sorted_db[1], ['', 'gallery', '2.0_rc2'])
+
+        # Now test with a specific package and version:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      package = 'horde', version = '3.0.5')
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        self.assertEqual(sorted_db, [['', 'horde', '3.0.5']])
+
+        # Now test with an install file that doesn't exist:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      package = 'nihil', version = '3.0.5')
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        self.assertEqual(sorted_db, [])
+        
+    def test_add_rm(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      pretend = True, package = 'horde', version = '3.0.5')
+        # Test adding:
+        db.add('/'.join(('/screwy', 'wonky', 'foobar', 'horde', 'hierarchy')),
+               user = 'me', group = 'me')
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[0], '* Pretended to append installation '\
+                                    '/screwy/wonky/foobar/horde/hierarchy')
+
+        # Test deleting a webapp that is actually in the database:
+        db.remove('/'.join(('/var', 'www', 'localhost', 'htdocs', 'horde')))
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[6], '* ')
+
+        # And now test deleting one that isn't:
+        db.remove('/'.join(('/screwy', 'wonky', 'foobar', 'horde', 'hierarchy')))
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[11], '* 1124612110 root root '\
+                                     '/var/www/localhost/htdocs/horde')
+
+
+class WebappSourceTest(unittest.TestCase):
+        SHARE = '/'.join((HERE, 'testfiles', 'share-webapps'))
+        def test_list_unused(self):
+            source = WebappSource(root = '/'.join((HERE,
+                                                  'testfiles',
+                                                  'share-webapps')))
+            db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+            source.listunused(db)
+            output = sys.stdout.getvalue().split('\n')
+            self.assertEqual(output[2], 'share-webapps/uninstalled-6.6.6')
+
+        def test_read(self):
+            source = WebappSource(root = '/'.join((HERE,
+                                                   'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+
+            source.read()
+            self.assertEqual(source.filetype('test1'), 'config-owned')
+            self.assertEqual(source.filetype('test2'), 'server-owned')
+
+        def test_src_exists(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            self.assertTrue(source.source_exists('htdocs'))
+            self.assertFalse(source.source_exists('foobar'))
+
+        def test_get_src_dirs(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            dirs = source.get_source_directories('htdocs')
+            dirs = [i for i in dirs if i != '.svn']
+            self.assertEqual(dirs, ['dir1', 'dir2'])
+
+        def test_get_src_files(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            files = source.get_source_files('htdocs')
+            self.assertEqual(files, ['test1', 'test2'])
+
+        def test_pkg_avail(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'nihil',
+                                  version = '3.0.5',
+                                  pm = 'portage')
+            self.assertEqual(source.packageavail(), 1)
+
 
 if __name__ == '__main__':
     filterwarnings('ignore')


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-02  7:37 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-02  7:37 UTC (permalink / raw
  To: gentoo-commits

commit:     df0030fc5e881fff1f093509f145297544c3af2e
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Sun Nov  2 07:29:05 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Sun Nov  2 07:36:58 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=df0030fc

Adds Ebuild tests to external test suite

tests/dtest.py: Removes WebappConfig.ebuild from doctest listing
tests/external.py: Adds tests for Ebuild class
ebuild.py: Removes doctests, the tests used for testing run_hooks()
were not added to the external test suite due to the fact that there
is no return to check against, just output.

---
 WebappConfig/ebuild.py         | 143 +----------------------------------------
 WebappConfig/tests/dtest.py    |   2 -
 WebappConfig/tests/external.py |  37 +++++++++++
 3 files changed, 38 insertions(+), 144 deletions(-)

diff --git a/WebappConfig/ebuild.py b/WebappConfig/ebuild.py
index 24ef0d6..b4dc391 100644
--- a/WebappConfig/ebuild.py
+++ b/WebappConfig/ebuild.py
@@ -35,69 +35,6 @@ class Ebuild:
     This class handles all ebuild related task. Currently this includes
     displaying the post install instruction as well as running hooks
     provided by the ebuild.
-
-    This creates the basic configuration defaults:
-
-    >>> import WebappConfig.config
-    >>> config = WebappConfig.config.Config()
-
-    This needs to be completed with some parameters
-    that would be usually provided when parsing the
-    commandline:
-
-    >>> config.config.set('USER', 'my_htdocsbase',  'htdocs')
-    >>> config.config.set('USER', 'pn',   'horde')
-    >>> config.config.set('USER', 'pvr',  '3.0.5')
-    >>> config.config.set('USER', 'vhost_server_uid', 'apache')
-    >>> config.config.set('USER', 'vhost_server_gid', 'apache')
-
-    And the application directory needs to be set
-    to the testfile reporitory
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-    >>> config.config.set('USER', 'my_approot', here +
-    ...                   '/tests/testfiles/share-webapps')
-
-    Time to create the ebuild handler:
-
-    >>> my_approot = config.config.get('USER', 'my_approot')
-    >>> my_appdir = my_approot + "/horde/3.0.5"
-    >>> config.config.set('USER', 'my_appdir', my_appdir)
-    >>> config.config.set('USER', 'my_hookscriptsdir', my_appdir + '/hooks')
-    >>> config.config.set('USER', 'my_cgibinbase', 'cgi-bin')
-    >>> config.config.set('USER', 'my_errorsbase', 'error')
-    >>> config.config.set('USER', 'my_iconsbase', 'icons')
-    >>> config.config.set('USER', 'my_serverconfigdir', '/'.join([my_appdir,'conf']))
-    >>> config.config.set('USER', 'my_hostrootdir', '/'.join([my_appdir,'hostroot']))
-    >>> config.config.set('USER', 'my_htdocsdir', '/'.join([my_appdir,'htdocs']))
-    >>> config.config.set('USER', 'my_sqlscriptsdir', '/'.join([my_appdir,'sqlscripts']))
-    >>> a = Ebuild(config)
-
-    Run a hook script:
-
-    >>> from WebappConfig.server import Basic
-    >>> basic = Basic({'source': '', 'destination': '', 'hostroot': '', 'vhostroot':''},
-    ...               config.create_permissions(),
-    ...               {'source':'','content':'','protect':'','dotconfig':'','ebuild':'','db':''},
-    ...               {'verbose':False,'pretend':True}, 'portage')
-    >>> a.run_hooks('test', basic)
-
-    The same on a directory that misses a hook dir:
-
-    >>> config.config.set('USER', 'pn',   'empty')
-    >>> config.config.set('USER', 'pvr',  '1.0')
-    >>> a = Ebuild(config)
-    >>> a.run_hooks('test', basic)
-
-    This app has a hook dir but no script:
-
-    >>> config.config.set('USER', 'pn',   'uninstalled')
-    >>> config.config.set('USER', 'pvr',  '6.6.6')
-    >>> a = Ebuild(config)
-    >>> a.run_hooks('test', basic)
-
-
     '''
 
     def __init__(self, config):
@@ -135,7 +72,7 @@ class Ebuild:
 
                     OUT.debug('Running hook script', 7)
 
-                    sandbox.spawn(self.__hooksd + '/' + x + ' ' + type, env_map)
+                    return sandbox.spawn(self.__hooksd + '/' + x + ' ' + type, env_map)
 
     def show_post(self, filename, ptype, server = None):
         '''
@@ -197,80 +134,6 @@ class Ebuild:
         This function exports the necessary variables to the shell
         environment so that they are accessible within the shell scripts
         and/or files provided by the ebuild.
-
-        The procedure from above is repeated to set up the default
-        environment:
-
-        ">>> import WebappConfig.config"
-        ">>> config = WebappConfig.config.Config()"
-        ">>> config.config.set('USER', 'my_htdocsbase',  'htdocs')"
-        ">>> config.config.set('USER', 'pn',   'horde')"
-        ">>> config.config.set('USER', 'pvr',  '3.0.5')"
-        ">>> import os.path"
-        ">>> here = os.path.dirname(os.path.realpath(__file__))"
-        ">>> config.config.set('USER', 'my_approot', here +"
-        "...                   '/tests/testfiles/share-webapps')"
-        ">>> my_approot = config.config.get('USER', 'my_approot')"
-        ">>> my_appdir = my_approot + "/horde/3.0.5""
-        ">>> config.config.set('USER', 'my_appdir', my_appdir)"
-        ">>> config.config.set('USER', 'my_hookscriptsdir', my_appdir + '/hooks')"
-        ">>> config.config.set('USER', 'my_cgibinbase', 'cgi-bin')"
-        ">>> config.config.set('USER', 'my_errorsbase', 'error')"
-        ">>> config.config.set('USER', 'my_iconsbase', 'icons')"
-        ">>> config.config.set('USER', 'my_serverconfigdir', '/'.join([my_appdir,'conf']))"
-        ">>> config.config.set('USER', 'my_hostrootdir', '/'.join([my_appdir,'hostroot']))"
-        ">>> config.config.set('USER', 'my_htdocsdir', '/'.join([my_appdir,'htdocs']))"
-        ">>> config.config.set('USER', 'my_sqlscriptsdir', '/'.join([my_appdir,'sqlscripts']))"
-
-        Time to create the ebuild handler:
-
-        ">>> a = Ebuild(config)"
-
-        The dummy post-install file should display all the variables
-        that are exported here:
-
-        ">>> a.show_postinst() #doctest: +ELLIPSIS
-        <BLANKLINE>
-        =================================================================
-        POST-INSTALL INSTRUCTIONS
-        =================================================================
-        <BLANKLINE>
-        MY_HOSTROOTDIR: .../tests/testfiles/share-webapps/horde/3.0.5/hostroot
-        MY_HTDOCSDIR: .../tests/testfiles/share-webapps/horde/3.0.5/htdocs
-        MY_CGIBINDIR: .../tests/testfiles/share-webapps/horde/3.0.5/hostroot/cgi-bin
-        MY_INSTALLDIR: /
-        MY_ICONSDIR: .../tests/testfiles/share-webapps/horde/3.0.5/hostroot/icons
-        MY_SERVERCONFIGDIR: .../tests/testfiles/share-webapps/horde/3.0.5/conf
-        MY_ERRORSDIR: .../tests/testfiles/share-webapps/horde/3.0.5/hostroot/error
-        MY_SQLSCRIPTSDIR: .../tests/testfiles/share-webapps/horde/3.0.5/sqlscripts
-        VHOST_ROOT: /var/www/...
-        VHOST_HTDOCSDIR: /var/www/.../htdocs
-        VHOST_CGIBINDIR: /var/www/.../cgi-bin
-        VHOST_CONFDIR: /var/www/.../
-        VHOST_ERRORSDIR: /var/www/.../error
-        VHOST_ICONSDIR: /var/www/.../icons
-        VHOST_HOSTNAME: ...
-        VHOST_SERVER: apache
-        VHOST_APPDIR: /
-        VHOST_CONFIG_UID: ...
-        VHOST_CONFIG_GID: ...
-        VHOST_SERVER_UID: ...
-        VHOST_SERVER_GID: ...
-        VHOST_DEFAULT_UID: 0
-        VHOST_DEFAULT_GID: 0
-        VHOST_PERMS_SERVEROWNED_DIR: 0775
-        VHOST_PERMS_SERVEROWNED_FILE: 0664
-        VHOST_PERMS_CONFIGOWNED_DIR: 0755
-        VHOST_PERMS_CONFIGOWNED_FILE: 0644
-        VHOST_PERMS_DEFAULTOWNED_DIR: 0755
-        VHOST_PERMS_VIRTUALOWNED_FILE: o-w
-        VHOST_PERMS_INSTALLDIR: 0755
-        ROOT: /
-        PN: horde
-        PVR: 3.0.5
-        <BLANKLINE>
-        =================================================================
-        <BLANKLINE>"
         '''
 
         v_root = self.get_config('vhost_root')
@@ -337,7 +200,3 @@ class Ebuild:
             result[i] = str(value)
 
         return result
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

diff --git a/WebappConfig/tests/dtest.py b/WebappConfig/tests/dtest.py
index 8dab47a..a46be2c 100644
--- a/WebappConfig/tests/dtest.py
+++ b/WebappConfig/tests/dtest.py
@@ -8,14 +8,12 @@
 
 import unittest, doctest, sys
 
-import WebappConfig.ebuild
 import WebappConfig.filetype
 import WebappConfig.protect
 import WebappConfig.worker
 
 def test_suite():
     return unittest.TestSuite((
-        doctest.DocTestSuite(WebappConfig.ebuild),
         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 1aabf11..5035c06 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -22,10 +22,13 @@ import os
 import unittest
 import sys
 
+from  WebappConfig.config    import Config
 from  WebappConfig.content   import Contents
 from  WebappConfig.db        import WebappDB, WebappSource
 from  WebappConfig.debug     import OUT
 from  WebappConfig.dotconfig import DotConfig
+from  WebappConfig.ebuild    import Ebuild
+from  WebappConfig.server    import Basic
 from  warnings               import filterwarnings, resetwarnings
 
 HERE = os.path.dirname(os.path.realpath(__file__))
@@ -297,6 +300,40 @@ class DotConfigTest(unittest.TestCase):
                                    '.webapp')))
 
 
+
+class EbuildTest(unittest.TestCase):
+    def test_showpostinst(self):
+        config = Config()
+        approot = '/'.join((HERE, 'testfiles', 'share-webapps'))
+        appdir  = '/'.join((approot, 'horde', '3.0.5'))
+        conf   = {'my_htdocsbase': 'htdocs', 'pn': 'horde', 'pvr': '3.0.5',
+                  'vhost_server_uid': 'apache', 'vhost_server_git': 'apache',
+                  'my_approot': approot,
+                  'my_appdir': appdir,
+                  'my_hookscriptsdir': '/'.join((appdir, 'hooks')),
+                  'my_cgibinbase': 'cgi-bin', 'my_errorsbase': 'error',
+                  'my_iconsbase': 'icons',
+                  'my_serverconfigdir': '/'.join((appdir, 'conf')),
+                  'my_hostrootdir': '/'.join((appdir, 'hostroot')),
+                  'my_htdocsdir': '/'.join((appdir, 'htdocs')),
+                  'my_sqlscriptsdir': '/'.join((appdir, 'sqlscripts')),
+                 }
+
+        for key in conf.keys():
+            config.config.set('USER', key, conf[key])
+
+        ebuild = Ebuild(config)
+        ebuild.show_postinst()
+        output = sys.stdout.getvalue().split('\n')
+
+        self.assertEqual(output[5], 'MY_HOSTROOTDIR: ' + '/'.join((HERE,
+                                                                 'testfiles',
+                                                                 'share-webapps',
+                                                                 'horde',
+                                                                 '3.0.5',
+                                                                 'hostroot')))
+
+
 if __name__ == '__main__':
     filterwarnings('ignore')
     unittest.main(module=__name__, buffer=True)


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-02  5:58 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-02  5:58 UTC (permalink / raw
  To: gentoo-commits

commit:     a033c590bdcfc333831ef67ef37740212be75dee
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: Sun Nov  2 05:56:40 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=a033c590

Adds DotConfig tests to external test suite

tests/dtest.py: Removes WebappConfig.content 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 4aa93cf..1aabf11 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__))
 
@@ -258,6 +259,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] 18+ messages in thread
* [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
@ 2014-11-02  5:58 Devan Franchini
  0 siblings, 0 replies; 18+ messages in thread
From: Devan Franchini @ 2014-11-02  5:58 UTC (permalink / raw
  To: gentoo-commits

commit:     8e583d0b0b6d7641d58cd61c06771ed2916f8f7d
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 31 14:11:20 2014 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Sun Nov  2 04:33:04 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=8e583d0b

Adds WebappDB and WebappSource tests to external test suite

tests/dtest.py: Removes WebappConfig.content from doctest listing
tests/external.py: Adds tests for Contents class
db.py: Removes doctests

---
 WebappConfig/db.py             | 174 -----------------------------------------
 WebappConfig/tests/dtest.py    |   2 -
 WebappConfig/tests/external.py | 121 ++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 176 deletions(-)

diff --git a/WebappConfig/db.py b/WebappConfig/db.py
index aa33ac5..0fbd34a 100644
--- a/WebappConfig/db.py
+++ b/WebappConfig/db.py
@@ -162,100 +162,6 @@ class WebappDB(AppHierarchy):
     '''
     The DataBase class handles a file-oriented data base that stores
     information about virtual installs of web applications.
-
-    Some test files are needed to test the functionality. This localizes
-    the current position:
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-
-    Deactivates color output which is bad for the doctest
-
-    >>> OUT.color_off()
-
-    Initialize the class:
-
-    >>> a = WebappDB(root = here + '/tests/testfiles/webapps')
-
-    This lists the database:
-    >>> a.listinstalls()
-    /var/www/localhost/htdocs/gallery
-    /var/www/localhost/htdocs/horde
-    /var/www/localhost/htdocs/phpldapadmin
-
-    Which is also possible in a more user friendly way:
-
-    >>> b = WebappDB(root = here + '/tests/testfiles/webapps', verbose = True)
-    >>> b.listinstalls()
-    * Installs for gallery-1.4.4_p6
-    *   /var/www/localhost/htdocs/gallery
-    * Installs for horde-3.0.5
-    *   /var/www/localhost/htdocs/horde
-    * Installs for phpldapadmin-0.9.7_alpha4
-    *   /var/www/localhost/htdocs/phpldapadmin
-
-    The function 'get_inst_files' handles the file locations within the
-    database. If no package has been specified while initializing
-    the database, the funtion will return all files available:
-
-    (code will only return package and varsion since the actual path
-     varies whith your code location)
-
-    >>> sb = [i[1] for i in b.list_locations().items()]
-    >>> sb.sort(key=lambda x: x[0]+x[1]+x[2])
-    >>> sb
-    [['', 'gallery', '1.4.4_p6'], ['', 'gallery', '2.0_rc2'], ['', 'horde', '3.0.5'], ['', 'phpldapadmin', '0.9.7_alpha4']]
-
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'horde', version = '3.0.5')
-    >>> [i[1] for i in c.list_locations().items()]
-    [['', 'horde', '3.0.5']]
-
-    Package specifiers that do not map to an install file will yield
-    an empty result and a warning.
-
-    The warning is turned off for the example:
-    >>> OUT.warn_off()
-
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'garbish', version = '3.0.5')
-    >>> [i[1] for i in c.list_locations().items()]
-    []
-
-    Package specifiers that do not map to an install file will yield
-    an empty result and a warning:
-    >>> c = WebappDB(root = here + '/tests/testfiles/webapps',
-    ...              package = 'horde', version = '8.1.1')
-    >>> [i[1] for i in c.list_locations().items()]
-    []
-
-    The warning is turned off for the example:
-    >>> OUT.warn_on()
-
-    Virtual installs can be added or removed using the corresponding
-    functions (the example will just pretend to write):
-
-    >>> d = WebappDB(root = here + '/tests/testfiles/webapps', pretend = True,
-    ...              package = 'horde', version = '3.0.5')
-    >>> d.add('/my/really/weird/hierarchy/for/horde', #doctest: +ELLIPSIS
-    ...       user = 'me', group = 'me')
-    * Pretended to append installation /my/really/weird/hierarchy/for/horde
-    * Entry:
-    * ... me me /my/really/weird/hierarchy/for/horde
-    * 
-    >>> d.remove('/var/www/localhost/htdocs/horde')
-    * Pretended to remove installation /var/www/localhost/htdocs/horde
-    * Final DB content:
-    * 
-    * 
-
-    >>> d.remove('/my/really/weird/hierarchy/for/horde')  #doctest: +ELLIPSIS
-    * Installation at "/my/really/weird/hierarchy/for/horde" could not be found in the database file. Check the entries in ".../tests/testfiles/webapps/horde/3.0.5/installs"!
-    * Pretended to remove installation /my/really/weird/hierarchy/for/horde
-    * Final DB content:
-    * 1124612110 root root /var/www/localhost/htdocs/horde
-    * 
-
     '''
 
     def __init__(self,
@@ -507,28 +413,6 @@ class WebappSource(AppHierarchy):
     '''
     The WebappSource class handles a web application hierarchy under
     /usr/share/webapps.
-
-    Some test files are needed to test the functionality. This localizes
-    the current position:
-
-    >>> import os.path
-    >>> here = os.path.dirname(os.path.realpath(__file__))
-
-    Initialize the class:
-
-    >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',)
-
-    A WebappDB class is needed to retrive information about installed
-    packages:
-    >>> b = WebappDB(root = here + '/tests/testfiles/webapps')
-
-    This lists the database:
-    >>> a.listunused(b)
-    share-webapps/horde-3.0.5
-    share-webapps/installtest-1.0
-    share-webapps/uninstalled-6.6.6
-
-
     '''
 
     def __init__(self,
@@ -561,19 +445,6 @@ class WebappSource(AppHierarchy):
              default_dirs  = 'default-owned'):
         '''
         Initialize the type cache.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root=here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-
-        >>> a.read()
-        >>> a.filetype('test1')
-        'config-owned'
-
-        >>> a.filetype('test2')
-        'server-owned'
-
         '''
         import WebappConfig.filetype
 
@@ -621,17 +492,6 @@ class WebappSource(AppHierarchy):
         '''
         Checks if the specified source directory exists within the
         application directory.
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-
-        >>> a.source_exists('htdocs')
-        True
-
-        >>> a.source_exists('test')
-        False
         '''
         if self.appdir() and os.path.isdir(self.appdir()
                                             + '/' + directory):
@@ -642,14 +502,6 @@ class WebappSource(AppHierarchy):
         '''
         Lists the directories provided by the source directory
         'directory'
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-        >>> d = a.get_source_directories('htdocs')
-        >>> [i for i in d if i != '.svn']
-        ['dir1', 'dir2']
         '''
         dirs = []
 
@@ -675,13 +527,6 @@ class WebappSource(AppHierarchy):
         '''
         Lists the files provided by the source directory
         'directory'
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='', package='horde', version='3.0.5')
-        >>> a.get_source_files('htdocs')
-        ['test1', 'test2']
         '''
 
         files = []
@@ -743,20 +588,6 @@ class WebappSource(AppHierarchy):
             1       - package not found
             2       - no package to find
             3       - package isn't webapp-config compatible          '
-
-        >>> import os.path
-        >>> here = os.path.dirname(os.path.realpath(__file__))
-
-        Does not exist:
-
-        >>> a = WebappSource(root = here + '/tests/testfiles/share-webapps',
-        ...             category='www-apps',package='nothere', version='1',pm='portage')
-        >>> a.packageavail()
-        1
-
-        Incompatible cannot be tested since that would require a
-        oackage (including version number) that is installed on
-        all systems.
         '''
 
         OUT.debug('Verifying package ' + self.package_name(), 6)
@@ -768,7 +599,6 @@ class WebappSource(AppHierarchy):
             package = self.category + '/' + self.pn
 
         # not using self.package_name() here as we don't need pvr
-        if not wrapper.package_installed(package, self.pm):
             return 1
 
         # unfortunately, just because a package has been installed, it
@@ -802,7 +632,3 @@ class WebappSource(AppHierarchy):
             OUT.die('  ' + self.package_name() + ' is not compatible with '
                     'webapp-config.\nIf it should be, report this at '
                     + wrapper.bugs_link)
-
-if __name__ == '__main__':
-    import doctest, sys
-    doctest.testmod(sys.modules[__name__])

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

diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py
index d4b3aa4..4aa93cf 100755
--- a/WebappConfig/tests/external.py
+++ b/WebappConfig/tests/external.py
@@ -23,6 +23,7 @@ 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
 
@@ -136,6 +137,126 @@ class ContentsTest(unittest.TestCase):
                                                           '.webapp-test-1.0!'))
         self.assertEqual(output[0], expected)
 
+class WebappDBTest(unittest.TestCase):
+    def test_list_installs(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+
+        db.listinstalls()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[1], '/var/www/localhost/htdocs/horde')
+
+        # Now test the verbosity:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      verbose = True)
+        db.listinstalls()
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[5], '* Installs for horde-3.0.5')
+
+    def test_list_locations(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        sorted_db.sort(key=lambda x: x[0]+x[1]+x[2])
+
+        self.assertEqual(sorted_db[1], ['', 'gallery', '2.0_rc2'])
+
+        # Now test with a specific package and version:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      package = 'horde', version = '3.0.5')
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        self.assertEqual(sorted_db, [['', 'horde', '3.0.5']])
+
+        # Now test with an install file that doesn't exist:
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      package = 'nihil', version = '3.0.5')
+        sorted_db = [i[1] for i in db.list_locations().items()]
+        self.assertEqual(sorted_db, [])
+        
+    def test_add_rm(self):
+        OUT.color_off()
+        db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')),
+                      pretend = True, package = 'horde', version = '3.0.5')
+        # Test adding:
+        db.add('/'.join(('/screwy', 'wonky', 'foobar', 'horde', 'hierarchy')),
+               user = 'me', group = 'me')
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[0], '* Pretended to append installation '\
+                                    '/screwy/wonky/foobar/horde/hierarchy')
+
+        # Test deleting a webapp that is actually in the database:
+        db.remove('/'.join(('/var', 'www', 'localhost', 'htdocs', 'horde')))
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[6], '* ')
+
+        # And now test deleting one that isn't:
+        db.remove('/'.join(('/screwy', 'wonky', 'foobar', 'horde', 'hierarchy')))
+        output = sys.stdout.getvalue().split('\n')
+        self.assertEqual(output[11], '* 1124612110 root root '\
+                                     '/var/www/localhost/htdocs/horde')
+
+
+class WebappSourceTest(unittest.TestCase):
+        SHARE = '/'.join((HERE, 'testfiles', 'share-webapps'))
+        def test_list_unused(self):
+            source = WebappSource(root = '/'.join((HERE,
+                                                  'testfiles',
+                                                  'share-webapps')))
+            db = WebappDB(root = '/'.join((HERE, 'testfiles', 'webapps')))
+            source.listunused(db)
+            output = sys.stdout.getvalue().split('\n')
+            self.assertEqual(output[2], 'share-webapps/uninstalled-6.6.6')
+
+        def test_read(self):
+            source = WebappSource(root = '/'.join((HERE,
+                                                   'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+
+            source.read()
+            self.assertEqual(source.filetype('test1'), 'config-owned')
+            self.assertEqual(source.filetype('test2'), 'server-owned')
+
+        def test_src_exists(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            self.assertTrue(source.source_exists('htdocs'))
+            self.assertFalse(source.source_exists('foobar'))
+
+        def test_get_src_dirs(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            dirs = source.get_source_directories('htdocs')
+            dirs = [i for i in dirs if i != '.svn']
+            self.assertEqual(dirs, ['dir1', 'dir2'])
+
+        def test_get_src_files(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'horde',
+                                  version = '3.0.5')
+            files = source.get_source_files('htdocs')
+            self.assertEqual(files, ['test1', 'test2'])
+
+        def test_pkg_avail(self):
+            source = WebappSource(root = '/'.join((HERE, 'testfiles',
+                                                   'share-webapps')),
+                                  category = '',
+                                  package = 'nihil',
+                                  version = '3.0.5',
+                                  pm = 'portage')
+            self.assertEqual(source.packageavail(), 1)
+
 
 if __name__ == '__main__':
     filterwarnings('ignore')


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

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

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-17 23:42 [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/ Devan Franchini
  -- strict thread matches above, loose matches on Subject: below --
2015-06-19 19:19 Devan Franchini
2014-11-17 23:58 Devan Franchini
2014-11-17 23:58 Devan Franchini
2014-11-17 23:58 Devan Franchini
2014-11-17 23:58 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-03  0:02 Devan Franchini
2014-11-03  0:02 Devan Franchini
2014-11-02  8:27 Devan Franchini
2014-11-02  7:37 Devan Franchini
2014-11-02  7:37 Devan Franchini
2014-11-02  5:58 Devan Franchini
2014-11-02  5:58 Devan Franchini

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