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