[Pkg-mozext-commits] [requestpolicy] 148/257: [tst][fix] RPTestCase: leaked rules in rules file
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:20:07 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 52d7665798293e80b15c876925d39fb5cd947bb4
Author: Martin Kimmerle <dev at 256k.de>
Date: Thu Nov 19 00:47:55 2015 +0100
[tst][fix] RPTestCase: leaked rules in rules file
A test must not leak rules in the rules file.
---
tests/marionette/rp_puppeteer/api/rules.py | 6 ++++--
tests/marionette/rp_puppeteer/tests/test_your_policy.py | 5 +++--
tests/marionette/rp_ui_harness/testcases.py | 13 +++++++++++--
tests/marionette/tests/policy/old_rules/test_import.py | 2 +-
4 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/tests/marionette/rp_puppeteer/api/rules.py b/tests/marionette/rp_puppeteer/api/rules.py
index e2b0d43..9d3034b 100644
--- a/tests/marionette/rp_puppeteer/api/rules.py
+++ b/tests/marionette/rp_puppeteer/api/rules.py
@@ -66,9 +66,11 @@ class Rules(BaseLib):
counter += self._count_rules(allow_value, temp_value)
return counter
- def remove_all(self):
+ def remove_all(self, store=False):
for rule in self.all:
- rule.remove()
+ rule.remove(store=False)
+ if store:
+ self.save()
def save(self):
"""Save the rules to the json file."""
diff --git a/tests/marionette/rp_puppeteer/tests/test_your_policy.py b/tests/marionette/rp_puppeteer/tests/test_your_policy.py
index e34df7a..2ec8805 100644
--- a/tests/marionette/rp_puppeteer/tests/test_your_policy.py
+++ b/tests/marionette/rp_puppeteer/tests/test_your_policy.py
@@ -179,8 +179,9 @@ class TestAddRuleForm(YourPolicyTestCase):
self.add_rule_form.set_all_values_by_rule(rule)
# Submit and compare.
submit_and_compare(rule)
- # Remove the rule again.
- rule.remove()
+ # Remove the rule again. The rules file must be updated
+ # because submitting the form has saved the rule.
+ rule.remove(store=True)
# Test some rules which make use of all fields.
test_rule(self.data.allow_rule_shp_shp)
diff --git a/tests/marionette/rp_ui_harness/testcases.py b/tests/marionette/rp_ui_harness/testcases.py
index 2aeea4e..af2b35b 100644
--- a/tests/marionette/rp_ui_harness/testcases.py
+++ b/tests/marionette/rp_ui_harness/testcases.py
@@ -35,7 +35,8 @@ class RequestPolicyTestCase(RequestPolicyPuppeteer, FirefoxTestCase):
def tearDown(self, *args, **kwargs):
try:
- self._check_rules_and_remove_all()
+ self._check_and_fix_leaked_rules()
+ self._check_and_fix_leaked_rules_in_rules_file()
self._check_and_reset_error_counts()
finally:
FirefoxTestCase.tearDown(self, *args, **kwargs)
@@ -44,7 +45,7 @@ class RequestPolicyTestCase(RequestPolicyPuppeteer, FirefoxTestCase):
# Private Properties and Methods #
##################################
- def _check_rules_and_remove_all(self):
+ def _check_and_fix_leaked_rules(self):
try:
n_rules = self.rules.count_rules()
self.assertEqual(n_rules, 0,
@@ -53,6 +54,14 @@ class RequestPolicyTestCase(RequestPolicyPuppeteer, FirefoxTestCase):
finally:
self.rules.remove_all()
+ def _check_and_fix_leaked_rules_in_rules_file(self):
+ rules = self.rules_file.get_rules()
+ n_rules = 0 if rules is None else len(rules)
+ if n_rules != 0:
+ self.rules.save()
+ self.fail("A test must not leak rules in the rules file. "
+ "Rule count is {} but should be zero.".format(n_rules))
+
def _check_and_reset_error_counts(self):
try:
self.assertEqual(self.logging_error_detect.n_errors, 0,
diff --git a/tests/marionette/tests/policy/old_rules/test_import.py b/tests/marionette/tests/policy/old_rules/test_import.py
index d072c29..1fcdf9e 100644
--- a/tests/marionette/tests/policy/old_rules/test_import.py
+++ b/tests/marionette/tests/policy/old_rules/test_import.py
@@ -26,7 +26,7 @@ class RulesImportTestCase(RequestPolicyTestCase):
def tearDown(self):
try:
self.prefs.old_rules.remove_all_prefs()
- self.rules.remove_all()
+ self.rules.remove_all(store=True)
finally:
super(RulesImportTestCase, self).tearDown()
--
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