[Pkg-mozext-commits] [requestpolicy] 66/257: [tst][imp] rules.py: add properties like `origin_scheme`
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:19:57 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit bd331b8c7388acadeee5c6e3f3844c47d59e525c
Author: Martin Kimmerle <dev at 256k.de>
Date: Tue Oct 6 01:06:35 2015 +0200
[tst][imp] rules.py: add properties like `origin_scheme`
---
tests/marionette/rp_puppeteer/api/rules.py | 12 +++++++
tests/marionette/rp_puppeteer/tests/test_rules.py | 38 +++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/tests/marionette/rp_puppeteer/api/rules.py b/tests/marionette/rp_puppeteer/api/rules.py
index 2f241e0..5d1b9dd 100644
--- a/tests/marionette/rp_puppeteer/api/rules.py
+++ b/tests/marionette/rp_puppeteer/api/rules.py
@@ -198,6 +198,13 @@ class Rule(BaseLib):
""", script_args=[self._ruleset_name, self._rule_action,
self.rule_data])
+ origin_scheme = property(lambda self: self._get_rule_data_entry("o", "s"))
+ origin_host = property(lambda self: self._get_rule_data_entry("o", "h"))
+ origin_port = property(lambda self: self._get_rule_data_entry("o", "port"))
+ dest_scheme = property(lambda self: self._get_rule_data_entry("d", "s"))
+ dest_host = property(lambda self: self._get_rule_data_entry("d", "h"))
+ dest_port = property(lambda self: self._get_rule_data_entry("d", "port"))
+
##################################
# Private Properties and Methods #
##################################
@@ -209,3 +216,8 @@ class Rule(BaseLib):
@property
def _rule_action(self):
return 1 if self.allow else 2
+
+ def _get_rule_data_entry(self, first, second):
+ if first in self.rule_data and second in self.rule_data[first]:
+ return self.rule_data[first][second]
+ return None
diff --git a/tests/marionette/rp_puppeteer/tests/test_rules.py b/tests/marionette/rp_puppeteer/tests/test_rules.py
index 8271e51..d546862 100644
--- a/tests/marionette/rp_puppeteer/tests/test_rules.py
+++ b/tests/marionette/rp_puppeteer/tests/test_rules.py
@@ -58,6 +58,21 @@ class RulesTestCase(RequestPolicyTestCase):
different_temp=cr({"o": {"h": "a"}}, allow=False, temp=True)
)
+ # Rules specifying scheme, host and port, but only
+ # for origin or dest, respectively.
+ self.origin_shp_rule = cr(
+ {"o": {"s": "fooscheme", "h": "barhost", "port": 18224}},
+ allow=False, temp=True)
+ self.dest_shp_rule = cr(
+ {"d": {"s": "bazscheme", "h": "xyzhost", "port": 34755}},
+ allow=False, temp=True)
+
+ # A rule specifying scheme, host and port for both origin and dest.
+ self.shp_shp_rule = cr(
+ {"o": {"s": "fooscheme", "h": "barhost", "port": 18224},
+ "d": {"s": "bazscheme", "h": "xyzhost", "port": 34755}},
+ allow=False, temp=True)
+
def tearDown(self):
try:
self.rules.remove_all()
@@ -232,3 +247,26 @@ class TestRule(RulesTestCase):
self.assertFalse(rule.exists())
rule.add()
self.assertTrue(rule.exists())
+
+ def test_rule_data_properties(self):
+ # Test that all fields return `None` if not present.
+ self.assertIsNone(self.dest_shp_rule.origin_scheme)
+ self.assertIsNone(self.dest_shp_rule.origin_host)
+ self.assertIsNone(self.dest_shp_rule.origin_port)
+ self.assertIsNone(self.origin_shp_rule.dest_scheme)
+ self.assertIsNone(self.origin_shp_rule.dest_host)
+ self.assertIsNone(self.origin_shp_rule.dest_port)
+
+ # Test that each field returns the correct value if present.
+ self.assertEqual(self.shp_shp_rule.origin_scheme,
+ self.shp_shp_rule.rule_data["o"]["s"])
+ self.assertEqual(self.shp_shp_rule.origin_host,
+ self.shp_shp_rule.rule_data["o"]["h"])
+ self.assertEqual(self.shp_shp_rule.origin_port,
+ self.shp_shp_rule.rule_data["o"]["port"])
+ self.assertEqual(self.shp_shp_rule.dest_scheme,
+ self.shp_shp_rule.rule_data["d"]["s"])
+ self.assertEqual(self.shp_shp_rule.dest_host,
+ self.shp_shp_rule.rule_data["d"]["h"])
+ self.assertEqual(self.shp_shp_rule.dest_port,
+ self.shp_shp_rule.rule_data["d"]["port"])
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list