815 |
815 |
(datetime.date(2020, 7, 14), False),
|
816 |
816 |
(datetime.date(2020, 7, 15), True),
|
817 |
817 |
])
|
818 |
|
def test_is_working_day(settings, value, expected):
|
|
818 |
def test_is_working_day(settings, pub, value, expected):
|
819 |
819 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
820 |
820 |
t = Template('{{ value|is_working_day }}')
|
821 |
821 |
assert t.render({'value': value}) == str(expected)
|
... | ... | |
823 |
823 |
assert t.render({'value': value}) == str(expected)
|
824 |
824 |
|
825 |
825 |
|
826 |
|
def test_is_working_day_weekend(settings):
|
|
826 |
def test_is_working_day_weekend(settings, pub):
|
827 |
827 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
828 |
828 |
# check saturday
|
829 |
829 |
t = Template('{{ value|is_working_day }}')
|
... | ... | |
878 |
878 |
assert t.render({'value': '2020-07-13'}) == '2020-07-15'
|
879 |
879 |
|
880 |
880 |
|
881 |
|
def test_add_working_days_arg(settings):
|
|
881 |
def test_add_working_days_arg(settings, pub):
|
882 |
882 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
883 |
883 |
t = Template('{{ value|add_working_days:"foobar" }}')
|
884 |
884 |
assert t.render({'value': '2020-07-13'}) == ''
|
... | ... | |
903 |
903 |
(datetime.datetime(2020, 7, 13, 12, 1, 3), '2020-07-15'),
|
904 |
904 |
(datetime.date(2020, 7, 13), '2020-07-15'),
|
905 |
905 |
])
|
906 |
|
def test_add_working_days(settings, value, expected):
|
|
906 |
def test_add_working_days(settings, pub, value, expected):
|
907 |
907 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
908 |
908 |
t = Template('{{ value|add_working_days:1 }}')
|
909 |
909 |
assert t.render({'value': value}) == str(expected)
|
... | ... | |
911 |
911 |
assert t.render({'value': value}) == str(expected)
|
912 |
912 |
|
913 |
913 |
|
914 |
|
def test_add_working_days_weekend(settings):
|
|
914 |
def test_add_working_days_weekend(settings, pub):
|
915 |
915 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
916 |
916 |
t = Template('{{ value|add_working_days:1 }}')
|
917 |
917 |
assert t.render({'value': '2020-06-19'}) == '2020-06-22'
|
... | ... | |
974 |
974 |
(datetime.date(2020, 7, 14), '2020-07-15'),
|
975 |
975 |
(datetime.date(2020, 7, 15), '2020-07-15'),
|
976 |
976 |
])
|
977 |
|
def test_adjust_to_working_day(settings, value, expected):
|
|
977 |
def test_adjust_to_working_day(settings, pub, value, expected):
|
978 |
978 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
979 |
979 |
t = Template('{{ value|adjust_to_working_day }}')
|
980 |
980 |
assert t.render({'value': value}) == str(expected)
|
... | ... | |
982 |
982 |
assert t.render({'value': value}) == str(expected)
|
983 |
983 |
|
984 |
984 |
|
985 |
|
def test_adjust_to_working_day_weekend(settings):
|
|
985 |
def test_adjust_to_working_day_weekend(settings, pub):
|
986 |
986 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
987 |
987 |
t = Template('{{ value|adjust_to_working_day }}')
|
988 |
988 |
assert t.render({'value': '2020-06-20'}) == '2020-06-22'
|
... | ... | |
990 |
990 |
assert t.render({'value': '2020-06-20'}) == '2020-06-20'
|
991 |
991 |
|
992 |
992 |
|
|
993 |
def test_age_in_working_days_settings(settings, pub):
|
|
994 |
settings.WORKING_DAY_CALENDAR = None
|
|
995 |
t = Template('{{ value|age_in_working_days:"2020-07-15" }}')
|
|
996 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
997 |
t = Template('{{ value|age_in_working_days_with_saturday:"2020-07-15" }}')
|
|
998 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
999 |
|
|
1000 |
settings.WORKING_DAY_CALENDAR = ''
|
|
1001 |
t = Template('{{ value|age_in_working_days:"2020-07-15" }}')
|
|
1002 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
1003 |
t = Template('{{ value|age_in_working_days_with_saturday:"2020-07-15" }}')
|
|
1004 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
1005 |
|
|
1006 |
settings.WORKING_DAY_CALENDAR = 'foobar'
|
|
1007 |
t = Template('{{ value|age_in_working_days:"2020-07-15" }}')
|
|
1008 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
1009 |
t = Template('{{ value|age_in_working_days_with_saturday:"2020-07-15" }}')
|
|
1010 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
1011 |
|
|
1012 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
|
1013 |
t = Template('{{ value|age_in_working_days:"2020-07-15" }}')
|
|
1014 |
assert t.render({'value': '2020-07-12'}) == '2'
|
|
1015 |
t = Template('{{ value|age_in_working_days_with_saturday:"2020-07-15" }}')
|
|
1016 |
assert t.render({'value': '2020-07-12'}) == '2'
|
|
1017 |
|
|
1018 |
pub.site_options.set('options', 'working_day_calendar', 'foobar')
|
|
1019 |
pub.site_options.write(open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w'))
|
|
1020 |
t = Template('{{ value|age_in_working_days:"2020-07-15" }}')
|
|
1021 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
1022 |
t = Template('{{ value|age_in_working_days_with_saturday:"2020-07-15" }}')
|
|
1023 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
1024 |
|
|
1025 |
settings.WORKING_DAY_CALENDAR = 'foobar'
|
|
1026 |
pub.site_options.set('options', 'working_day_calendar', 'workalendar.europe.France')
|
|
1027 |
pub.site_options.write(open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w'))
|
|
1028 |
t = Template('{{ value|age_in_working_days:"2020-07-15" }}')
|
|
1029 |
assert t.render({'value': '2020-07-12'}) == '2'
|
|
1030 |
t = Template('{{ value|age_in_working_days_with_saturday:"2020-07-15" }}')
|
|
1031 |
assert t.render({'value': '2020-07-12'}) == '2'
|
|
1032 |
|
|
1033 |
|
|
1034 |
def test_age_in_working_days_arg(settings, pub):
|
|
1035 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
|
1036 |
t = Template('{{ value|age_in_working_days:"foobar" }}')
|
|
1037 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
1038 |
t = Template('{{ value|age_in_working_days_with_saturday:"foobar" }}')
|
|
1039 |
assert t.render({'value': '2020-07-12'}) == ''
|
|
1040 |
t = Template('{{ value|age_in_working_days:"2020-07-15" }}')
|
|
1041 |
assert t.render({'value': '2020-07-12'}) == '2'
|
|
1042 |
t = Template('{{ value|age_in_working_days_with_saturday:"2020-07-15" }}')
|
|
1043 |
assert t.render({'value': '2020-07-12'}) == '2'
|
|
1044 |
|
|
1045 |
|
|
1046 |
@pytest.mark.parametrize('value, expected', [
|
|
1047 |
(None, ''),
|
|
1048 |
('', ''),
|
|
1049 |
('foobar', ''),
|
|
1050 |
(42, ''),
|
|
1051 |
('2020-07-14T12:01:03', '2'),
|
|
1052 |
('2020-07-14 02:03', '2'),
|
|
1053 |
('14/07/2020 02h03', '2'),
|
|
1054 |
('2020-07-14', '2'),
|
|
1055 |
('14/07/2020', '2'),
|
|
1056 |
(datetime.datetime(2020, 7, 14, 12, 1, 3), '2'),
|
|
1057 |
(datetime.date(2020, 7, 14), '2'),
|
|
1058 |
(datetime.date(2020, 7, 15), '1'),
|
|
1059 |
])
|
|
1060 |
def test_age_in_working_days(settings, pub, value, expected):
|
|
1061 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
|
1062 |
t = Template('{{ value|age_in_working_days:"2020-07-16" }}')
|
|
1063 |
assert t.render({'value': value}) == str(expected)
|
|
1064 |
t = Template('{{ value|age_in_working_days_with_saturday:"2020-07-16" }}')
|
|
1065 |
assert t.render({'value': value}) == str(expected)
|
|
1066 |
|
|
1067 |
|
|
1068 |
def test_age_in_working_days_weekend(settings, pub):
|
|
1069 |
settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France'
|
|
1070 |
t = Template('{{ value|age_in_working_days:"2020-06-22" }}')
|
|
1071 |
assert t.render({'value': '2020-06-19'}) == '1'
|
|
1072 |
t = Template('{{ value|age_in_working_days_with_saturday:"2020-06-22" }}')
|
|
1073 |
assert t.render({'value': '2020-06-19'}) == '2'
|
|
1074 |
|
|
1075 |
|
993 |
1076 |
def test_sum():
|
994 |
1077 |
tmpl = Template('{{ "2 29.5 9,5 .5"|split|sum }}')
|
995 |
1078 |
assert tmpl.render({}) == '41.5'
|