[Pkg-mozext-commits] [requestpolicy] 136/257: [tst][ref] Factor out RulesTable from YourPolicy
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:20:06 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 0fbacb6d074657e44e9509f93d0145a2054e50f3
Author: Martin Kimmerle <dev at 256k.de>
Date: Mon Nov 16 23:43:13 2015 +0100
[tst][ref] Factor out RulesTable from YourPolicy
Factor out RulesTable from the YourPolicy module.
Create YourPolicyRulesTable so that RulesTable can be used on
the "oldrules" page.
Also factor out test_rules_table.py from test_your_policy.py.
---
tests/marionette/rp_puppeteer/tests/manifest.ini | 1 +
.../rp_puppeteer/tests/test_rules_table.py | 237 +++++++++++++++++++++
.../rp_puppeteer/tests/test_your_policy.py | 206 ------------------
.../ui/settings/{your_policy.py => rules_table.py} | 206 +++++-------------
.../rp_puppeteer/ui/settings/your_policy.py | 116 +---------
5 files changed, 300 insertions(+), 466 deletions(-)
diff --git a/tests/marionette/rp_puppeteer/tests/manifest.ini b/tests/marionette/rp_puppeteer/tests/manifest.ini
index bf2d45a..a441b7a 100644
--- a/tests/marionette/rp_puppeteer/tests/manifest.ini
+++ b/tests/marionette/rp_puppeteer/tests/manifest.ini
@@ -6,6 +6,7 @@
[test_request_log.py]
[test_requests.py]
[test_rules.py]
+[test_rules_table.py]
[test_tabs.py]
[test_web_utils.py]
[test_your_policy.py]
diff --git a/tests/marionette/rp_puppeteer/tests/test_rules_table.py b/tests/marionette/rp_puppeteer/tests/test_rules_table.py
new file mode 100644
index 0000000..403f4b3
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/tests/test_rules_table.py
@@ -0,0 +1,237 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from rp_ui_harness import RequestPolicyTestCase
+from rp_puppeteer.api.rules import Rule
+from marionette import SkipTest
+from rp_ui_harness.test_data.rules import ExemplaryRules
+
+
+class RulesTableTestCase(RequestPolicyTestCase):
+
+ def setUp(self):
+ super(RulesTableTestCase, self).setUp()
+
+ self.marionette.set_context("content")
+ self.your_policy.open()
+
+ self.table = self.your_policy.rules_table
+
+ self.data = ExemplaryRules(lambda: self.marionette)
+
+ def tearDown(self):
+ try:
+ self.rules.remove_all()
+ self.marionette.set_context("chrome")
+ finally:
+ super(RulesTableTestCase, self).tearDown()
+
+
+class TestRulesTable(RulesTableTestCase):
+
+ def test_get_all_rule_rows(self):
+ raise SkipTest("The 'Rules' API doesn't support subscription rules "
+ "yet.")
+
+ def test_count_rules(self):
+ # Alias for `count_rules()`
+ count = self.table.count_rules
+
+ self.assertEqual(self.rules.count_rules(), 0,
+ "There are no user rules yet.")
+
+ # Remember the number of rule rows. The counter includes
+ # subscription rules.
+ num_rules_initial = count()
+
+ rule = self.data.some_rules[0]
+
+ # Add a rule
+ rule.add()
+ self.assertEqual(count(), num_rules_initial + 1)
+
+ # Remove the rule
+ rule.remove()
+ self.assertEqual(count(), num_rules_initial)
+
+
+class TestYourPolicyRulesTable(RulesTableTestCase):
+
+ def test_get_user_rule_rows(self):
+ self.assertEqual(len(self.table.user_rule_rows), 0,
+ "There are no user rules yet.")
+
+ # Add some rules
+ some_rules = self.data.some_rules
+ for rule in some_rules:
+ rule.add()
+
+ # Get the user rule rows.
+ user_rule_rows = self.table.user_rule_rows
+ # Compare the amount of rules.
+ self.assertEqual(len(user_rule_rows), len(some_rules),
+ "The correct amount of rules have been added.")
+
+ # Convert rule-rows to `Rule` instances.
+ returned_rules = [row.create_rule() for row in user_rule_rows]
+
+ # Compare the two `Rule` lists.
+ self.assertEqual(returned_rules.sort(), some_rules.sort(),
+ "All rules have been added and returned correctly.")
+
+ def test_get_rule_rows_by_ruleset_string(self):
+ permanent_rule = self.data.allow_rule
+ temporary_rule = self.data.temp_deny_rule
+
+ permanent_rule.add()
+ temporary_rule.add()
+
+ def get_rules(ruleset_string):
+ rule_rows = (self.table
+ .get_rule_rows_by_ruleset_string(ruleset_string))
+ return [row.create_rule() for row in rule_rows]
+
+ returned_temporary_rules = get_rules("Temporary")
+ returned_permanent_rules = get_rules("User")
+ rules_with_empty_ruleset_string = get_rules("")
+
+ self.assertEqual(returned_temporary_rules, [temporary_rule])
+ self.assertEqual(returned_permanent_rules, [permanent_rule])
+ self.assertEqual(rules_with_empty_ruleset_string, [])
+
+
+class TestRuleRow(RulesTableTestCase):
+
+ def test_policy_property(self):
+ def assert_policy(policy_string_id):
+ # Get the localized policy string.
+ expected_policy_string = self.l10n.get_rp_property(policy_string_id)
+
+ rule_row = self.table.user_rule_rows[0]
+ returned_policy_string = rule_row.policy
+
+ self.assertEqual(returned_policy_string, expected_policy_string)
+
+ def test_rule(rule, policy_string_id):
+ rule.add()
+ assert_policy(policy_string_id)
+ rule.remove()
+
+ # Test using a rule with "allow" policy.
+ test_rule(self.data.allow_rule, "allow")
+
+ # Test using a rule with "deny" policy.
+ test_rule(self.data.deny_rule, "block")
+
+ def _test_endpoint(self, endpoint):
+ assert endpoint in ["origin", "dest"]
+
+ def test(spec_id):
+ self._test_pre_path_spec(endpoint,
+ self.data.pre_path_specs[spec_id])
+
+ test("s")
+ test("h")
+ test("p")
+ test("sh")
+ test("sp")
+ test("hp")
+ test("shp")
+
+ def _test_pre_path_spec(self, endpoint, spec):
+ def create_rule():
+ """Create the rule from the spec info."""
+ endpoint_short = "o" if endpoint == "origin" else "d"
+ rule_data = {endpoint_short: spec["spec"]}
+ return self.rules.create_rule(rule_data, allow=True)
+
+ # Create and add the rule.
+ rule = create_rule()
+ rule.add()
+
+ # Check if the cell text matches the expected string.
+ rule_row = self.table.user_rule_rows[0]
+ returned_string = getattr(rule_row, endpoint)
+ self.assertEqual(returned_string, spec["expected_string"])
+
+ # Remove the rule again.
+ rule.remove()
+
+ def test_origin_property(self):
+ self._test_endpoint("origin")
+
+ def test_dest_property(self):
+ self._test_endpoint("dest")
+
+ def test_origin_empty(self):
+ self.data.rule_without_origin.add()
+ origin_string = self.table.user_rule_rows[0].origin
+ self.assertEqual(origin_string, "")
+
+ def test_dest_empty(self):
+ self.data.rule_without_dest.add()
+ dest_string = self.table.user_rule_rows[0].dest
+ self.assertEqual(dest_string, "")
+
+
+class TestYourPolicyRuleRow(RulesTableTestCase):
+
+ def test_rule_set_property(self):
+ def test(rule, expected_ruleset_string):
+ rule.add()
+ self.assertEqual(self.table.user_rule_rows[0].rule_set,
+ expected_ruleset_string)
+ rule.remove()
+
+ test(self.data.allow_rule, "User")
+ test(self.data.temp_allow_rule, "Temporary")
+
+ def test_create_rule(self):
+ def test(rule):
+ rule.add()
+ rule_row = self.table.user_rule_rows[0]
+ returned_rule = rule_row.create_rule()
+ self.assertIsInstance(returned_rule, Rule,
+ "`create_rule()` has returned a `Rule` "
+ "instance.")
+ self.assertEqual(returned_rule, rule,
+ msg=("The returned rule is identical to what "
+ "has been added."))
+ rule.remove()
+
+ # Test rules with all origin/dest fields specified.
+ test(self.data.allow_rule_shp_shp)
+ test(self.data.temp_deny_rule_shp_shp)
+
+ def test_remove_rule(self):
+ for rule in self.data.some_rules:
+ rule.add()
+ self.assertTrue(rule.exists())
+ self.table.user_rule_rows[0].remove()
+ self.assertFalse(rule.exists())
+
+ def test_is_user_rule(self):
+ def test_rule(rule, is_user_rule):
+ rule.add()
+ self.assertEqual(self.table.user_rule_rows[0].is_user_rule(),
+ is_user_rule)
+ rule.remove()
+
+ # Test some user rules, that is, both temporary and permanent rules.
+ test_rule(self.data.allow_rule, True)
+ test_rule(self.data.temp_allow_rule, True)
+
+ # TODO: Test some non-user rules (subscription rules).
+ # In those cases `is_user_rule()` should return `False`.
+
+ def test_is_temporary(self):
+ def test_rule(rule, is_temp):
+ rule.add()
+ self.assertEqual(self.table.user_rule_rows[0].is_temporary(),
+ is_temp)
+ rule.remove()
+
+ # Test both temporary and permanent rules.
+ test_rule(self.data.allow_rule, False)
+ test_rule(self.data.temp_allow_rule, True)
diff --git a/tests/marionette/rp_puppeteer/tests/test_your_policy.py b/tests/marionette/rp_puppeteer/tests/test_your_policy.py
index eee7263..9286dee 100644
--- a/tests/marionette/rp_puppeteer/tests/test_your_policy.py
+++ b/tests/marionette/rp_puppeteer/tests/test_your_policy.py
@@ -4,8 +4,6 @@
from rp_ui_harness import RequestPolicyTestCase
from rp_ui_harness.test_data.rules import ExemplaryRules
-from rp_puppeteer.api.rules import Rule
-from marionette import SkipTest
from functools import partial
@@ -45,210 +43,6 @@ class TestYourPolicy(YourPolicyTestCase):
"about:requestpolicy?yourpolicy")
-class TestRulesTable(YourPolicyTestCase):
-
- def test_get_all_rule_rows(self):
- raise SkipTest("The 'Rules' API doesn't support subscription rules "
- "yet.")
-
- def test_get_user_rule_rows(self):
- self.assertEqual(len(self._user_rule_rows), 0,
- "There are no user rules yet.")
-
- # Add some rules
- some_rules = self.data.some_rules
- for rule in some_rules:
- rule.add()
-
- # Get the user rule rows.
- user_rule_rows = self._user_rule_rows
- # Compare the amount of rules.
- self.assertEqual(len(user_rule_rows), len(some_rules),
- "The correct amount of rules have been added.")
-
- # Convert rule-rows to `Rule` instances.
- returned_rules = [row.create_rule() for row in user_rule_rows]
-
- # Compare the two `Rule` lists.
- self.assertEqual(returned_rules.sort(), some_rules.sort(),
- "All rules have been added and returned correctly.")
-
- def test_get_rule_rows_by_ruleset_string(self):
- permanent_rule = self.data.allow_rule
- temporary_rule = self.data.temp_deny_rule
-
- permanent_rule.add()
- temporary_rule.add()
-
- def get_rules(ruleset_string):
- rule_rows = (
- self.rules_table
- .get_rule_rows_by_ruleset_string(ruleset_string)
- )
- return [row.create_rule() for row in rule_rows]
-
- returned_temporary_rules = get_rules("Temporary")
- returned_permanent_rules = get_rules("User")
- rules_with_empty_ruleset_string = get_rules("")
-
- self.assertEqual(returned_temporary_rules, [temporary_rule])
- self.assertEqual(returned_permanent_rules, [permanent_rule])
- self.assertEqual(rules_with_empty_ruleset_string, [])
-
- def test_count_rules(self):
- # Alias for `count_rules()`
- count = self.rules_table.count_rules
-
- self.assertEqual(self.rules.count_rules(), 0,
- "There are no user rules yet.")
-
- # Remember the number of rule rows. The counter includes
- # subscription rules.
- num_rules_initial = count()
-
- rule = self.data.some_rules[0]
-
- # Add a rule
- rule.add()
- self.assertEqual(count(), num_rules_initial + 1)
-
- # Remove the rule
- rule.remove()
- self.assertEqual(count(), num_rules_initial)
-
-
-class TestRuleRow(YourPolicyTestCase):
-
- def test_policy_property(self):
- def assert_policy(policy_string_id):
- # Get the localized policy string.
- expected_policy_string = self.l10n.get_rp_property(policy_string_id)
-
- rule_row = self._user_rule_rows[0]
- returned_policy_string = rule_row.policy
-
- self.assertEqual(returned_policy_string, expected_policy_string)
-
- def test_rule(rule, policy_string_id):
- rule.add()
- assert_policy(policy_string_id)
- rule.remove()
-
- # Test using a rule with "allow" policy.
- test_rule(self.data.allow_rule, "allow")
-
- # Test using a rule with "deny" policy.
- test_rule(self.data.deny_rule, "block")
-
- def _test_endpoint(self, endpoint):
- assert endpoint in ["origin", "dest"]
-
- def test(spec_id):
- self._test_pre_path_spec(endpoint,
- self.data.pre_path_specs[spec_id])
-
- test("s")
- test("h")
- test("p")
- test("sh")
- test("sp")
- test("hp")
- test("shp")
-
- def _test_pre_path_spec(self, endpoint, spec):
- def create_rule():
- """Create the rule from the spec info."""
- endpoint_short = "o" if endpoint == "origin" else "d"
- rule_data = {endpoint_short: spec["spec"]}
- return self.rules.create_rule(rule_data, allow=True)
-
- # Create and add the rule.
- rule = create_rule()
- rule.add()
-
- # Check if the cell text matches the expected string.
- rule_row = self._user_rule_rows[0]
- returned_string = getattr(rule_row, endpoint)
- self.assertEqual(returned_string, spec["expected_string"])
-
- # Remove the rule again.
- rule.remove()
-
- def test_origin_property(self):
- self._test_endpoint("origin")
-
- def test_dest_property(self):
- self._test_endpoint("dest")
-
- def test_origin_empty(self):
- self.data.rule_without_origin.add()
- origin_string = self._user_rule_rows[0].origin
- self.assertEqual(origin_string, "")
-
- def test_dest_empty(self):
- self.data.rule_without_dest.add()
- dest_string = self._user_rule_rows[0].dest
- self.assertEqual(dest_string, "")
-
- def test_rule_set_property(self):
- def test(rule, expected_ruleset_string):
- rule.add()
- self.assertEqual(self._user_rule_rows[0].rule_set,
- expected_ruleset_string)
- rule.remove()
-
- test(self.data.allow_rule, "User")
- test(self.data.temp_allow_rule, "Temporary")
-
- def test_create_rule(self):
- def test(rule):
- rule.add()
- rule_row = self._user_rule_rows[0]
- returned_rule = rule_row.create_rule()
- self.assertIsInstance(returned_rule, Rule,
- "`create_rule()` has returned a `Rule` "
- "instance.")
- self.assertEqual(returned_rule, rule,
- msg=("The returned rule is identical to what "
- "has been added."))
- rule.remove()
-
- # Test rules with all origin/dest fields specified.
- test(self.data.allow_rule_shp_shp)
- test(self.data.temp_deny_rule_shp_shp)
-
- def test_remove_rule(self):
- for rule in self.data.some_rules:
- rule.add()
- self.assertTrue(rule.exists())
- self._user_rule_rows[0].remove()
- self.assertFalse(rule.exists())
-
- def test_is_user_rule(self):
- def test_rule(rule, is_user_rule):
- rule.add()
- self.assertEqual(self._user_rule_rows[0].is_user_rule(),
- is_user_rule)
- rule.remove()
-
- # Test some user rules, that is, both temporary and permanent rules.
- test_rule(self.data.allow_rule, True)
- test_rule(self.data.temp_allow_rule, True)
-
- # TODO: Test some non-user rules (subscription rules).
- # In those cases `is_user_rule()` should return `False`.
-
- def test_is_temporary(self):
- def test_rule(rule, is_temp):
- rule.add()
- self.assertEqual(self._user_rule_rows[0].is_temporary(), is_temp)
- rule.remove()
-
- # Test both temporary and permanent rules.
- test_rule(self.data.allow_rule, False)
- test_rule(self.data.temp_allow_rule, True)
-
-
class TestAddRuleForm(YourPolicyTestCase):
def setUp(self):
diff --git a/tests/marionette/rp_puppeteer/ui/settings/your_policy.py b/tests/marionette/rp_puppeteer/ui/settings/rules_table.py
similarity index 52%
copy from tests/marionette/rp_puppeteer/ui/settings/your_policy.py
copy to tests/marionette/rp_puppeteer/ui/settings/rules_table.py
index 33d02cd..738324d 100644
--- a/tests/marionette/rp_puppeteer/ui/settings/your_policy.py
+++ b/tests/marionette/rp_puppeteer/ui/settings/rules_table.py
@@ -2,86 +2,40 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-from rp_puppeteer.base import BaseLib, ElementBaseLib, HTMLFormBaseLib
-from rp_puppeteer.errors import RadioButtonException
+from rp_puppeteer.base import BaseLib, ElementBaseLib
from rp_puppeteer.api.rules import Rule
-class YourPolicy(BaseLib):
-
- @property
- def add_rule_form(self):
- form = self.marionette.find_element("id", "addruleform")
- return AddRuleForm(lambda: self.marionette, form)
-
- @property
- def rules_table(self):
- return RulesTable(lambda: self.marionette)
-
- def open(self):
- self.marionette.navigate("about:requestpolicy?yourpolicy")
-
-
-class RulesTable(BaseLib):
+class RuleRow(ElementBaseLib):
#################################
# Public Properties and Methods #
#################################
- @property
- def all_rule_rows(self):
- """Get a list of all rules."""
-
- tr_elements = self._tbody.find_elements("tag name", "tr")
- return self._create_rule_rows(tr_elements)
-
- @property
- def user_rule_rows(self):
- """Get a list of all user rules."""
-
- rows = []
- for ruleset_string in ["Temporary", "User"]:
- rows += self.get_rule_rows_by_ruleset_string(ruleset_string)
- return rows
-
- def get_rule_rows_by_ruleset_string(self, ruleset_string):
- # XPath to get all <tr> elements where the fourth <td> child (the
- # rule-set column) contains the exact string `ruleset_string`.
- xpath = "tr[./td[4]='{}']".format(ruleset_string)
- tr_elements = self._tbody.find_elements("xpath", xpath)
- return self._create_rule_rows(tr_elements)
-
- def count_rules(self):
- return self.marionette.execute_script("""
- return arguments[0].children.length
- """, script_args=[self._tbody])
+ # Properties to get the strings of the corresponding table cells.
+ policy = property(lambda self: self._get_cell_text_content(0))
+ origin = property(lambda self: self._get_cell_text_content(1))
+ dest = property(lambda self: self._get_cell_text_content(2))
##################################
# Private Properties and Methods #
##################################
@property
- def _tbody(self):
- return self.marionette.find_element("id", "rules")
-
- @property
- def _filter_field(self):
- return self.marionette.find_element("id", "rulesearch")
+ def _cells(self):
+ return self.element.find_elements("tag name", "td")
- def _create_rule_rows(self, tr_elements):
- return [RuleRow(lambda: self.marionette, tr) for tr in tr_elements]
+ def _get_cell_text_content(self, column_index):
+ return self._cells[column_index].get_attribute("textContent")
-class RuleRow(ElementBaseLib):
+class YourPolicyRuleRow(RuleRow):
#################################
# Public Properties and Methods #
#################################
# Properties to get the strings of the corresponding table cells.
- policy = property(lambda self: self._get_cell_text_content(0))
- origin = property(lambda self: self._get_cell_text_content(1))
- dest = property(lambda self: self._get_cell_text_content(2))
rule_set = property(lambda self: self._get_cell_text_content(3))
def create_rule(self):
@@ -121,115 +75,73 @@ class RuleRow(ElementBaseLib):
##################################
@property
- def _cells(self):
- return self.element.find_elements("tag name", "td")
-
- def _get_cell_text_content(self, column_index):
- return self._cells[column_index].get_attribute("textContent")
-
- @property
def _remove_anchor(self):
return self._cells[4].find_element("tag name", "a")
-class AddRuleForm(HTMLFormBaseLib):
+class RulesTable(BaseLib):
#################################
# Public Properties and Methods #
#################################
@property
- def allow(self):
- allow_selected = self._allow_radio_button.is_selected()
- deny_selected = self._deny_radio_button.is_selected()
- if allow_selected == deny_selected:
- # Either both or none of the radio buttons is selected.
- raise RadioButtonException
- return allow_selected
-
- @allow.setter
- def allow(self, value):
- if value:
- self._allow_radio_button.click()
- else:
- self._deny_radio_button.click()
+ def all_rule_rows(self):
+ """Get a list of all rules."""
- @property
- def temp(self):
- return self._temp_check_box.is_selected()
-
- @temp.setter
- def temp(self, value):
- if self.temp != value:
- # Toggle the value.
- self._temp_check_box.click()
-
- # Property attributes to get the <input> HTML elements.
- origin_scheme = HTMLFormBaseLib.input_field("name", "originscheme")
- origin_host = HTMLFormBaseLib.input_field("name", "originhost")
- origin_port = HTMLFormBaseLib.input_field("name", "originport")
- dest_scheme = HTMLFormBaseLib.input_field("name", "destscheme")
- dest_host = HTMLFormBaseLib.input_field("name", "desthost")
- dest_port = HTMLFormBaseLib.input_field("name", "destport")
-
- def set_all_values(self, allow=True, origin_scheme="", origin_host="",
- origin_port="", dest_scheme="", dest_host="",
- dest_port="", temp=False):
- """Fill all form fields.
-
- All parameters are optional, but all fields will be set. All fields
- whose parameters arent's specified will be reset.
- """
-
- self.allow = allow
- self.temp = temp
- self.origin_scheme = origin_scheme
- self.origin_host = origin_host
- self.origin_port = origin_port
- self.dest_scheme = dest_scheme
- self.dest_host = dest_host
- self.dest_port = dest_port
-
- def set_all_values_by_rule(self, rule):
- """Fill the form using a `Rule` instance."""
-
- self.allow = rule.allow
- self.temp = rule.temp
-
- for field_name in ["origin_scheme", "origin_host", "origin_port",
- "dest_scheme", "dest_host", "dest_port"]:
- # Get the field's value. If the value is not set it will be `None`,
- # so in that case `value` will be an empty string.
- value = getattr(rule, field_name) or ""
- setattr(self, field_name, value)
-
- def reset(self):
- """Reset all fields to its default value."""
-
- self.set_all_values()
-
- def submit(self):
- """Submit the form."""
-
- self._submit_button.click()
+ tr_elements = self._tbody.find_elements("tag name", "tr")
+ return self._create_rule_rows(tr_elements)
+
+ def count_rules(self):
+ return self.marionette.execute_script("""
+ return arguments[0].children.length
+ """, script_args=[self._tbody])
##################################
# Private Properties and Methods #
##################################
- @property
- def _allow_radio_button(self):
- return self.element.find_element("id", "allowrule")
+ _rule_row_class = RuleRow
@property
- def _deny_radio_button(self):
- return self.element.find_element("id", "denyrule")
+ def _tbody(self):
+ return self.marionette.find_element("id", "rules")
+
+ def _create_rule_rows(self, tr_elements):
+ return [self._create_rule_row(tr) for tr in tr_elements]
+
+ def _create_rule_row(self, tr_element):
+ return self._rule_row_class(lambda: self.marionette, tr_element)
+
+
+class YourPolicyRulesTable(RulesTable):
+
+ #################################
+ # Public Properties and Methods #
+ #################################
@property
- def _temp_check_box(self):
- return self.element.find_element("id", "temporary")
+ def user_rule_rows(self):
+ """Get a list of all user rules."""
+
+ rows = []
+ for ruleset_string in ["Temporary", "User"]:
+ rows += self.get_rule_rows_by_ruleset_string(ruleset_string)
+ return rows
+
+ def get_rule_rows_by_ruleset_string(self, ruleset_string):
+ # XPath to get all <tr> elements where the fourth <td> child (the
+ # rule-set column) contains the exact string `ruleset_string`.
+ xpath = "tr[./td[4]='{}']".format(ruleset_string)
+ tr_elements = self._tbody.find_elements("xpath", xpath)
+ return self._create_rule_rows(tr_elements)
+
+ ##################################
+ # Private Properties and Methods #
+ ##################################
+
+ _rule_row_class = YourPolicyRuleRow
@property
- def _submit_button(self):
- return self.element.find_element("css selector",
- "button[data-string=addRule]")
+ def _filter_field(self):
+ return self.marionette.find_element("id", "rulesearch")
diff --git a/tests/marionette/rp_puppeteer/ui/settings/your_policy.py b/tests/marionette/rp_puppeteer/ui/settings/your_policy.py
index 33d02cd..f0149bf 100644
--- a/tests/marionette/rp_puppeteer/ui/settings/your_policy.py
+++ b/tests/marionette/rp_puppeteer/ui/settings/your_policy.py
@@ -2,9 +2,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-from rp_puppeteer.base import BaseLib, ElementBaseLib, HTMLFormBaseLib
+from rp_puppeteer.base import BaseLib, HTMLFormBaseLib
from rp_puppeteer.errors import RadioButtonException
-from rp_puppeteer.api.rules import Rule
+from .rules_table import YourPolicyRulesTable
class YourPolicy(BaseLib):
@@ -16,122 +16,12 @@ class YourPolicy(BaseLib):
@property
def rules_table(self):
- return RulesTable(lambda: self.marionette)
+ return YourPolicyRulesTable(lambda: self.marionette)
def open(self):
self.marionette.navigate("about:requestpolicy?yourpolicy")
-class RulesTable(BaseLib):
-
- #################################
- # Public Properties and Methods #
- #################################
-
- @property
- def all_rule_rows(self):
- """Get a list of all rules."""
-
- tr_elements = self._tbody.find_elements("tag name", "tr")
- return self._create_rule_rows(tr_elements)
-
- @property
- def user_rule_rows(self):
- """Get a list of all user rules."""
-
- rows = []
- for ruleset_string in ["Temporary", "User"]:
- rows += self.get_rule_rows_by_ruleset_string(ruleset_string)
- return rows
-
- def get_rule_rows_by_ruleset_string(self, ruleset_string):
- # XPath to get all <tr> elements where the fourth <td> child (the
- # rule-set column) contains the exact string `ruleset_string`.
- xpath = "tr[./td[4]='{}']".format(ruleset_string)
- tr_elements = self._tbody.find_elements("xpath", xpath)
- return self._create_rule_rows(tr_elements)
-
- def count_rules(self):
- return self.marionette.execute_script("""
- return arguments[0].children.length
- """, script_args=[self._tbody])
-
- ##################################
- # Private Properties and Methods #
- ##################################
-
- @property
- def _tbody(self):
- return self.marionette.find_element("id", "rules")
-
- @property
- def _filter_field(self):
- return self.marionette.find_element("id", "rulesearch")
-
- def _create_rule_rows(self, tr_elements):
- return [RuleRow(lambda: self.marionette, tr) for tr in tr_elements]
-
-
-class RuleRow(ElementBaseLib):
-
- #################################
- # Public Properties and Methods #
- #################################
-
- # Properties to get the strings of the corresponding table cells.
- policy = property(lambda self: self._get_cell_text_content(0))
- origin = property(lambda self: self._get_cell_text_content(1))
- dest = property(lambda self: self._get_cell_text_content(2))
- rule_set = property(lambda self: self._get_cell_text_content(3))
-
- def create_rule(self):
- """Create a `Rule` instance for this rule row."""
-
- if not self.is_user_rule():
- # Getting non-user (e.g. subscription) rules is not implemented yet.
- raise NotImplementedError
-
- # The rule details are retained by RequestPolicy via `jQuery.data()`
- # on the "<a>x</a>" HTML anchor element, the element being clicked to
- # remove the rule.
- [rule_action, rule_data] = self.marionette.execute_script("""
- var anchor = $(arguments[0]);
- return [
- anchor.data('requestpolicyRuleAction'),
- anchor.data('requestpolicyRuleData')
- ];
- """, script_args=[self._remove_anchor])
-
- allow = True if rule_action == "allow" else False
- temp = self.is_temporary()
-
- return Rule(lambda: self.marionette, rule_data, allow, temp)
-
- def remove(self):
- self._remove_anchor.click()
-
- def is_user_rule(self):
- return self.rule_set in ["User", "Temporary"]
-
- def is_temporary(self):
- return self.rule_set == "Temporary"
-
- ##################################
- # Private Properties and Methods #
- ##################################
-
- @property
- def _cells(self):
- return self.element.find_elements("tag name", "td")
-
- def _get_cell_text_content(self, column_index):
- return self._cells[column_index].get_attribute("textContent")
-
- @property
- def _remove_anchor(self):
- return self._cells[4].find_element("tag name", "a")
-
-
class AddRuleForm(HTMLFormBaseLib):
#################################
--
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