Skip to content

Commit

Permalink
Add additional /timezone test (#989)
Browse files Browse the repository at this point in the history
## Fixes issue
#323

## Description of Changes
Added test to cover an empty string timezone being passed.
  • Loading branch information
michplunkett authored Jul 25, 2023
1 parent b28955a commit 4500b87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions OpenOversight/tests/routes/route_helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from faker import Faker
from flask import url_for

from OpenOversight.app.auth.forms import LoginForm


ADMIN_EMAIL = "[email protected]"
ADMIN_PASSWORD = "testtest"
FAKER = Faker()


def login_user(client):
Expand Down
20 changes: 17 additions & 3 deletions OpenOversight/tests/routes/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask import current_app, url_for

from OpenOversight.app.utils.constants import ENCODING_UTF_8, KEY_TIMEZONE
from OpenOversight.tests.routes.route_helpers import login_user
from OpenOversight.tests.routes.route_helpers import FAKER, login_user


@pytest.mark.parametrize(
Expand Down Expand Up @@ -58,12 +58,26 @@ def test_user_can_access_profile_differently_cased(mockdata, client, session):

def test_timezone_setting(client):
with current_app.test_request_context():
test_tz = FAKER.timezone()
with client.session_transaction() as session:
assert KEY_TIMEZONE not in session
rv = client.post(
url_for("main.set_session_timezone"),
data="A TIMEZONE".encode(ENCODING_UTF_8),
data=test_tz.encode(ENCODING_UTF_8),
)
assert rv.status_code == HTTPStatus.OK
with client.session_transaction() as session:
assert session[KEY_TIMEZONE] == "A TIMEZONE"
assert session[KEY_TIMEZONE] == test_tz


def test_timezone_setting_empty_string(client):
with current_app.test_request_context():
with client.session_transaction() as session:
assert KEY_TIMEZONE not in session
rv = client.post(
url_for("main.set_session_timezone"),
data="".encode(ENCODING_UTF_8),
)
assert rv.status_code == HTTPStatus.OK
with client.session_transaction() as session:
assert session[KEY_TIMEZONE] == current_app.config.get(KEY_TIMEZONE)

0 comments on commit 4500b87

Please sign in to comment.