Skip to content
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

Merged
merged 17 commits into from Oct 7, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 22 additions & 41 deletions tableauserverclient/models/interval_item.py
Expand Up @@ -11,8 +11,8 @@ class Frequency:
Monthly = "Monthly"

class Occurrence:
Hours = "Hours"
Minutes = "Minutes"
Hours = "hours"
Copy link
Collaborator Author

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

Minutes = "minutes"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minutes should come before hours.

WeekDay = "weekDay"
MonthDay = "monthDay"

Expand Down Expand Up @@ -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]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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]
Expand All @@ -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:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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)