mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 16:28:25 -04:00
Refactor code. Tests still failing
This commit is contained in:
@@ -330,19 +330,20 @@ def make_session_permanent():
|
|||||||
session.permanent = True
|
session.permanent = True
|
||||||
|
|
||||||
|
|
||||||
def create_url(environment, url):
|
def create_beta_url(url):
|
||||||
url_created = urlparse(url)
|
url_created = urlparse(url)
|
||||||
if environment == "production":
|
url_list = list(url_created)
|
||||||
url_list = list(url_created)
|
url_list[1] = "beta.notify.gov"
|
||||||
url_list[1] = "beta.notify.gov"
|
url_for_redirect = urlunparse(url_list)
|
||||||
url_for_redirect = urlunparse(url_list)
|
return url_for_redirect
|
||||||
return url_for_redirect
|
|
||||||
return url
|
|
||||||
|
|
||||||
|
|
||||||
def redirect_notify_to_beta():
|
def redirect_notify_to_beta():
|
||||||
url_to_beta = create_url(current_app.config["NOTIFY_ENVIRONMENT"], request.url)
|
if (
|
||||||
if current_app.config["NOTIFY_ENVIRONMENT"] == "production":
|
current_app.config["NOTIFY_ENVIRONMENT"] == "production"
|
||||||
|
and "beta.notify.gov" not in request.url
|
||||||
|
):
|
||||||
|
url_to_beta = create_beta_url(request.url)
|
||||||
redirect(url_to_beta, 301)
|
redirect(url_to_beta, 301)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
18
tests/app/main/test_beta_redirect.py
Normal file
18
tests/app/main/test_beta_redirect.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
from flask import current_app
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from app import create_beta_url
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_beta_url():
|
||||||
|
url_for_redirect = create_beta_url("https://notify.gov/using-notify/get-started")
|
||||||
|
assert url_for_redirect == "https://beta.notify.gov/using-notify/get-started"
|
||||||
|
|
||||||
|
|
||||||
|
def test_redirect_notify_to_beta(monkeypatch, client_request):
|
||||||
|
monkeypatch.setitem(current_app.config, "NOTIFY_ENVIRONMENT", "production")
|
||||||
|
# import pdb
|
||||||
|
# pdb.set_trace()
|
||||||
|
# resp = client_request.get_response_from_url("https://notify.gov/using-notify/get-started")
|
||||||
|
# assert resp.status_code == 301
|
||||||
|
assert current_app.config["NOTIFY_ENVIRONMENT"] == "production"
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from unittest.mock import ANY
|
from unittest.mock import ANY
|
||||||
|
|
||||||
from app import create_url
|
|
||||||
from app.event_handlers import (
|
from app.event_handlers import (
|
||||||
create_add_user_to_service_event,
|
create_add_user_to_service_event,
|
||||||
create_archive_service_event,
|
create_archive_service_event,
|
||||||
@@ -130,15 +129,3 @@ def test_set_user_permissions(client_request, mock_events):
|
|||||||
|
|
||||||
create_set_user_permissions_event(**kwargs)
|
create_set_user_permissions_event(**kwargs)
|
||||||
mock_events.assert_called_with("set_user_permissions", event_dict(**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