From 564fc7352120829ad28320eb9897736efaaa3f3e Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Fri, 23 Feb 2024 17:38:47 -0500 Subject: [PATCH] Fixed up documentation to match current state; blackened formatting Signed-off-by: Carlo Costino --- docs/end_to_end_tests.md | 29 +++++++++---------- tests/app/main/views/test_manage_users.py | 6 ++-- tests/app/main/views/test_template_folders.py | 8 +++-- tests/conftest.py | 14 +++++---- tests/end_to_end/conftest.py | 1 - 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/docs/end_to_end_tests.md b/docs/end_to_end_tests.md index 557bdf327..11758a16e 100644 --- a/docs/end_to_end_tests.md +++ b/docs/end_to_end_tests.md @@ -110,29 +110,22 @@ Inside the `tests/end_to_end` folder you'll see a `conftest.py` file, which is similar to the one found in the root `tests` folder but is specific to the E2E tests. -There a few fixtures defined in here, but the three most important at -this time are these: +There a few fixtures defined in here, but the two most important at this +time are these: - `end_to_end_context`: A Playwright context object needed to interact with a browser instance. - `authenticated_page`: A Playwright page object that has gone through the sign in process the E2E user is authenticated. -- `unauthenticated_page`: A Playwright page object that has only loaded - the home page; no authentication done. In short, if you're starting a test from scratch and testing pages that do not require authentication, you'll start with the -`unauthenticated_page` fixture and work from there. +`end_to_end_context` fixture and work from there. Any test that requires you to be authenticated, you'll start with the `authenticated_page` object as that'll have taken care of getting everything set for you and logged into the site with the E2E test user. -The `end_to_end_context` fixture is there more for the two page than for -direct use, but there may be instances where it's easier to get data -or manipulate tests in ways that are better done with the context object -instead of working back from the page object. - ### Creating a new test file @@ -153,7 +146,7 @@ much easier. ### Using the fixtures -To use the `authenticated_page` or `unauthenticated_page` fixtures, you +To use the `authenticated_page` or `end_to_end_context` fixtures, you start by defining a test function and then passing in the fixture you need as a positional argument. This works the same as the other functions defined to create a test for pytest. @@ -161,12 +154,17 @@ functions defined to create a test for pytest. For example, the test for the landing page starts with this: ```python -def test_landing_page(unauthenticated_page): - page = unauthenticated_page +def test_landing_page(end_to_end_context): + # Open a new page and go to the site. + page = end_to_end_context.browser.new_page() + page.goto(f"{E2E_TEST_URI}/") + + # Check to make sure that we've arrived at the next page. + page.wait_for_load_state("domcontentloaded") ... ``` -Note the passing in of the `unauthenticated_page` fixture - there is no +Note the passing in of the `end_to_end_context` fixture - there is no need to import this or anything, just pass it into the function. pytest takes care of everything else for you. @@ -187,7 +185,8 @@ Again, it's helpful to assign the fixture to a `page` variable for easy reference throughout the test. Lastly, if you need want access to the Playwright context object that is -used behind the page fixtures, you can reference it directly as well: +used behind the page fixtures, you can reference it directly as well +using the `end_to_end_context` fixture: ```python def test_add_new_service_workflow(authenticated_page, end_to_end_context): diff --git a/tests/app/main/views/test_manage_users.py b/tests/app/main/views/test_manage_users.py index 9bdabf925..c3d128155 100644 --- a/tests/app/main/views/test_manage_users.py +++ b/tests/app/main/views/test_manage_users.py @@ -862,9 +862,9 @@ def test_should_show_page_if_prefilled_user_is_already_invited( mock_get_invites_for_service, platform_admin_user, ): - active_user_with_permission_to_other_service[ - "email_address" - ] = "user_1@testnotify.gsa.gov" + active_user_with_permission_to_other_service["email_address"] = ( + "user_1@testnotify.gsa.gov" + ) client_request.login(platform_admin_user) mocker.patch( "app.models.user.user_api_client.get_user", diff --git a/tests/app/main/views/test_template_folders.py b/tests/app/main/views/test_template_folders.py index fae020e58..0bf2fcb08 100644 --- a/tests/app/main/views/test_template_folders.py +++ b/tests/app/main/views/test_template_folders.py @@ -31,9 +31,11 @@ def _folder(name, folder_id=None, parent=None, users_with_permission=None): "name": name, "id": folder_id or str(uuid.uuid4()), "parent_id": parent, - "users_with_permission": users_with_permission - if users_with_permission is not None - else [sample_uuid()], + "users_with_permission": ( + users_with_permission + if users_with_permission is not None + else [sample_uuid()] + ), } diff --git a/tests/conftest.py b/tests/conftest.py index 6c4f94b4f..4c2ceeea9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -904,9 +904,11 @@ def create_service_templates(service_id, number_of_templates=4): "{}_template_{}".format(template_type, template_number), template_type, "{} template {} content".format(template_type, template_number), - subject="{} template {} subject".format(template_type, template_number) - if template_type == "email" - else None, + subject=( + "{} template {} subject".format(template_type, template_number) + if template_type == "email" + else None + ), ) ) @@ -1101,9 +1103,9 @@ def active_user_with_permission_to_other_service( active_user_with_permission_to_two_services["permissions"].pop(SERVICE_ONE_ID) active_user_with_permission_to_two_services["services"].pop(0) active_user_with_permission_to_two_services["name"] = "Service Two User" - active_user_with_permission_to_two_services[ - "email_address" - ] = "service-two-user@test.gsa.gov" + active_user_with_permission_to_two_services["email_address"] = ( + "service-two-user@test.gsa.gov" + ) return active_user_with_permission_to_two_services diff --git a/tests/end_to_end/conftest.py b/tests/end_to_end/conftest.py index f21fbe0fc..16940d4e0 100644 --- a/tests/end_to_end/conftest.py +++ b/tests/end_to_end/conftest.py @@ -68,7 +68,6 @@ def login_for_end_to_end_testing(browser): context.storage_state(path=auth_state_path) - @pytest.fixture(scope="session") def end_to_end_authenticated_context(browser): # Create and load a previously authenticated context for Playwright E2E