From c37258fd0deedf0144857234e6ffef600c79b4f6 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 4 Jan 2022 19:04:45 +0000 Subject: [PATCH] Stop using `logged_in_client_with_session` fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have a `client_request` fixture which does a bunch of useful stuff like: - checking the status code of the response - returning a `BeautifulSoup` object A few of our tests still use an older fixture called `logged_in_client_with_session`. It’s not clear how this is different from `logged_in_client`, which we have replaced with `client_request`. So this commit goes ahead and converts all the tests using `logged_in_client_with_session` to use `client_request` instead. --- tests/app/main/views/test_sign_out.py | 36 +++++++++++++++------------ tests/conftest.py | 19 -------------- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/tests/app/main/views/test_sign_out.py b/tests/app/main/views/test_sign_out.py index 217fb3a35..e9b795241 100644 --- a/tests/app/main/views/test_sign_out.py +++ b/tests/app/main/views/test_sign_out.py @@ -4,16 +4,18 @@ from tests.conftest import SERVICE_ONE_ID def test_render_sign_out_redirects_to_sign_in( - logged_in_client_with_session + client_request ): - with logged_in_client_with_session.session_transaction() as session: + with client_request.session_transaction() as session: assert session - response = logged_in_client_with_session.get( - url_for('main.sign_out')) - assert response.status_code == 302 - assert response.location == url_for( - 'main.index', _external=True) - with logged_in_client_with_session.session_transaction() as session: + client_request.get( + 'main.sign_out', + _expected_redirect=url_for( + 'main.index', + _external=True, + ) + ) + with client_request.session_transaction() as session: assert not session @@ -54,13 +56,15 @@ def test_sign_out_user( def test_sign_out_of_two_sessions( - logged_in_client_with_session + client_request ): - logged_in_client_with_session.get( - url_for('main.sign_out')) - with logged_in_client_with_session.session_transaction() as session: + client_request.get( + 'main.sign_out', + _expected_status=302, + ) + with client_request.session_transaction() as session: assert not session - response = logged_in_client_with_session.get( - url_for('main.sign_out')) - - assert response.status_code == 302 + client_request.get( + 'main.sign_out', + _expected_status=302, + ) diff --git a/tests/conftest.py b/tests/conftest.py index b87432186..076b1b684 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1139,13 +1139,6 @@ def active_user_approve_broadcasts_permission(): return create_active_user_approve_broadcasts_permissions() -@pytest.fixture(scope='function') -def active_user_with_session(fake_uuid): - return create_service_one_admin( - id=fake_uuid, - ) - - @pytest.fixture(scope='function') def active_user_with_permission_to_two_services(fake_uuid): permissions = [ @@ -2756,18 +2749,6 @@ def _logged_in_client( yield client -@pytest.fixture(scope='function') -def logged_in_client_with_session( - client, - active_user_with_session, - mocker, - service_one, - mock_login -): - client.login(active_user_with_session, mocker, service_one) - yield client - - @pytest.fixture def os_environ(): """