[Pkg-mozext-commits] [requestpolicy] 139/257: [tst][ref] old rules: move "typical old rules" to harness

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 f20bc97c88d1974565c335cbf32abdd79bd52429
Author: Martin Kimmerle <dev at 256k.de>
Date:   Tue Nov 17 10:40:28 2015 +0100

    [tst][ref] old rules: move "typical old rules" to harness
---
 tests/marionette/rp_ui_harness/test_data/rules.py  | 60 +++++++++++++++++++++-
 .../tests/policy/old_rules/test_import.py          | 58 ++++-----------------
 2 files changed, 69 insertions(+), 49 deletions(-)

diff --git a/tests/marionette/rp_ui_harness/test_data/rules.py b/tests/marionette/rp_ui_harness/test_data/rules.py
index e84df9d..1bf193c 100644
--- a/tests/marionette/rp_ui_harness/test_data/rules.py
+++ b/tests/marionette/rp_ui_harness/test_data/rules.py
@@ -7,14 +7,17 @@ from rp_puppeteer.api.rules import Rules
 from ..decorators import lazyprop
 
 
-class ExemplaryRules(BaseLib):
+class ExemplaryRules_Meta(BaseLib):
     """Some rules for unit tests."""
 
     def __init__(self, marionette_getter):
-        super(ExemplaryRules, self).__init__(marionette_getter)
+        super(ExemplaryRules_Meta, self).__init__(marionette_getter)
 
         self.rules = Rules(marionette_getter)
 
+
+class ExemplaryRules(ExemplaryRules_Meta):
+
     #################################
     # Public Properties and Methods #
     #################################
@@ -120,3 +123,56 @@ class ExemplaryRules(BaseLib):
 
     def _rule(self, *args, **kwargs):
         return self.rules.create_rule(*args, **kwargs)
+
+
+class ExemplaryOldRules(ExemplaryRules_Meta):
+
+    #################################
+    # Public Properties and Methods #
+    #################################
+
+    @lazyprop
+    def typical_rules(self):
+        return {
+            "v0": {
+                "allowedOriginsToDestinations": (
+                    "https://www.mozilla.org|https://mozorg.cdn.mozilla.net "
+                    "www.mozilla.org|mozorg.cdn.mozilla.net "
+                    "mozilla.org|mozilla.net"
+                ),
+                "allowedOrigins": (
+                    "https://www.mozilla.org "
+                    "www.mozilla.org "
+                    "mozilla.org"
+                ),
+                "allowedDestinations": (
+                    "https://mozorg.cdn.mozilla.net "
+                    "mozorg.cdn.mozilla.net "
+                    "mozilla.net"
+                )
+            },
+            "expected": [
+                # origin-to-destination rules
+                self._rule({"o": {"s": "https", "h": "*.www.mozilla.org"},
+                            "d": {"s": "https", "h": "*.mozorg.cdn.mozilla.net"}}),
+                self._rule({"o": {"h": "*.www.mozilla.org"},
+                            "d": {"h": "*.mozorg.cdn.mozilla.net"}}),
+                self._rule({"o": {"h": "*.mozilla.org"},
+                            "d": {"h": "*.mozilla.net"}}),
+                # origin rules
+                self._rule({"o": {"s": "https", "h": "*.www.mozilla.org"}}),
+                self._rule({"o": {"h": "*.www.mozilla.org"}}),
+                self._rule({"o": {"h": "*.mozilla.org"}}),
+                # destination rules
+                self._rule({"d": {"s": "https", "h": "*.mozorg.cdn.mozilla.net"}}),
+                self._rule({"d": {"h": "*.mozorg.cdn.mozilla.net"}}),
+                self._rule({"d": {"h": "*.mozilla.net"}})
+            ]
+        }
+
+    ##################################
+    # Private Properties and Methods #
+    ##################################
+
+    def _rule(self, rule_data):
+        return self.rules.create_rule(rule_data, allow=True, temp=False)
diff --git a/tests/marionette/tests/policy/old_rules/test_import.py b/tests/marionette/tests/policy/old_rules/test_import.py
index 23e7e0d..c3799a8 100644
--- a/tests/marionette/tests/policy/old_rules/test_import.py
+++ b/tests/marionette/tests/policy/old_rules/test_import.py
@@ -3,8 +3,8 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from rp_ui_harness.testcases import RequestPolicyTestCase
-from rp_ui_harness.decorators import lazyprop
 from marionette.marionette_test import SkipTest
