Skip to content

Commit

Permalink
test: add a test for login_success
Browse files Browse the repository at this point in the history
This is an important test as it is something that works on CKAN 2.9 but not on CKAN 2.10.
  • Loading branch information
jrdh committed Sep 21, 2023
1 parent 300423d commit b68e13d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/routes/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

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


@pytest.mark.filterwarnings("ignore::sqlalchemy.exc.SADeprecationWarning")
Expand All @@ -19,3 +19,20 @@ def test_login_failed(flash_notice_mock: MagicMock, flash_error_mock: MagicMock)
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 b68e13d

Please sign in to comment.