def test_update(self): with open(UPDATE_XML, "rb") as f: response_xml = f.read().decode("utf-8") with requests_mock.mock() as m: m.put(self.baseurl + '/7bea1766-1543-4052-9753-9d224bc069b5', text=response_xml) new_interval = TSC.WeeklyInterval(time(7), TSC.IntervalItem.Day.Monday, TSC.IntervalItem.Day.Friday) single_schedule = TSC.ScheduleItem( "weekly-schedule-1", 90, TSC.ScheduleItem.Type.Extract, TSC.ScheduleItem.ExecutionOrder.Parallel, new_interval) single_schedule._id = "7bea1766-1543-4052-9753-9d224bc069b5" single_schedule = self.server.schedules.update(single_schedule) self.assertEqual("7bea1766-1543-4052-9753-9d224bc069b5", single_schedule.id) self.assertEqual("weekly-schedule-1", single_schedule.name) self.assertEqual(90, single_schedule.priority) self.assertEqual("2016-09-15T23:50:02Z", format_datetime(single_schedule.updated_at)) self.assertEqual(TSC.ScheduleItem.Type.Extract, single_schedule.schedule_type) self.assertEqual("2016-09-16T14:00:00Z", format_datetime(single_schedule.next_run_at)) self.assertEqual(TSC.ScheduleItem.ExecutionOrder.Parallel, single_schedule.execution_order) self.assertEqual(time(7), single_schedule.interval_item.start_time) self.assertEqual(("Monday", "Friday"), single_schedule.interval_item.interval)
def test_create_weekly(self): with open(CREATE_WEEKLY_XML, "rb") as f: response_xml = f.read().decode("utf-8") with requests_mock.mock() as m: m.post(self.baseurl, text=response_xml) weekly_interval = TSC.WeeklyInterval( time(9, 15), TSC.IntervalItem.Day.Monday, TSC.IntervalItem.Day.Wednesday, TSC.IntervalItem.Day.Friday) new_schedule = TSC.ScheduleItem( "weekly-schedule-1", 80, TSC.ScheduleItem.Type.Extract, TSC.ScheduleItem.ExecutionOrder.Parallel, weekly_interval) new_schedule = self.server.schedules.create(new_schedule) self.assertEqual("1adff386-6be0-4958-9f81-a35e676932bf", new_schedule.id) self.assertEqual("weekly-schedule-1", new_schedule.name) self.assertEqual("Active", new_schedule.state) self.assertEqual(80, new_schedule.priority) self.assertEqual("2016-09-15T21:12:50Z", format_datetime(new_schedule.created_at)) self.assertEqual("2016-09-15T21:12:50Z", format_datetime(new_schedule.updated_at)) self.assertEqual(TSC.ScheduleItem.Type.Extract, new_schedule.schedule_type) self.assertEqual("2016-09-16T16:15:00Z", format_datetime(new_schedule.next_run_at)) self.assertEqual(TSC.ScheduleItem.ExecutionOrder.Parallel, new_schedule.execution_order) self.assertEqual(time(9, 15), new_schedule.interval_item.start_time) self.assertEqual(("Monday", "Wednesday", "Friday"), new_schedule.interval_item.interval) self.assertEqual(2, len(new_schedule.warnings)) self.assertEqual("warning 1", new_schedule.warnings[0]) self.assertEqual("warning 2", new_schedule.warnings[1])
def main(): parser = argparse.ArgumentParser(description='Creates sample schedules for each type of frequency.') parser.add_argument('--server', '-s', required=True, help='server address') parser.add_argument('--username', '-u', required=True, help='username to sign into server') parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', help='desired logging level (set to error by default)') args = parser.parse_args() password = getpass.getpass("Password: "******"Hourly-Schedule", 50, TSC.ScheduleItem.Type.Extract, TSC.ScheduleItem.ExecutionOrder.Parallel, hourly_interval) hourly_schedule = server.schedules.create(hourly_schedule) print("Hourly schedule created (ID: {}).".format(hourly_schedule.id)) # Daily Schedule # This schedule will run every day at 5AM daily_interval = TSC.DailyInterval(start_time=time(5)) daily_schedule = TSC.ScheduleItem("Daily-Schedule", 60, TSC.ScheduleItem.Type.Subscription, TSC.ScheduleItem.ExecutionOrder.Serial, daily_interval) daily_schedule = server.schedules.create(daily_schedule) print("Daily schedule created (ID: {}).".format(daily_schedule.id)) # Weekly Schedule # This schedule will wun every Monday, Wednesday, and Friday at 7:15PM weekly_interval = TSC.WeeklyInterval(time(19, 15), TSC.IntervalItem.Day.Monday, TSC.IntervalItem.Day.Wednesday, TSC.IntervalItem.Day.Friday) weekly_schedule = TSC.ScheduleItem("Weekly-Schedule", 70, TSC.ScheduleItem.Type.Extract, TSC.ScheduleItem.ExecutionOrder.Serial, weekly_interval) weekly_schedule = server.schedules.create(weekly_schedule) print("Weekly schedule created (ID: {}).".format(weekly_schedule.id)) # Monthly Schedule # This schedule will run on the 15th of every month at 11:30PM monthly_interval = TSC.MonthlyInterval(start_time=time(23, 30), interval_value=15) monthly_schedule = TSC.ScheduleItem("Monthly-Schedule", 80, TSC.ScheduleItem.Type.Subscription, TSC.ScheduleItem.ExecutionOrder.Parallel, monthly_interval) monthly_schedule = server.schedules.create(monthly_schedule) print("Monthly schedule created (ID: {}).".format(monthly_schedule.id))
def main(): parser = argparse.ArgumentParser(description="Creates sample schedules for each type of frequency.") # Common options; please keep those in sync across all samples parser.add_argument("--server", "-s", required=True, help="server address") parser.add_argument("--site", "-S", help="site name") parser.add_argument( "--token-name", "-p", required=True, help="name of the personal access token used to sign into the server" ) parser.add_argument( "--token-value", "-v", required=True, help="value of the personal access token used to sign into the server" ) parser.add_argument( "--logging-level", "-l", choices=["debug", "info", "error"], default="error", help="desired logging level (set to error by default)", ) # Options specific to this sample: # This sample has no additional options, yet. If you add some, please add them here args = parser.parse_args() # Set logging level based on user input, or error by default logging_level = getattr(logging, args.logging_level.upper()) logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=False) server.add_http_options({"verify": False}) server.use_server_version() with server.auth.sign_in(tableau_auth): # Hourly Schedule # This schedule will run every 2 hours between 2:30AM and 11:00PM hourly_interval = TSC.HourlyInterval(start_time=time(2, 30), end_time=time(23, 0), interval_value=2) hourly_schedule = TSC.ScheduleItem( "Hourly-Schedule", 50, TSC.ScheduleItem.Type.Extract, TSC.ScheduleItem.ExecutionOrder.Parallel, hourly_interval, ) try: hourly_schedule = server.schedules.create(hourly_schedule) print("Hourly schedule created (ID: {}).".format(hourly_schedule.id)) except Exception as e: print(e) # Daily Schedule # This schedule will run every day at 5AM daily_interval = TSC.DailyInterval(start_time=time(5)) daily_schedule = TSC.ScheduleItem( "Daily-Schedule", 60, TSC.ScheduleItem.Type.Subscription, TSC.ScheduleItem.ExecutionOrder.Serial, daily_interval, ) try: daily_schedule = server.schedules.create(daily_schedule) print("Daily schedule created (ID: {}).".format(daily_schedule.id)) except Exception as e: print(e) # Weekly Schedule # This schedule will wun every Monday, Wednesday, and Friday at 7:15PM weekly_interval = TSC.WeeklyInterval( time(19, 15), TSC.IntervalItem.Day.Monday, TSC.IntervalItem.Day.Wednesday, TSC.IntervalItem.Day.Friday ) weekly_schedule = TSC.ScheduleItem( "Weekly-Schedule", 70, TSC.ScheduleItem.Type.Extract, TSC.ScheduleItem.ExecutionOrder.Serial, weekly_interval, ) try: weekly_schedule = server.schedules.create(weekly_schedule) print("Weekly schedule created (ID: {}).".format(weekly_schedule.id)) except Exception as e: print(e) options = TSC.RequestOptions() options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, "Weekly Schedule") ) schedules, _ = server.schedules.get(req_options=options) weekly_schedule = schedules[0] print(weekly_schedule) # Monthly Schedule # This schedule will run on the 15th of every month at 11:30PM monthly_interval = TSC.MonthlyInterval(start_time=time(23, 30), interval_value=15) monthly_schedule = TSC.ScheduleItem( "Monthly-Schedule", 80, TSC.ScheduleItem.Type.Subscription, TSC.ScheduleItem.ExecutionOrder.Parallel, monthly_interval, ) try: monthly_schedule = server.schedules.create(monthly_schedule) print("Monthly schedule created (ID: {}).".format(monthly_schedule.id)) except Exception as e: print(e) # Now fetch the weekly schedule by id fetched_schedule = server.schedules.get_by_id(weekly_schedule.id) fetched_interval = fetched_schedule.interval_item print("Fetched back our weekly schedule, it shows interval ", fetched_interval)
def main(): parser = argparse.ArgumentParser(description='Creates sample schedules for each type of frequency.') # Common options; please keep those in sync across all samples parser.add_argument('--server', '-s', required=True, help='server address') parser.add_argument('--site', '-S', help='site name') parser.add_argument('--token-name', '-p', required=True, help='name of the personal access token used to sign into the server') parser.add_argument('--token-value', '-v', required=True, help='value of the personal access token used to sign into the server') parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', help='desired logging level (set to error by default)') # Options specific to this sample # This sample has no additional options, yet. If you add some, please add them here args = parser.parse_args() # Set logging level based on user input, or error by default logging_level = getattr(logging, args.logging_level.upper()) logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): # Hourly Schedule # This schedule will run every 2 hours between 2:30AM and 11:00PM hourly_interval = TSC.HourlyInterval(start_time=time(2, 30), end_time=time(23, 0), interval_value=2) hourly_schedule = TSC.ScheduleItem("Hourly-Schedule", 50, TSC.ScheduleItem.Type.Extract, TSC.ScheduleItem.ExecutionOrder.Parallel, hourly_interval) hourly_schedule = server.schedules.create(hourly_schedule) print("Hourly schedule created (ID: {}).".format(hourly_schedule.id)) # Daily Schedule # This schedule will run every day at 5AM daily_interval = TSC.DailyInterval(start_time=time(5)) daily_schedule = TSC.ScheduleItem("Daily-Schedule", 60, TSC.ScheduleItem.Type.Subscription, TSC.ScheduleItem.ExecutionOrder.Serial, daily_interval) daily_schedule = server.schedules.create(daily_schedule) print("Daily schedule created (ID: {}).".format(daily_schedule.id)) # Weekly Schedule # This schedule will wun every Monday, Wednesday, and Friday at 7:15PM weekly_interval = TSC.WeeklyInterval(time(19, 15), TSC.IntervalItem.Day.Monday, TSC.IntervalItem.Day.Wednesday, TSC.IntervalItem.Day.Friday) weekly_schedule = TSC.ScheduleItem("Weekly-Schedule", 70, TSC.ScheduleItem.Type.Extract, TSC.ScheduleItem.ExecutionOrder.Serial, weekly_interval) weekly_schedule = server.schedules.create(weekly_schedule) print("Weekly schedule created (ID: {}).".format(weekly_schedule.id)) # Monthly Schedule # This schedule will run on the 15th of every month at 11:30PM monthly_interval = TSC.MonthlyInterval(start_time=time(23, 30), interval_value=15) monthly_schedule = TSC.ScheduleItem("Monthly-Schedule", 80, TSC.ScheduleItem.Type.Subscription, TSC.ScheduleItem.ExecutionOrder.Parallel, monthly_interval) monthly_schedule = server.schedules.create(monthly_schedule) print("Monthly schedule created (ID: {}).".format(monthly_schedule.id))