From 109f3d99929ef84c86a1838b0d8a64f08501a038 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 31 Oct 2024 12:04:26 -0700 Subject: [PATCH] feature flag for testing --- app/main/views/index.py | 17 +++++- .../test_best_practices_content_pages.py | 58 +++++++++++-------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/app/main/views/index.py b/app/main/views/index.py index 8b965991c..238f2d524 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -2,7 +2,15 @@ import os import secrets from urllib.parse import unquote -from flask import abort, current_app, redirect, render_template, request, url_for +from flask import ( + abort, + current_app, + jsonify, + redirect, + render_template, + request, + url_for, +) from flask_login import current_user from app import redis_client, status_api_client @@ -30,6 +38,13 @@ def check_guidance_feature(): abort(404) +@main.route("/test/feature-flags") +def test_feature_flags(): + return jsonify({ + "FEATURE_BEST_PRACTICES_ENABLED": current_app.config["FEATURE_BEST_PRACTICES_ENABLED"] + }) + + @main.route("/") def index(): if current_user and current_user.is_authenticated: diff --git a/tests/end_to_end/test_best_practices_content_pages.py b/tests/end_to_end/test_best_practices_content_pages.py index fbf5cd280..962100de3 100644 --- a/tests/end_to_end/test_best_practices_content_pages.py +++ b/tests/end_to_end/test_best_practices_content_pages.py @@ -16,38 +16,43 @@ def test_best_practices_side_menu(authenticated_page): page.wait_for_load_state("domcontentloaded") check_axe_report(page) - page.get_by_role("link", name="Best Practices").click() - expect(page).to_have_title(re.compile("Best Practice")) + response = page.request.get(f"{E2E_TEST_URI}/test/feature-flags") + feature_flags = response.json() + feature_best_practices_enabled = feature_flags.get("FEATURE_BEST_PRACTICES_ENABLED") - page.get_by_role("link", name="Clear goals", exact=True).click() - expect(page).to_have_title(re.compile("Establish clear goals")) + if feature_best_practices_enabled: + page.get_by_role("link", name="Best Practices").click() + expect(page).to_have_title(re.compile("Best Practice")) - page.get_by_role("link", name="Rules and regulations").click() - expect(page).to_have_title(re.compile("Rules and regulations")) + page.get_by_role("link", name="Clear goals", exact=True).click() + expect(page).to_have_title(re.compile("Establish clear goals")) - page.get_by_role("link", name="Establish trust").click() - expect(page).to_have_title(re.compile("Establish trust")) + page.get_by_role("link", name="Rules and regulations").click() + expect(page).to_have_title(re.compile("Rules and regulations")) - page.get_by_role("link", name="Write for action").click() - expect(page).to_have_title(re.compile("Write texts that provoke")) + page.get_by_role("link", name="Establish trust").click() + expect(page).to_have_title(re.compile("Establish trust")) - page.get_by_role("link", name="Multiple languages").click() - expect(page).to_have_title(re.compile("Text in multiple languages")) + page.get_by_role("link", name="Write for action").click() + expect(page).to_have_title(re.compile("Write texts that provoke")) - page.get_by_role("link", name="Benchmark performance").click() - expect(page).to_have_title(re.compile("Measuring performance with")) + page.get_by_role("link", name="Multiple languages").click() + expect(page).to_have_title(re.compile("Text in multiple languages")) - parent_link = page.get_by_role("link", name="Establish trust") - parent_link.hover() + page.get_by_role("link", name="Benchmark performance").click() + expect(page).to_have_title(re.compile("Measuring performance with")) - submenu_item = page.get_by_role("link", name=re.compile("Get the word out")) - submenu_item.click() + parent_link = page.get_by_role("link", name="Establish trust") + parent_link.hover() - expect(page).to_have_url(re.compile(r"#get-the-word-out")) + submenu_item = page.get_by_role("link", name=re.compile("Get the word out")) + submenu_item.click() - anchor_target = page.locator("#get-the-word-out") - expect(anchor_target).to_be_visible() - anchor_target.click() + expect(page).to_have_url(re.compile(r"#get-the-word-out")) + + anchor_target = page.locator("#get-the-word-out") + expect(anchor_target).to_be_visible() + anchor_target.click() def test_breadcrumbs_best_practices(authenticated_page): @@ -58,5 +63,10 @@ def test_breadcrumbs_best_practices(authenticated_page): page.wait_for_load_state("domcontentloaded") check_axe_report(page) - page.get_by_role("link", name="Clear goals", exact=True).click() - page.locator("ol").get_by_role("link", name="Best Practices").click() + response = page.request.get(f"{E2E_TEST_URI}/test/feature-flags") + feature_flags = response.json() + feature_best_practices_enabled = feature_flags.get("FEATURE_BEST_PRACTICES_ENABLED") + + if feature_best_practices_enabled: + page.get_by_role("link", name="Clear goals", exact=True).click() + page.locator("ol").get_by_role("link", name="Best Practices").click()