Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional /timezone test #989

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)