Skip to content

Commit

Permalink
Merge pull request #119 from NaturalHistoryMuseum/josh/test_on_210
Browse files Browse the repository at this point in the history
Add tests that work on CKAN 2.9 but break on 2.10
  • Loading branch information
jrdh authored Sep 25, 2023
2 parents 40b9069 + b68e13d commit fad9b66
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Empty file added tests/routes/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions tests/routes/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from unittest.mock import patch, MagicMock

import pytest

from ckan.lib.helpers import url_for
from ckanext.ldap.routes._helpers import login_failed, login_success


@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"))


@pytest.mark.filterwarnings("ignore::sqlalchemy.exc.SADeprecationWarning")
@pytest.mark.usefixtures("with_request_context")
def test_login_success():
username = "a_user"
came_from = "somewhere_else"

with patch("ckanext.ldap.routes._helpers.session") as mock_session:
response = login_success(username, came_from)

mock_session.__setitem__.assert_called_once_with("ckanext-ldap-user", username)
assert mock_session.save.called
assert response.status_code == 302
assert response.location.endswith(
f'{url_for("user.logged_in")}?came_from={came_from}'
)

0 comments on commit fad9b66

Please sign in to comment.