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
Adding Schedules Support Round 2 #48
Changes from 1 commit
03e8ce3
312a1c7
b32a632
0adb03f
66e1793
0342bed
bb9ff8f
34457b3
f4490fb
79271a1
b710d9d
46cc1d0
fd17154
371b6f9
28ebb9e
c330687
d7add3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ class Frequency: | |
Monthly = "Monthly" | ||
|
||
class Occurrence: | ||
Hours = "Hours" | ||
Minutes = "Minutes" | ||
Hours = "hours" | ||
Minutes = "minutes" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minutes should come before hours. |
||
WeekDay = "weekDay" | ||
MonthDay = "monthDay" | ||
|
||
|
@@ -75,6 +75,20 @@ def from_xml_element(cls, parsed_response, frequency): | |
|
||
class HourlyInterval(IntervalItem): | ||
def __init__(self, start_time, end_time, interval_occurrence, interval_value): | ||
self._validate_time(start_time) | ||
self._validate_time(end_time) | ||
|
||
if interval_occurrence != IntervalItem.Occurrence.Hours and \ | ||
interval_occurrence != IntervalItem.Occurrence.Minutes: | ||
error = "Invalid interval type defined: {}.".format(interval_occurrence) | ||
raise ValueError(error) | ||
elif interval_occurrence == IntervalItem.Occurrence.Hours and int(interval_value) not in [1, 2, 4, 6, 8, 12]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly I'm not sure how this worked before, parsed responses will be strings, found via test failures. |
||
error = "Invalid hour value defined: {}.".format(interval_value) | ||
raise ValueError(error) | ||
elif interval_occurrence == IntervalItem.Occurrence.Minutes and int(interval_value) not in [15, 30]: | ||
error = "Invalid minute value defined: {}".format(interval_value) | ||
raise ValueError(error) | ||
|
||
self.start_time = start_time | ||
self.end_time = end_time | ||
self.frequency = IntervalItem.Frequency.Hourly | ||
|
@@ -92,7 +106,8 @@ def __init__(self, start_time, *args): | |
class WeeklyInterval(IntervalItem): | ||
def __init__(self, start_time, *interval_values): | ||
self._validate_time(start_time) | ||
|
||
if not all(hasattr(IntervalItem.Day, day) for day in interval_values): | ||
raise ValueError("Invalid week day defined " + str(interval_values)) | ||
self.start_time = start_time | ||
self.frequency = IntervalItem.Frequency.Weekly | ||
self.interval = [(IntervalItem.Occurrence.WeekDay, day) for day in interval_values] | ||
|
@@ -102,44 +117,10 @@ class MonthlyInterval(IntervalItem): | |
def __init__(self, start_time, interval_value): | ||
self._validate_time(start_time) | ||
|
||
if (int(interval_value) < 1 or int(interval_value) > 31) and interval_value != IntervalItem.Day.LastDay: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, not sure how this worked without converting to an int before |
||
error = "Invalid interval value defined for a monthly frequency: {}.".format(interval_value) | ||
raise ValueError(error) | ||
|
||
self.start_time = start_time | ||
self.frequency = IntervalItem.Frequency.Monthly | ||
self.interval = [(IntervalItem.Occurrence.MonthDay, str(interval_value))] | ||
|
||
# @classmethod | ||
# def create_hourly(cls, start_time, end_time, interval_occurrence, interval_value): | ||
# if interval_occurrence != IntervalItem.Occurrence.Hours and \ | ||
# interval_occurrence != IntervalItem.Occurrence.Minutes: | ||
# error = "Invalid interval type defined: {}.".format(interval_occurrence) | ||
# raise ValueError(error) | ||
# elif interval_occurrence == IntervalItem.Occurrence.Hours and interval_value not in [1, 2, 4, 6, 8, 12]: | ||
# error = "Invalid hour value defined: {}.".format(interval_value) | ||
# raise ValueError(error) | ||
# elif interval_occurrence == IntervalItem.Occurrence.Minutes and interval_value not in [15, 30]: | ||
# error = "Invalid minute value defined: {}".format(interval_value) | ||
# raise ValueError(error) | ||
|
||
# cls._validate_time(start_time) | ||
# cls._validate_time(end_time) | ||
# interval = [(interval_occurrence.lower(), str(interval_value))] | ||
# return cls(IntervalItem.Frequency.Hourly, interval, start_time, end_time) | ||
|
||
# @classmethod | ||
# def create_weekly(cls, start_time, *interval_value): | ||
# interval = [] | ||
# for day in interval_value: | ||
# if not hasattr(IntervalItem.Day, day): | ||
# error = "Invalid week day defined: {}.".format(day) | ||
# raise ValueError(error) | ||
# interval.append((IntervalItem.Occurrence.WeekDay, day)) | ||
# cls._validate_time(start_time) | ||
# return cls(IntervalItem.Frequency.Weekly, interval, start_time) | ||
|
||
# @classmethod | ||
# def create_monthly(cls, start_time, interval_value): | ||
# if (interval_value < 1 or interval_value > 31) and interval_value != IntervalItem.Day.LastDay: | ||
# error = "Invalid interval value defined for a monthly frequency: {}.".format(interval_value) | ||
# raise ValueError(error) | ||
# interval = [(IntervalItem.Occurrence.MonthDay, str(interval_value))] | ||
# cls._validate_time(start_time) | ||
# return cls(IntervalItem.Frequency.Monthly, interval, start_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XSD actually specifies these as lower case, I'm not sure how it was working before to be honest.
But I found these by getting test failures after the refactor