From 3267cf0c7e6315f725b9f50eb8c9ffd72ce74d62 Mon Sep 17 00:00:00 2001 From: Bryant Howell Date: Sat, 7 Dec 2019 09:39:41 -0600 Subject: [PATCH] Added type hints to the UrlFilter classes --- ...date_delete_publish_tableau_server_rest.py | 6 +- tableau_rest_api/url_filter.py | 231 ++++-------------- 2 files changed, 47 insertions(+), 190 deletions(-) diff --git a/examples/test_suite_all_add_update_delete_publish_tableau_server_rest.py b/examples/test_suite_all_add_update_delete_publish_tableau_server_rest.py index 40a74bd..a89a76a 100644 --- a/examples/test_suite_all_add_update_delete_publish_tableau_server_rest.py +++ b/examples/test_suite_all_add_update_delete_publish_tableau_server_rest.py @@ -133,14 +133,12 @@ def create_test_site(tableau_server_default_connection: TableauServerRest, serve # THis could be different depending on the version / if Named Users test_site.sites.update_site(content_url=new_site_content_url, admin_mode='ContentAndUsers', - tier_creator_capacity='10', - tier_explorer_capacity='30', tier_viewer_capacity='50', + user_quota=100, storage_quota='400', state='Active', revision_history_enabled=True, revision_limit='15', disable_subscriptions=False) else: test_site.sites.update_site(content_url=new_site_content_url, admin_mode='ContentAndUsers', - tier_creator_capacity='10', - tier_explorer_capacity='30', tier_viewer_capacity='50', + user_quota=100, storage_quota='400', disable_subscriptions=False, state='Active') print('Finished creating new site') diff --git a/tableau_rest_api/url_filter.py b/tableau_rest_api/url_filter.py index b8fcddc..11b8ffe 100644 --- a/tableau_rest_api/url_filter.py +++ b/tableau_rest_api/url_filter.py @@ -1,16 +1,13 @@ -from tableau_tools.tableau_exceptions import * - +from ..tableau_exceptions import * +from typing import Union, Optional, List, Dict, Tuple class UrlFilter: - def __init__(self, field, operator, values): + def __init__(self, field: str, operator: str, values: List[str]): self.field = field self.operator = operator self.values = values - def get_filter_string(self): - """ - :rtype: unicode - """ + def get_filter_string(self) -> str: if len(self.values) == 0: raise InvalidOptionException('Must pass in at least one value for the filter') elif len(self.values) == 1: @@ -23,22 +20,15 @@ def get_filter_string(self): # Users, Datasources, Views, Workbooks @staticmethod - def create_name_filter(name): - """ - :type name: unicode - :rtype: UrlFilter - """ + def create_name_filter(name: str) -> 'UrlFilter': return UrlFilter('name', 'eq', [name, ]) # Users @staticmethod - def create_last_login_filter(operator, last_login_time): + def create_last_login_filter(operator: str, last_login_time: str) -> 'UrlFilter': """ :param operator: Should be one of 'eq', 'gt', 'gte', 'lt', 'lte' - :type operator: unicode :param last_login_time: ISO 8601 representation of time like 2016-01-01T00:00:00:00Z - :type last_login_time: unicode - :rtype: UrlFilter """ comparison_operators = ['eq', 'gt', 'gte', 'lt', 'lte'] if operator not in comparison_operators: @@ -49,31 +39,21 @@ def create_last_login_filter(operator, last_login_time): # Users @staticmethod - def create_site_role_filter(site_role): - """ - :type site_role: unicode - :rtype: UrlFilter - """ + def create_site_role_filter(site_role: str) -> 'UrlFilter': return UrlFilter('siteRole', 'eq', [site_role, ]) # Workbooks @staticmethod - def create_owner_name_filter(owner_name): - """ - :type owner_name: unicode - :rtype: UrlFilter - """ + def create_owner_name_filter(owner_name: str) -> 'UrlFilter': + return UrlFilter('ownerName', 'eq', [owner_name, ]) # Workbooks, Datasources, Views, Jobs @staticmethod - def create_created_at_filter(operator, created_at_time): + def create_created_at_filter(operator: str, created_at_time: str) -> 'UrlFilter': """ :param operator: Should be one of 'eq', 'gt', 'gte', 'lt', 'lte' - :type operator: unicode :param created_at_time: ISO 8601 representation of time like 2016-01-01T00:00:00:00Z - :type created_at_time: unicode - :rtype: UrlFilter """ comparison_operators = ['eq', 'gt', 'gte', 'lt', 'lte'] if operator not in comparison_operators: @@ -84,13 +64,10 @@ def create_created_at_filter(operator, created_at_time): # Workbooks, Datasources, Views @staticmethod - def create_updated_at_filter(operator, updated_at_time): + def create_updated_at_filter(operator: str, updated_at_time: str) -> 'UrlFilter': """ :param operator: Should be one of 'eq', 'gt', 'gte', 'lt', 'lte' - :type operator: unicode :param updated_at_time: ISO 8601 representation of time like 2016-01-01T00:00:00:00Z - :type updated_at_time: unicode - :rtype: UrlFilter """ comparison_operators = ['eq', 'gt', 'gte', 'lt', 'lte'] if operator not in comparison_operators: @@ -101,29 +78,17 @@ def create_updated_at_filter(operator, updated_at_time): # Workbooks, Datasources, Views @staticmethod - def create_tags_filter(tags): - """ - :type tags: list[unicode] - :rtype: UrlFilter - """ + def create_tags_filter(tags: List[str]) -> 'UrlFilter': return UrlFilter('tags', 'in', tags) # Workbooks, Datasources, Views @staticmethod - def create_tag_filter(tag): - """ - :type tag: unicode - :rtype: UrlFilter - """ + def create_tag_filter(tag: str) -> 'UrlFilter': return UrlFilter('tags', 'eq', [tag, ]) # Datasources @staticmethod - def create_datasource_type_filter(ds_type): - """ - :type ds_type: unicode - :rtype: UrlFilter - """ + def create_datasource_type_filter(ds_type: str) -> 'UrlFilter': return UrlFilter('type', 'eq', [ds_type, ]) class UrlFilter27(UrlFilter): @@ -133,29 +98,17 @@ def __init__(self, field, operator, values): # Users, Datasources, Views, Workbooks @staticmethod - def create_names_filter(names): - """ - :type names: list[unicode] - :rtype: UrlFilter - """ + def create_names_filter(names: List[str]) -> 'UrlFilter': return UrlFilter('name', 'in', names) # Users @staticmethod - def create_site_roles_filter(site_roles): - """ - :type site_roles: list[unicode] - :rtype: UrlFilter - """ + def create_site_roles_filter(site_roles: List[str]) -> 'UrlFilter': return UrlFilter('siteRole', 'in', site_roles) # Workbooks, Projects @staticmethod - def create_owner_names_filter(owner_names): - """ - :type owner_names: list[unicode] - :rtype: UrlFilter - """ + def create_owner_names_filter(owner_names: List[str]) -> 'UrlFilter': return UrlFilter('ownerName', 'in', owner_names) # Workbooks. Datasources, Views @@ -163,138 +116,82 @@ def create_owner_names_filter(owner_names): # Groups @staticmethod - def create_domain_names_filter(domain_names): - """ - :type domain_names: list[unicode] - :rtype: UrlFilter - """ - + def create_domain_names_filter(domain_names: List[str]) -> 'UrlFilter': return UrlFilter('domainName', 'in', domain_names) # Groups @staticmethod - def create_domain_nicknames_filter(domain_nicknames): - """ - :type domain_nicknames: list[unicode] - :rtype: UrlFilter - """ + def create_domain_nicknames_filter(domain_nicknames: str) -> 'UrlFilter': + return UrlFilter('domainNickname', 'in', domain_nicknames) # Groups @staticmethod - def create_domain_name_filter(domain_name): - """ - :type domain_name: unicode - :rtype: UrlFilter - """ - + def create_domain_name_filter(domain_name: str) -> 'UrlFilter': return UrlFilter('domainName', 'eq', [domain_name, ]) # Groups @staticmethod - def create_domain_nickname_filter(domain_nickname): - """ - :type domain_nickname: unicode - :rtype: UrlFilter - """ + def create_domain_nickname_filter(domain_nickname: str) -> 'UrlFilter': + return UrlFilter('domainNickname', 'eq', [domain_nickname, ]) # Groups @staticmethod - def create_minimum_site_roles_filter(minimum_site_roles): - """ - :type minimum_site_roles: list[unicode] - :rtype: UrlFilter - """ + def create_minimum_site_roles_filter(minimum_site_roles: List[str]) -> 'UrlFilter': return UrlFilter('minimumSiteRole', 'in', minimum_site_roles) # Groups @staticmethod - def create_minimum_site_role_filter(minimum_site_role): - """ - :type minimum_site_role: unicode - :rtype: UrlFilter - """ + def create_minimum_site_role_filter(minimum_site_role: str) -> 'UrlFilter': return UrlFilter('minimumSiteRole', 'eq', [minimum_site_role, ]) # Groups @staticmethod - def create_is_local_filter(is_local): - """ - :type is_local: - :return: bool - """ + def create_is_local_filter(is_local: bool) -> 'UrlFilter': if is_local not in [True, False]: raise InvalidOptionException('is_local must be True or False') - return UrlFilter('isLocal', 'eq', str(is_local).lower()) + return UrlFilter('isLocal', 'eq', [str(is_local).lower(), ]) # Groups @staticmethod - def create_user_count_filter(operator, user_count): - """ - :param operator: Should be one of 'eq', 'gt', 'gte', 'lt', 'lte' - :type operator: unicode - :type user_count: int - :rtype: UrlFilter - """ + def create_user_count_filter(operator, user_count: int) -> 'UrlFilter': comparison_operators = ['eq', 'gt', 'gte', 'lt', 'lte'] if operator not in comparison_operators: raise InvalidOptionException("operator must be one of 'eq', 'gt', 'gte', 'lt', 'lte' ") # Convert to the correct time format - return UrlFilter('userCount', operator, [user_count, ]) + return UrlFilter('userCount', operator, [str(user_count), ]) # Projects @staticmethod - def create_owner_domains_filter(owner_domains): - """ - :param owner_domains: list[unicode] - :rtype: UrlFilter - """ + def create_owner_domains_filter(owner_domains: List[str]) -> 'UrlFilter': return UrlFilter('ownerDomain', 'in', owner_domains) # Projects @staticmethod - def create_owner_domain_filter(owner_domain): - """ - :param owner_domain: unicode - :rtype: UrlFilter - """ + def create_owner_domain_filter(owner_domain: str) -> 'UrlFilter': return UrlFilter('ownerDomain', 'in', [owner_domain, ]) # Projects @staticmethod - def create_owner_emails_filter(owner_emails): - """ - :param owner_emails: list[unicode] - :rtype: UrlFilter - """ + def create_owner_emails_filter(owner_emails: List[str]) -> 'UrlFilter': return UrlFilter('ownerEmail', 'in', owner_emails) # Projects @staticmethod - def create_owner_email_filter(owner_email): - """ - :param owner_email: unicode - :rtype: UrlFilter - """ + def create_owner_email_filter(owner_email: str) -> 'UrlFilter': return UrlFilter('ownerEmail', 'in', [owner_email, ]) # Views @staticmethod - def create_hits_total_filter(operator, hits_total): - """ - :param operator: Should be one of 'eq', 'gt', 'gte', 'lt', 'lte' - :type operator: unicode - :type hits_total: int - :rtype: UrlFilter - """ + def create_hits_total_filter(operator, hits_total: int) -> 'UrlFilter': comparison_operators = ['eq', 'gt', 'gte', 'lt', 'lte'] if operator not in comparison_operators: raise InvalidOptionException("operator must be one of 'eq', 'gt', 'gte', 'lt', 'lte' ") # Convert to the correct time format - return UrlFilter('hitsTotal', operator, [hits_total, ]) + return UrlFilter('hitsTotal', operator, [str(hits_total), ]) class UrlFilter28(UrlFilter27): @@ -315,13 +212,10 @@ def __init__(self, field, operator, values): # Jobs @staticmethod - def create_started_at_filter(operator, started_at_time) -> UrlFilter: + def create_started_at_filter(operator: str, started_at_time: str) -> UrlFilter: """ :param operator: Should be one of 'eq', 'gt', 'gte', 'lt', 'lte' - :type operator: unicode :param started_at_time: ISO 8601 representation of time like 2016-01-01T00:00:00:00Z - :type started_at_time: unicode - :rtype: UrlFilter """ comparison_operators = ['eq', 'gt', 'gte', 'lt', 'lte'] if operator not in comparison_operators: @@ -332,13 +226,10 @@ def create_started_at_filter(operator, started_at_time) -> UrlFilter: # Jobs @staticmethod - def create_ended_at_filter(operator, ended_at_time) -> UrlFilter: + def create_ended_at_filter(operator: str, ended_at_time: str) -> UrlFilter: """ :param operator: Should be one of 'eq', 'gt', 'gte', 'lt', 'lte' - :type operator: unicode :param ended_at_time: ISO 8601 representation of time like 2016-01-01T00:00:00:00Z - :type ended_at_time: unicode - :rtype: UrlFilter """ comparison_operators = ['eq', 'gt', 'gte', 'lt', 'lte'] if operator not in comparison_operators: @@ -349,61 +240,33 @@ def create_ended_at_filter(operator, ended_at_time) -> UrlFilter: # Jobs @staticmethod - def create_job_types_filter(job_types) -> UrlFilter: - """ - :type job_types: list[unicode] - :rtype: UrlFilter - """ + def create_job_types_filter(job_types: List[str]) -> UrlFilter: return UrlFilter('jobType', 'in', job_types) # Jobs @staticmethod - def create_job_type_filter(job_type) -> UrlFilter: - """ - :type job_type: unicode - :rtype: UrlFilter - """ + def create_job_type_filter(job_type: str) -> UrlFilter: return UrlFilter('tags', 'eq', [job_type, ]) # Jobs @staticmethod - def create_notes_filter(notes) -> UrlFilter: - """ - :type notes: unicode - :rtype: UrlFilter - """ + def create_notes_filter(notes: str) -> UrlFilter: return UrlFilter('notes', 'has', [notes, ]) @staticmethod - def create_title_equals_filter(title) -> UrlFilter: - """ - :type title: unicode - :rtype: UrlFilter - """ + def create_title_equals_filter(title: str) -> UrlFilter: return UrlFilter('title', 'eq', [title, ]) @staticmethod - def create_title_has_filter(title) -> UrlFilter: - """ - :type title: unicode - :rtype: UrlFilter - """ + def create_title_has_filter(title: str) -> UrlFilter: return UrlFilter('title', 'has', [title, ]) @staticmethod - def create_subtitle_equals_filter(subtitle) -> UrlFilter: - """ - :type subtitle: unicode - :rtype: UrlFilter - """ + def create_subtitle_equals_filter(subtitle: str) -> UrlFilter: return UrlFilter('subtitle', 'eq', [subtitle, ]) @staticmethod - def create_subtitle_has_filter(subtitle) -> UrlFilter: - """ - :type subtitle: unicode - :rtype: UrlFilter - """ + def create_subtitle_has_filter(subtitle: str) -> UrlFilter: return UrlFilter('subtitle', 'has', [subtitle, ]) class UrlFilter33(UrlFilter31): @@ -411,9 +274,5 @@ def __init__(self, field, operator, values): UrlFilter31.__init__(self, field, operator, values) @staticmethod - def create_project_name_equals_filter(project_name) -> UrlFilter: - """ - :type subtitle: unicode - :rtype: UrlFilter - """ + def create_project_name_equals_filter(project_name: str) -> UrlFilter: return UrlFilter('projectName', 'eq', [project_name, ])