33# Licensed under the MIT License. See License.txt in the project root for
44# license information.
55# -------------------------------------------------------------------------
6- from featuremanagement ._time_window_filter ._models import RecurrencePatternType , RecurrenceRangeType , RecurrencePattern , RecurrenceRange , Recurrence
6+ from featuremanagement ._time_window_filter ._models import (
7+ RecurrencePatternType ,
8+ RecurrenceRangeType ,
9+ RecurrencePattern ,
10+ RecurrenceRange ,
11+ Recurrence ,
12+ )
713from datetime import datetime
814import math
915
16+
1017def test_recurrence_pattern_type ():
1118 assert RecurrencePatternType .from_str ("Daily" ) == RecurrencePatternType .DAILY
1219 assert RecurrencePatternType .from_str ("Weekly" ) == RecurrencePatternType .WEEKLY
@@ -15,6 +22,7 @@ def test_recurrence_pattern_type():
1522 except ValueError as e :
1623 assert str (e ) == "Invalid value: Invalid"
1724
25+
1826def test_recurrence_range_type ():
1927 assert RecurrenceRangeType .from_str ("NoEnd" ) == RecurrenceRangeType .NO_END
2028 assert RecurrenceRangeType .from_str ("EndDate" ) == RecurrenceRangeType .END_DATE
@@ -24,64 +32,97 @@ def test_recurrence_range_type():
2432 except ValueError as e :
2533 assert str (e ) == "Invalid value: Invalid"
2634
35+
2736def test_recurrence_pattern ():
28- pattern = RecurrencePattern ({"Type" :"Daily" , "Interval" :1 , "DaysOfWeek" :["Monday" , "Tuesday" ]})
37+ pattern = RecurrencePattern ({"Type" : "Daily" , "Interval" : 1 , "DaysOfWeek" : ["Monday" , "Tuesday" ]})
2938 assert pattern .type == RecurrencePatternType .DAILY
3039 assert pattern .interval == 1
3140 assert pattern .days_of_week == [0 , 1 ]
3241 assert pattern .first_day_of_week == 6
3342
34- pattern = RecurrencePattern ({"Type" :"Daily" , "Interval" :1 , "DaysOfWeek" :["Monday" , "Tuesday" ], "FirstDayOfWeek" :"Monday" })
43+ pattern = RecurrencePattern (
44+ {"Type" : "Daily" , "Interval" : 1 , "DaysOfWeek" : ["Monday" , "Tuesday" ], "FirstDayOfWeek" : "Monday" }
45+ )
3546 assert pattern .type == RecurrencePatternType .DAILY
3647 assert pattern .interval == 1
3748 assert pattern .days_of_week == [0 , 1 ]
3849 assert pattern .first_day_of_week == 0
3950
4051 try :
41- pattern = RecurrencePattern ({"Type" :"Daily" , "Interval" :1 , "DaysOfWeek" :["Monday" , "Tuesday" ], "FirstDayOfWeek" :"Thor's day" })
52+ pattern = RecurrencePattern (
53+ {"Type" : "Daily" , "Interval" : 1 , "DaysOfWeek" : ["Monday" , "Tuesday" ], "FirstDayOfWeek" : "Thor's day" }
54+ )
4255 except ValueError as e :
4356 assert str (e ) == "Invalid value for FirstDayOfWeek: Thor's day"
4457
45- pattern = RecurrencePattern ({"Type" :"Weekly" , "Interval" :2 , "DaysOfWeek" :["Wednesday" ]})
58+ pattern = RecurrencePattern ({"Type" : "Weekly" , "Interval" : 2 , "DaysOfWeek" : ["Wednesday" ]})
4659 assert pattern .type == RecurrencePatternType .WEEKLY
4760 assert pattern .interval == 2
4861 assert pattern .days_of_week == [2 ]
4962 assert pattern .first_day_of_week == 6
5063
5164 try :
52- pattern = RecurrencePattern ({"Type" :"Daily" , "Interval" :0 , "DaysOfWeek" :["Monday" , "Tuesday" ]})
65+ pattern = RecurrencePattern ({"Type" : "Daily" , "Interval" : 0 , "DaysOfWeek" : ["Monday" , "Tuesday" ]})
5366 except ValueError as e :
5467 assert str (e ) == "The interval must be greater than 0."
5568
5669 try :
57- pattern = RecurrencePattern ({"Type" :"Daily" , "Interval" :1 , "DaysOfWeek" :["Monday" , "Thor's day" ]})
70+ pattern = RecurrencePattern ({"Type" : "Daily" , "Interval" : 1 , "DaysOfWeek" : ["Monday" , "Thor's day" ]})
5871 except ValueError as e :
5972 assert str (e ) == "Invalid value for DaysOfWeek: Thor's day"
6073
74+
6175def test_recurrence_range ():
6276 max_occurrences = math .pow (2 , 63 ) - 1
6377
64- range = RecurrenceRange ({"Type" :"NoEnd" })
78+ range = RecurrenceRange ({"Type" : "NoEnd" })
6579 assert range .type == RecurrenceRangeType .NO_END
6680 assert range .end_date is None
6781 assert range .num_of_occurrences == max_occurrences
6882
69- range = RecurrenceRange ({"Type" :"EndDate" , "EndDate" :"Mon, 31 Mar 2025 00:00:00" })
83+ range = RecurrenceRange ({"Type" : "EndDate" , "EndDate" : "Mon, 31 Mar 2025 00:00:00" })
7084 assert range .type == RecurrenceRangeType .END_DATE
7185 assert range .end_date == datetime (2025 , 3 , 31 , 0 , 0 , 0 )
7286 assert range .num_of_occurrences == max_occurrences
7387
74- range = RecurrenceRange ({"Type" :"Numbered" , "NumberOfOccurrences" :10 })
88+ range = RecurrenceRange ({"Type" : "Numbered" , "NumberOfOccurrences" : 10 })
7589 assert range .type == RecurrenceRangeType .NUMBERED
7690 assert range .end_date is None
7791 assert range .num_of_occurrences == 10
7892
7993 try :
80- range = RecurrenceRange ({"Type" :"NoEnd" , "NumberOfOccurrences" :- 1 })
94+ range = RecurrenceRange ({"Type" : "NoEnd" , "NumberOfOccurrences" : - 1 })
8195 except ValueError as e :
8296 assert str (e ) == "The number of occurrences must be greater than or equal to 0."
8397
8498 try :
85- range = RecurrenceRange ({"Type" :"EndDate" , "EndDate" :"InvalidDate" })
99+ range = RecurrenceRange ({"Type" : "EndDate" , "EndDate" : "InvalidDate" })
100+ except ValueError as e :
101+ assert str (e ) == "Invalid value for EndDate: InvalidDate"
102+
103+
104+ def test_recurrence ():
105+ recurrence = Recurrence (
106+ {"Pattern" : {"Type" : "Daily" , "Interval" : 1 , "DaysOfWeek" : ["Monday" ]}, "Range" : {"Type" : "NoEnd" }}
107+ )
108+ assert recurrence .pattern .type == RecurrencePatternType .DAILY
109+ assert recurrence .range .type == RecurrenceRangeType .NO_END
110+
111+ try :
112+ recurrence = Recurrence ({"Pattern" : {"Type" : "Invalid" }, "Range" : {"Type" : "NoEnd" }})
113+ except ValueError as e :
114+ assert str (e ) == "Invalid value: Invalid"
115+
116+ try :
117+ recurrence = Recurrence (
118+ {"Pattern" : {"Type" : "Daily" , "Interval" : 0 , "DaysOfWeek" : ["Monday" ]}, "Range" : {"Type" : "NoEnd" }}
119+ )
120+ except ValueError as e :
121+ assert str (e ) == "The interval must be greater than 0."
122+
123+ try :
124+ recurrence = Recurrence (
125+ {"Pattern" : {"Type" : "Daily" , "Interval" : 1 , "DaysOfWeek" : ["Invalid" ]}, "Range" : {"Type" : "NoEnd" }}
126+ )
86127 except ValueError as e :
87- assert str (e ) == "Invalid value for EndDate: InvalidDate "
128+ assert str (e ) == "Invalid value for DaysOfWeek: Invalid "
0 commit comments