def test_with_ipa(client, dummy_user): """Test the with_ipa decorator""" view = mock.Mock() with current_app.test_request_context('/'): ipa = maybe_ipa_login(current_app, session, "dummy", "dummy_password") wrapped = with_ipa()(view) wrapped("arg") view.assert_called_once() assert "ipa" in view.call_args_list[0][1] assert isinstance(view.call_args_list[0][1]["ipa"], ipa.__class__) assert "arg" in view.call_args_list[0][0] assert "ipa" in g assert isinstance(g.ipa, ipa.__class__) assert "current_user" in g assert g.current_user.username == "dummy"
def test_with_ipa_anonymous(client): """Test the with_ipa decorator on anonymous users""" view = mock.Mock() with current_app.test_request_context('/'): wrapped = with_ipa()(view) response = wrapped("arg") assert response.status_code == 302 assert response.location == "/" view.assert_not_called() assert "ipa" not in g assert "current_user" not in g messages = get_flashed_messages(with_categories=True) assert len(messages) == 1 category, message = messages[0] assert message == "Please log in to continue." assert category == "warning"