summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-02-05 12:13:20 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-02-14 14:56:23 -0500
commit9d0e6991fc23c073efc0db6bf10e1081f6725e55 (patch)
treed59c0b3ce496aef72dd18812960fc2e101dab8e4 /testsuite
parentcfa4ce0a6fe82ed8578fe4668998012ad3833e05 (diff)
downloadbcfg2-9d0e6991fc23c073efc0db6bf10e1081f6725e55.tar.gz
bcfg2-9d0e6991fc23c073efc0db6bf10e1081f6725e55.tar.bz2
bcfg2-9d0e6991fc23c073efc0db6bf10e1081f6725e55.zip
abstracted similar digit range classes in POSIXUsers/GroupPatterns into Bcfg2.Utils
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py38
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py21
-rw-r--r--testsuite/Testsrc/Testlib/TestUtils.py48
3 files changed, 54 insertions, 53 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
index bcf6cf133..8ab279a50 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
@@ -6,6 +6,7 @@ import subprocess
from mock import Mock, MagicMock, patch
import Bcfg2.Client.Tools
from Bcfg2.Client.Tools.POSIXUsers import *
+from Bcfg2.Utils import PackedDigitRange
# add all parent testsuite directories to sys.path to allow (most)
# relative imports in python 2.4
@@ -19,33 +20,6 @@ while path != "/":
from common import *
-class TestIDRangeSet(Bcfg2TestCase):
- def test_ranges(self):
- # test cases. tuples of (ranges, included numbers, excluded
- # numbers)
- # tuples of (range description, numbers that are included,
- # numebrs that are excluded)
- tests = [(["0-3"], ["0", 1, "2", 3], [4]),
- (["1"], [1], [0, "2"]),
- (["10-11"], [10, 11], [0, 1]),
- (["9-9"], [9], [8, 10]),
- (["0-100"], [0, 10, 99, 100], []),
- (["1", "3", "5"], [1, 3, 5], [0, 2, 4, 6]),
- (["1-5", "7"], [1, 3, 5, 7], [0, 6, 8]),
- (["1-5", 7, "9-11"], [1, 3, 5, 7, 9, 11], [0, 6, 8, 12]),
- (["852-855", "321-497", 763], [852, 855, 321, 400, 497, 763],
- [851, 320, 766, 999]),
- (["0-"], [0, 1, 100, 100000], []),
- ([1, "5-10", "1000-"], [1, 5, 10, 1000, 10000000],
- [4, 11, 999])]
- for ranges, inc, exc in tests:
- rng = IDRangeSet(*ranges)
- for test in inc:
- self.assertIn(test, rng)
- for test in exc:
- self.assertNotIn(test, rng)
-
-
class TestExecutor(Bcfg2TestCase):
test_obj = Executor
@@ -177,19 +151,19 @@ class TestPOSIXUsers(Bcfg2TestCase):
def test__in_managed_range(self):
users = self.get_obj()
- users._whitelist = dict(POSIXGroup=IDRangeSet("1-10"))
- users._blacklist = dict(POSIXGroup=IDRangeSet("8-100"))
+ users._whitelist = dict(POSIXGroup=PackedDigitRange("1-10"))
+ users._blacklist = dict(POSIXGroup=PackedDigitRange("8-100"))
self.assertTrue(users._in_managed_range("POSIXGroup", "9"))
users._whitelist = dict(POSIXGroup=None)
- users._blacklist = dict(POSIXGroup=IDRangeSet("8-100"))
+ users._blacklist = dict(POSIXGroup=PackedDigitRange("8-100"))
self.assertFalse(users._in_managed_range("POSIXGroup", "9"))
users._whitelist = dict(POSIXGroup=None)
- users._blacklist = dict(POSIXGroup=IDRangeSet("100-"))
+ users._blacklist = dict(POSIXGroup=PackedDigitRange("100-"))
self.assertTrue(users._in_managed_range("POSIXGroup", "9"))
- users._whitelist = dict(POSIXGroup=IDRangeSet("1-10"))
+ users._whitelist = dict(POSIXGroup=PackedDigitRange("1-10"))
users._blacklist = dict(POSIXGroup=None)
self.assertFalse(users._in_managed_range("POSIXGroup", "25"))
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py
index a7a6b3d6e..a9346156c 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py
@@ -18,27 +18,6 @@ from common import *
from TestPlugin import TestXMLFileBacked, TestPlugin, TestConnector
-class TestPackedDigitRange(Bcfg2TestCase):
- def test_includes(self):
- # tuples of (range description, numbers that are included,
- # numebrs that are excluded)
- tests = [("1-3", [1, "2", 3], [4]),
- ("1", [1], [0, "2"]),
- ("10-11", [10, 11], [0, 1]),
- ("9-9", [9], [8, 10]),
- ("0-100", [0, 10, 99, 100], []),
- ("1,3,5", [1, 3, 5], [0, 2, 4, 6]),
- ("1-5,7", [1, 3, 5, 7], [0, 6, 8]),
- ("1-5,7,9-11", [1, 3, 5, 7, 9, 11], [0, 6, 8, 12]),
- ("852-855,321-497,763", [852, 855, 321, 400, 497, 763], [])]
- for rng, inc, exc in tests:
- r = PackedDigitRange(rng)
- for test in inc:
- self.assertTrue(r.includes(test))
- for test in exc:
- self.assertFalse(r.includes(test))
-
-
class TestPatternMap(Bcfg2TestCase):
def test_ranges(self):
""" test processing NameRange patterns """
diff --git a/testsuite/Testsrc/Testlib/TestUtils.py b/testsuite/Testsrc/Testlib/TestUtils.py
new file mode 100644
index 000000000..349d6cd40
--- /dev/null
+++ b/testsuite/Testsrc/Testlib/TestUtils.py
@@ -0,0 +1,48 @@
+import os
+import sys
+import copy
+import lxml.etree
+import subprocess
+from mock import Mock, MagicMock, patch
+from Bcfg2.Utils import *
+
+# add all parent testsuite directories to sys.path to allow (most)
+# relative imports in python 2.4
+path = os.path.dirname(__file__)
+while path != "/":
+ if os.path.basename(path).lower().startswith("test"):
+ sys.path.append(path)
+ if os.path.basename(path) == "testsuite":
+ break
+ path = os.path.dirname(path)
+from common import *
+
+
+class TestPackedDigitRange(Bcfg2TestCase):
+ def test_ranges(self):
+ # test cases. tuples of (ranges, included numbers, excluded
+ # numbers)
+ # tuples of (range description, numbers that are included,
+ # numebrs that are excluded)
+ tests = [(["0-3"], ["0", 1, "2", 3], [4]),
+ (["1"], [1], [0, "2"]),
+ (["10-11"], [10, 11], [0, 1]),
+ (["9-9"], [9], [8, 10]),
+ (["0-100"], [0, 10, 99, 100], []),
+ (["1", "3", "5"], [1, 3, 5], [0, 2, 4, 6]),
+ (["1-5", "7"], [1, 3, 5, 7], [0, 6, 8]),
+ (["1-5", 7, "9-11"], [1, 3, 5, 7, 9, 11], [0, 6, 8, 12]),
+ (["1-5, 7,9-11 "], [1, 3, 5, 7, 9, 11], [0, 6, 8, 12]),
+ (["852-855", "321-497", 763], [852, 855, 321, 400, 497, 763],
+ [851, 320, 766, 999]),
+ (["0-"], [0, 1, 100, 100000], []),
+ ([1, "5-10", "1000-"], [1, 5, 10, 1000, 10000000],
+ [4, 11, 999])]
+ for ranges, inc, exc in tests:
+ rng = PackedDigitRange(*ranges)
+ for test in inc:
+ self.assertIn(test, rng)
+ self.assertTrue(rng.includes(test))
+ for test in exc:
+ self.assertNotIn(test, rng)
+ self.assertFalse(rng.includes(test))