mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-16 19:30:13 -04:00
Redirect implemented with tests coverage
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import pathlib
|
||||
from functools import partial
|
||||
from time import monotonic
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
import jinja2
|
||||
from flask import (
|
||||
@@ -254,6 +255,7 @@ def create_app(application):
|
||||
|
||||
|
||||
def init_app(application):
|
||||
application.before_request(redirect_notify_to_beta)
|
||||
application.before_request(load_service_before_request)
|
||||
application.before_request(load_organization_before_request)
|
||||
application.before_request(request_helper.check_proxy_header_before_request)
|
||||
@@ -332,6 +334,22 @@ def make_session_permanent():
|
||||
session.permanent = True
|
||||
|
||||
|
||||
def create_url(environment, url):
|
||||
url_created = urlparse(url)
|
||||
if environment == "production":
|
||||
url_list = list(url_created)
|
||||
url_list[1] = "beta.notify.gov"
|
||||
url_for_redirect = urlunparse(url_list)
|
||||
return url_for_redirect
|
||||
return url
|
||||
|
||||
|
||||
def redirect_notify_to_beta():
|
||||
url_to_beta = create_url(current_app.config["NOTIFY_ENVIRONMENT"], request.url)
|
||||
if current_app.config["NOTIFY_ENVIRONMENT"] == "production":
|
||||
redirect(url_to_beta, 301)
|
||||
|
||||
|
||||
def load_service_before_request():
|
||||
if "/static/" in request.url:
|
||||
request_ctx.service = None
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
from unittest.mock import ANY
|
||||
|
||||
from app import create_url
|
||||
from app.event_handlers import (
|
||||
create_add_user_to_service_event,
|
||||
create_archive_service_event,
|
||||
@@ -129,3 +130,15 @@ def test_set_user_permissions(client_request, mock_events):
|
||||
|
||||
create_set_user_permissions_event(**kwargs)
|
||||
mock_events.assert_called_with("set_user_permissions", event_dict(**kwargs))
|
||||
|
||||
|
||||
def test_create_url():
|
||||
url_for_redirect = create_url(
|
||||
"production", "https://notify.gov/using-notify/get-started"
|
||||
)
|
||||
assert url_for_redirect == "https://beta.notify.gov/using-notify/get-started"
|
||||
|
||||
|
||||
def test_create_url_non_production():
|
||||
url = create_url("development", "https://notify.gov/using-notify/get-started")
|
||||
assert url == "https://notify.gov/using-notify/get-started"
|
||||
|
||||
Reference in New Issue
Block a user