public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Devan Franchini" <twitch153@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/, WebappConfig/tests/
Date: Mon,  3 Nov 2014 00:02:07 +0000 (UTC)	[thread overview]
Message-ID: <1414972800.2f30940d7fbc0961ab7e2410a9c682ac2a2734dc.twitch153@gentoo> (raw)

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

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 6296a34..ec49938 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')


             reply	other threads:[~2014-11-03  0:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-03  0:02 Devan Franchini [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-06-19 19:19 [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/, WebappConfig/tests/ Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
2015-06-19 19:19 Devan Franchini
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:42 Devan Franchini
2014-11-03  0:59 Devan Franchini
2014-11-03  0:02 Devan Franchini
2014-11-03  0:02 Devan Franchini
2014-11-03  0:02 Devan Franchini
2014-11-02 23:52 Devan Franchini
2014-11-02  8:27 Devan Franchini
2014-11-02  7:37 Devan Franchini
2014-11-02  5:58 Devan Franchini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1414972800.2f30940d7fbc0961ab7e2410a9c682ac2a2734dc.twitch153@gentoo \
    --to=twitch153@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox