diff options
author | Devan Franchini <twitch153@gentoo.org> | 2014-10-31 10:11:20 -0400 |
---|---|---|
committer | Devan Franchini <twitch153@gentoo.org> | 2015-06-19 15:48:21 -0400 |
commit | d821ced503b71edda66439b19b764d3a257519c8 (patch) | |
tree | 4759e4a8032e5d86716acf53049a1e12d3cb15f5 | |
parent | Adds beginning stages of external test suite (diff) | |
download | webapp-config-d821ced503b71edda66439b19b764d3a257519c8.tar.gz webapp-config-d821ced503b71edda66439b19b764d3a257519c8.tar.bz2 webapp-config-d821ced503b71edda66439b19b764d3a257519c8.zip |
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
-rw-r--r-- | WebappConfig/db.py | 174 | ||||
-rw-r--r-- | WebappConfig/tests/dtest.py | 2 | ||||
-rwxr-xr-x | 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') |