From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 75E38138A8F for ; Sun, 2 Nov 2014 05:58:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 546B2E0BE3; Sun, 2 Nov 2014 05:58:32 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 882C9E0C5D for ; Sun, 2 Nov 2014 05:58:31 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 50F7F340476 for ; Sun, 2 Nov 2014 05:58:30 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id EA4BA9425 for ; Sun, 2 Nov 2014 05:58:28 +0000 (UTC) From: "Devan Franchini" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Devan Franchini" Message-ID: <1414902784.8e583d0b0b6d7641d58cd61c06771ed2916f8f7d.twitch153@gentoo> Subject: [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/ X-VCS-Repository: proj/webapp-config X-VCS-Files: WebappConfig/db.py WebappConfig/tests/dtest.py WebappConfig/tests/external.py X-VCS-Directories: WebappConfig/ WebappConfig/tests/ X-VCS-Committer: twitch153 X-VCS-Committer-Name: Devan Franchini X-VCS-Revision: 8e583d0b0b6d7641d58cd61c06771ed2916f8f7d X-VCS-Branch: experimental Date: Sun, 2 Nov 2014 05:58:28 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 435dfc8a-133c-4826-9ef0-236c0d5835d7 X-Archives-Hash: fd66ddb1d9ce3bf193fbfdc9e2499972 commit: 8e583d0b0b6d7641d58cd61c06771ed2916f8f7d Author: Devan Franchini gentoo org> AuthorDate: Fri Oct 31 14:11:20 2014 +0000 Commit: Devan Franchini gentoo 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')