From 4b2d150b36e01a6b11d714586f5e521db4d639e1 Mon Sep 17 00:00:00 2001 From: Devan Franchini Date: Sun, 2 Nov 2014 19:57:18 -0500 Subject: 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(-) delete mode 100644 WebappConfig/tests/dtest.py 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__]) -- cgit v1.2.3-65-gdbad