Пример #1
0
class MandragoreBackendTestCase(TestCase):
    def setUp(self):
        self.user = User.objects.create_user(
            username="******", email="*****@*****.**", password="******"
        )

        self.backend = MandragoreBackend()

    def test_invalid_username(self):

        with self.assertRaises(PermissionDenied):
            self.backend.authenticate(username="******", password="******")

    def test_no_externaldb_in_settings(self):
        with self.settings(EXTERNAL_DATABASES=None):
            user = self.backend.authenticate(username="******", password="******")

            self.assertIsNone(user)

    def test_no_mandragore_in_externaldb_settings(self):
        with self.settings(EXTERNAL_DATABASES={}):
            user = self.backend.authenticate(username="******", password="******")
            self.assertIsNone(user)

    @override_settings(EXTERNAL_DATABASES={"mandragore": "dummy"})
    @mock.patch(
        "base.backends.get_user_from_mandragore", new=mock.MagicMock(return_value=("test_user", "$6$salt$passwd"))
    )
    def test_authentication_success(self):

        with mock.patch("crypt.crypt", new=mock.MagicMock(return_value="$6$salt$passwd")):
            user = self.backend.authenticate(username="******", password="******")

            self.assertEqual(user, self.user)

    @override_settings(EXTERNAL_DATABASES={"mandragore": "dummy"})
    @mock.patch(
        "base.backends.get_user_from_mandragore", new=mock.MagicMock(return_value=("test_user", "$6$salt$passwd"))
    )
    def test_wrong_password(self):
        user = self.backend.authenticate(username="******", password="******")

        self.assertIsNone(user)
Пример #2
0
    def setUp(self):
        self.user = User.objects.create_user(
            username="******", email="*****@*****.**", password="******"
        )

        self.backend = MandragoreBackend()