From 300423d72c6b89603cf409df5f3169c4da2ac048 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Thu, 21 Sep 2023 21:13:12 +0100 Subject: [PATCH] test: add test for login_failed helper --- tests/routes/__init__.py | 0 tests/routes/test_helpers.py | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/routes/__init__.py create mode 100644 tests/routes/test_helpers.py diff --git a/tests/routes/__init__.py b/tests/routes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/routes/test_helpers.py b/tests/routes/test_helpers.py new file mode 100644 index 0000000..c9ad6fe --- /dev/null +++ b/tests/routes/test_helpers.py @@ -0,0 +1,21 @@ +from unittest.mock import patch, MagicMock + +import pytest + +from ckan.lib.helpers import url_for +from ckanext.ldap.routes._helpers import login_failed + + +@pytest.mark.filterwarnings("ignore::sqlalchemy.exc.SADeprecationWarning") +@pytest.mark.usefixtures("with_request_context") +@patch("ckan.plugins.toolkit.h.flash_error") +@patch("ckan.plugins.toolkit.h.flash_notice") +def test_login_failed(flash_notice_mock: MagicMock, flash_error_mock: MagicMock): + notice = "A notice!" + error = "An error!" + response = login_failed(notice=notice, error=error) + + flash_notice_mock.assert_called_once_with(notice) + flash_error_mock.assert_called_once_with(error) + assert response.status_code == 302 + assert response.location.endswith(url_for("user.login"))