+from rp_ui_harness.test_data.rules import ExemplaryOldRules
 
 
 PREF_PREFIX = "extensions.requestpolicy."
@@ -15,6 +15,14 @@ PREF_LAST_RP_VERSION = PREF_PREFIX + "lastVersion"
 
 class RulesImportTestCase(RequestPolicyTestCase):
 
+    def setUp(self):
+        super(RulesImportTestCase, self).setUp()
+
+        typical_rules = (ExemplaryOldRules(lambda: self.marionette)
+                         .typical_rules)
+        self.oldrules_prefs = typical_rules["v0"]
+        self.oldrules_rules = typical_rules["expected"]
+
     def tearDown(self):
         try:
             self.prefs.old_rules.remove_all_prefs()
@@ -22,48 +30,6 @@ class RulesImportTestCase(RequestPolicyTestCase):
         finally:
             super(RulesImportTestCase, self).tearDown()
 
-    @lazyprop
-    def _typical_rules(self):
-        return {
-            "v0": {
-                "allowedOriginsToDestinations": (
-                    "https://www.mozilla.org|https://mozorg.cdn.mozilla.net "
-                    "www.mozilla.org|mozorg.cdn.mozilla.net "
-                    "mozilla.org|mozilla.net"
-                ),
-                "allowedOrigins": (
-                    "https://www.mozilla.org "
-                    "www.mozilla.org "
-                    "mozilla.org"
-                ),
-                "allowedDestinations": (
-                    "https://mozorg.cdn.mozilla.net "
-                    "mozorg.cdn.mozilla.net "
-                    "mozilla.net"
-                )
-            },
-            "expected": [
-                # origin-to-destination rules
-                self._rule({"o": {"s": "https", "h": "*.www.mozilla.org"},
-                            "d": {"s": "https", "h": "*.mozorg.cdn.mozilla.net"}}),
-                self._rule({"o": {"h": "*.www.mozilla.org"},
-                            "d": {"h": "*.mozorg.cdn.mozilla.net"}}),
-                self._rule({"o": {"h": "*.mozilla.org"},
-                            "d": {"h": "*.mozilla.net"}}),
-                # origin rules
-                self._rule({"o": {"s": "https", "h": "*.www.mozilla.org"}}),
-                self._rule({"o": {"h": "*.www.mozilla.org"}}),
-                self._rule({"o": {"h": "*.mozilla.org"}}),
-                # destination rules
-                self._rule({"d": {"s": "https", "h": "*.mozorg.cdn.mozilla.net"}}),
-                self._rule({"d": {"h": "*.mozorg.cdn.mozilla.net"}}),
-                self._rule({"d": {"h": "*.mozilla.net"}})
-            ]
-        }
-
-    def _rule(self, rule_data):
-        return self.rules.create_rule(rule_data, allow=True, temp=False)
-
 
 class TestAutomaticRulesImportOnUpgrade(RulesImportTestCase):
 
@@ -95,8 +61,6 @@ class TestAutomaticRulesImportOnUpgrade(RulesImportTestCase):
 
     def _test_autoimport_or_not(self, is_upgrade, with_existing_rules_file,
                                 with_welcomewin, should_autoimport):
-        rules = self._typical_rules
-
         if with_existing_rules_file:
             # Ensure that a user.json file exists.
             self.rules.save()
@@ -109,9 +73,9 @@ class TestAutomaticRulesImportOnUpgrade(RulesImportTestCase):
             self.prefs.set_pref(PREF_LAST_RP_VERSION, last_rp_version)
             self.prefs.set_pref(PREF_WELCOME_WIN_SHOWN, not with_welcomewin)
 
-            self.prefs.old_rules.set_rules(rules["v0"])
+            self.prefs.old_rules.set_rules(self.oldrules_prefs)
 
-        expected_rules = rules["expected"] if should_autoimport else []
+        expected_rules = self.oldrules_rules if should_autoimport else []
         self.assertListEqual(sorted(self.rules.get_rules()),
                              sorted(expected_rules))
 

-- 
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