Skip to content

Commit

Permalink
test: add test for login_failed helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdh committed Sep 21, 2023
1 parent 69106a6 commit 300423d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Empty file added tests/routes/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions tests/routes/test_helpers.py
Original file line number Diff line number Diff line change
@@ -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"))

0 comments on commit 300423d

Please sign in to comment.