def download_workspaces(self) -> List[Workspace]: reply = requests.get(API().workspaces, auth=self.__auth) Downloader.__log_download(logging.getLogger(__name__), reply) reply.raise_for_status() return json.loads(reply.text, cls=WorkspaceDecoder)
def delete_tag(self, tag: Tag) -> None: result = requests.delete(API().tags.details(tag.identifier), auth=self.__auth) Commands.__log_command(logging.getLogger(__name__), result) result.raise_for_status()
def delete_project(self, project: Project) -> None: result = requests.delete(API().projects.details(project.identifier), auth=self.__auth) Commands.__log_command(logging.getLogger(__name__), result) result.raise_for_status()
def get_current_time_entry(self) -> TimeEntry: result = requests.get(API().time_entries.current(), auth=self.__auth) Downloader.__log_download(logging.getLogger(__name__), result) result.raise_for_status() return json.loads(result.text, cls=TimeEntryDecoder)
def delete_time_entry(self, time_entry: TimeEntry) -> None: result = requests.delete(API().time_entries.details( time_entry.identifier), auth=self.__auth) Commands.__log_command(logging.getLogger(__name__), result) result.raise_for_status()
def delete_projects(self, projects: List[Project]) -> None: result = requests.delete(API().projects.details( identifiers=[project.identifier for project in projects]), auth=self.__auth) Commands.__log_command(logging.getLogger(__name__), result) result.raise_for_status()
def download_user_data(self) -> User: reply = requests.get(API().users.details(), auth=self.__auth) # Commented this out because it may show sensitive information. # Downloader.__log_download(logging.getLogger(__name__), reply) reply.raise_for_status() return json.loads(reply.text, cls=UserDecoder)
def download_projects(self, workspace: Workspace) -> List[Project]: reply = requests.get(API().workspaces.projects(workspace.identifier), auth=self.__auth) Downloader.__log_download(logging.getLogger(__name__), reply) reply.raise_for_status() return json.loads(reply.text, cls=ProjectDecoder)
def stop_time_entry(self, time_entry: TimeEntry) -> TimeEntry: result = requests.put(API().time_entries.stop(time_entry.identifier), auth=self.__auth) Commands.__log_command(logging.getLogger(__name__), result) result.raise_for_status() return json.loads(result.text, cls=TimeEntryDecoder)
def update_tag(self, tag: Tag) -> Tag: result = requests.put(API().tags.details(tag.identifier), data=json.dumps(tag, cls=TagEncoder), auth=self.__auth) Commands.__log_command(logging.getLogger(__name__), result) result.raise_for_status() return json.loads(result.text, cls=TagDecoder)
def update_project(self, project: Project) -> Project: result = requests.put(API().projects.details(project.identifier), data=json.dumps(project, cls=ProjectEncoder), auth=self.__auth) Commands.__log_command(logging.getLogger(__name__), result) result.raise_for_status() return json.loads(result.text, cls=ProjectDecoder)
def download_time_entries(self, start: datetime, end: datetime) -> List[TimeEntry]: reply = requests.get(API().time_entries.search(start, end), auth=self.__auth) Downloader.__log_download(logging.getLogger(__name__), reply) reply.raise_for_status() return json.loads(reply.text, cls=TimeEntryDecoder)
def update_completed_time_entry(self, time_entry: TimeEntry) -> TimeEntry: result = requests.put( API().time_entries.details(time_entry.identifier), data=json.dumps(time_entry, cls=TimeEntryEncoder), auth=self.__auth) Commands.__log_command(logging.getLogger(__name__), result) result.raise_for_status() return json.loads(result.text, cls=TimeEntryDecoder)
def start_time_entry(self, time_entry: TimeEntry) -> TimeEntry: result = requests.post(API().time_entries.start(), data=json.dumps(time_entry, cls=TimeEntryEncoder), auth=self.__auth) Commands.__log_command(logging.getLogger(__name__), result) result.raise_for_status() return json.loads(result.text, cls=TimeEntryDecoder)
def test_tags_base(self): tags_url = API(version=TestEndpoints.DEFAULT_VERSION).tags.__repr__() expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="tags", arguments="") if tags_url != expected_url: self.fail("{} ne {}".format(expected_url, tags_url))
def test_users_details(self): users_url = API(version=TestEndpoints.DEFAULT_VERSION).users.details() expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="me", arguments="") if users_url != expected_url: self.fail("{} ne {}".format(expected_url, users_url))
def test_users_details_with_extra(self): users_url = API(version=TestEndpoints.DEFAULT_VERSION).users.details( extra_data=True) expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="me", arguments="?with_related_data=true") if users_url != expected_url: self.fail("{} ne {}".format(expected_url, users_url))
def test_reset_api_token(self): users_url = API( version=TestEndpoints.DEFAULT_VERSION).users.reset_api_token() expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="reset_token", arguments="") if users_url != expected_url: self.fail("{} ne {}".format(expected_url, users_url))
def test_workspaces_base(self): users_url = API( version=TestEndpoints.DEFAULT_VERSION).workspaces.__repr__() expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="workspaces", arguments="") if users_url != expected_url: self.fail("{} ne {}".format(expected_url, users_url))
def test_time_entries_start(self): time_entry_url = API( version=TestEndpoints.DEFAULT_VERSION).time_entries.start() expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="time_entries/start", arguments="") if time_entry_url != expected_url: self.fail("{} ne {}".format(expected_url, time_entry_url))
def test_time_entries_details(self): time_entry_id = 1 time_entry_url = API(version=TestEndpoints.DEFAULT_VERSION ).time_entries.details(time_entry_id) expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="time_entries", arguments="/{}".format(time_entry_id)) if time_entry_url != expected_url: self.fail("{} ne {}".format(expected_url, time_entry_url))
def test_workspaces_tags(self): workspace_id = 1 users_url = API(version=TestEndpoints.DEFAULT_VERSION).workspaces.tags( workspace_id) expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="workspaces", arguments="/{}/tags".format(workspace_id)) if users_url != expected_url: self.fail("{} ne {}".format(expected_url, users_url))
def test_projects_details(self): project_id = 1 projects_url = API( version=TestEndpoints.DEFAULT_VERSION).projects.details( identifier=project_id) expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="projects", arguments="/{}".format(project_id)) if projects_url != expected_url: self.fail("{} ne {}".format(expected_url, projects_url))
def test_multiple_time_entries_details(self): time_entry_ids = [1, 2, 3, 4] time_entry_url = API( version=TestEndpoints.DEFAULT_VERSION).time_entries.details( identifiers=time_entry_ids) expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="time_entries", arguments="/{}".format(",".join(map(str, time_entry_ids)))) if time_entry_url != expected_url: self.fail("{} ne {}".format(expected_url, time_entry_url))
def test_multiple_projects_details(self): project_ids = [1, 2, 3, 4] projects_url = API( version=TestEndpoints.DEFAULT_VERSION).projects.details( identifiers=project_ids) expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="projects", arguments="/{}".format(",".join(map(str, project_ids)))) if projects_url != expected_url: self.fail("{} ne {}".format(expected_url, projects_url))
def test_time_entries_search(self): # The dates used in the generated URLs" start_date = datetime(2019, 12, 1, 10, 0, 0, tzinfo=timezone('EST')) end_date = datetime(2019, 12, 1, 11, 0, 0, tzinfo=timezone('EST')) # The URL under test: time_entry_url = API( version=TestEndpoints.DEFAULT_VERSION).time_entries.search( start=start_date, end=end_date) # The expected result as generated here in the test case: expected_url = TestEndpoints.ENDPOINT_URL_FORMAT.format( endpoint=TestEndpoints.DEFAULT_ENDPOINT, version=TestEndpoints.DEFAULT_VERSION, type="time_entries", arguments="?start_date={start_date}&end_date={end_date}".format( start_date=urllib.parse.quote(start_date.isoformat()), end_date=urllib.parse.quote(end_date.isoformat()))) if time_entry_url != expected_url: self.fail("{} ne {}".format(expected_url, time_entry_url))
def reset_api_token(self) -> str: reply = requests.post(API().users.reset_api_token(), auth=self.__auth) reply.raise_for_status() return reply.text