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, 17 Nov 2014 23:58:03 +0000 (UTC) [thread overview]
Message-ID: <1416268674.5e73953596d70e1efb1349b68f0472ab3291c4e0.twitch153@gentoo> (raw)
commit: 5e73953596d70e1efb1349b68f0472ab3291c4e0
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Sun Nov 2 23:50:23 2014 +0000
Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Mon Nov 17 23:57:54 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=5e739535
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()
next reply other threads:[~2014-11-17 23:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-17 23:58 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: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-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=1416268674.5e73953596d70e1efb1349b68f0472ab3291c4e0.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