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 355E3138CEE for ; Fri, 19 Jun 2015 19:53:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 14FD91403B; Fri, 19 Jun 2015 19:53:02 +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 CDC1014022 for ; Fri, 19 Jun 2015 19:53:00 +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 6F431340CC3 for ; Fri, 19 Jun 2015 19:52:59 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id E176CA54 for ; Fri, 19 Jun 2015 19:52:56 +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: <1434743345.9b10c59abfc75813670eea42a3ebdb6337265960.twitch153@gentoo> Subject: [gentoo-commits] proj/webapp-config:master commit in: WebappConfig/tests/, WebappConfig/ X-VCS-Repository: proj/webapp-config X-VCS-Files: WebappConfig/protect.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: 9b10c59abfc75813670eea42a3ebdb6337265960 X-VCS-Branch: master Date: Fri, 19 Jun 2015 19:52:56 +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: fb262238-14da-4bb5-bbc3-a624a0f793c6 X-Archives-Hash: fc0bc92ed530fdda53ffec06518904d1 commit: 9b10c59abfc75813670eea42a3ebdb6337265960 Author: Devan Franchini gentoo org> AuthorDate: Sun Nov 2 23:50:23 2014 +0000 Commit: Devan Franchini gentoo org> CommitDate: Fri Jun 19 19:49:05 2015 +0000 URL: https://gitweb.gentoo.org/proj/webapp-config.git/commit/?id=9b10c59a 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 c8b0646..69fd912 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 @@ -366,7 +367,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()