Files
notifications-admin/tests/app/main/test_choose_time_form.py
Ben Thorner 5bfce61bcf Rename "app_" fixture to "notify_admin"
This naming was introduced in 2016 without explanation [1]. I find it
confusing because:

- It's reminiscent of "_app", which is a Python convention indicating
the variable is internal, so maybe avoid using it.

- It suggests there's some other "app" fixture I should be using (there
isn't, though).

The Python style guide describes using an underscore suffix to avoid
clashes with inbuilt names [1], which is sort of applicable if we need
to import the "app" module [2]. However, we can also avoid clashes by
choosing a different name, without the strange underscore.

[1]: 3b1d521c10
[2]: 78824f54fd/tests/app/main/views/test_forgot_password.py (L5)
2021-05-19 11:44:20 +01:00

46 lines
1.3 KiB
Python

import pytest
from freezegun import freeze_time
from app.main.forms import ChooseTimeForm
@freeze_time("2016-01-01 11:09:00.061258")
def test_form_contains_next_24h(notify_admin):
choices = ChooseTimeForm().scheduled_for.choices
# Friday
assert choices[0] == ('', 'Now')
assert choices[1] == ('2016-01-01T12:00:00', 'Today at midday')
assert choices[13] == ('2016-01-02T00:00:00', 'Today at midnight')
# Saturday
assert choices[14] == ('2016-01-02T01:00:00', 'Tomorrow at 1am')
assert choices[37] == ('2016-01-03T00:00:00', 'Tomorrow at midnight')
# Sunday
assert choices[38] == ('2016-01-03T01:00:00', 'Sunday at 1am')
# Monday
assert choices[84] == ('2016-01-04T23:00:00', 'Monday at 11pm')
assert choices[85] == ('2016-01-05T00:00:00', 'Monday at midnight')
with pytest.raises(IndexError):
assert choices[
12 + # hours left in the day
(3 * 24) + # 3 days
2 # magic number
]
@freeze_time("2016-01-01 11:09:00.061258")
def test_form_defaults_to_now(notify_admin):
assert ChooseTimeForm().scheduled_for.data == ''
@freeze_time("2016-01-01 11:09:00.061258")
def test_form_contains_next_three_days(notify_admin):
assert ChooseTimeForm().scheduled_for.categories == [
'Later today', 'Tomorrow', 'Sunday', 'Monday'
]