Exemplo n.º 1
0
    def assert_patched(self, context=None):
        """helper to ensure django HAS been patched, and is using specified config"""
        # make sure we're currently patched
        mod = sys.modules.get("passlib.ext.django.models")
        self.assertTrue(mod and mod.adapter.patched,
                        "patch should have been enabled")

        # make sure only the expected objects have been patched
        for obj, attr, source, patched in self._iter_patch_candidates():
            if patched:
                self.assertTrue(
                    source == "passlib.ext.django.utils",
                    "obj=%r attr=%r should have been patched: %r" %
                    (obj, attr, source))
            else:
                self.assertFalse(
                    source.startswith("passlib."),
                    "obj=%r attr=%r should not have been patched: %r" %
                    (obj, attr, source))

        # check context matches
        if context is not None:
            context = CryptContext._norm_source(context)
            self.assertEqual(mod.password_context.to_dict(resolve=True),
                             context.to_dict(resolve=True))
Exemplo n.º 2
0
    def assert_patched(self, context=None):
        """helper to ensure django HAS been patched, and is using specified config"""
        # make sure we're currently patched
        mod = sys.modules.get("passlib.ext.django.models")
        self.assertTrue(mod and mod._patched, "patch should have been enabled")

        # make sure only the expected objects have been patched
        for obj, attr, source, patched in self._iter_patch_candidates():
            if patched:
                self.assertTrue(source == "passlib.ext.django.models",
                                "obj=%r attr=%r should have been patched: %r" %
                                (obj, attr, source))
            else:
                self.assertFalse(source.startswith("passlib."),
                                "obj=%r attr=%r should not have been patched: %r" %
                                (obj, attr, source))

        # check context matches
        if context is not None:
            context = CryptContext._norm_source(context)
            self.assertEqual(mod.password_context.to_dict(resolve=True),
                             context.to_dict(resolve=True))
Exemplo n.º 3
0
 def context(self):
     return CryptContext._norm_source(self.config)
Exemplo n.º 4
0
 def context(self):
     return CryptContext._norm_source(self.config)
Exemplo n.º 5
0
 def context(self):
     """
     per-test CryptContext() created from .config.
     """
     return CryptContext._norm_source(self.config)