def test_session_exception(mock_requests, a_mock_api): session = APISession(api_server=an_api, api_key='test') session.api = a_mock_api session.api.get_workspaces.side_effect = APIServerException('Something went wrong with the API', error_response=APIErrorResponse(code=999, message='mock error')) with pytest.raises(APIServerException): session.add_time_entry(start_time=None, description='test', project=None)
""" Add a time entry to a workspace """ from os import environ from clockifyclient.api import APIServer from clockifyclient.client import APISession session = APISession(api_server=APIServer("https://api.clockify.me/api/v1"), api_key=environ["API_KEY"]) stopped = session.stop_timer() if stopped: print(f'stopped {stopped}. Set endtime {stopped.end}') else: print('Stopped nothing. No timer was running')
"""Add a time entry to a workspace, start timer, and associate with a project""" from os import environ from clockifyclient.api import APIServer from clockifyclient.client import APISession session = APISession(api_server=APIServer("https://api.clockify.me/api/v1"), api_key=environ["API_KEY"]) if session.get_projects(): project = session.get_projects()[ 0] # For this example, just get the first project you find else: project = None # Or, if there are no projects, just don't use a project response = session.add_time_entry(start_time=session.now(), description="A test time entry", project=project) print(f"Created {response}")
"""Editing time entries""" from os import environ from clockifyclient.api import APIServer from clockifyclient.client import APISession from clockifyclient.models import TimeEntryQuery session = APISession(api_server=APIServer("https://api.clockify.me/api/v1"), api_key=environ["API_KEY"]) projects = {x.name: x for x in session.get_projects()} # get entries from clockify entries = session.get_time_entries(query=TimeEntryQuery(description="emails"), limit=None) # Prune away unwanted results print(f"{len(entries)} entries found") in_entries = [x for x in entries if x.project is None] # change project for all those for entry in in_entries: entry.project = projects["Research Bureau"] print(f"saving {len(in_entries)} entries..") session.add_time_entries(in_entries) print("Done")
def test_session(mock_requests, a_mock_api): """Run some session commands with a mocked underlying API""" session = APISession(api_server=an_api, api_key="test") session.api = a_mock_api session.add_time_entry(start_time=None, description="test", project=None) session.stop_timer()
def __init__(self, api_url, api_key): self.api_url = api_url self.api_key = api_key self.session = APISession(api_server=APIServer(api_url), api_key=api_key)
import os import json from clockifyclient.client import APISession from clockifyclient.api import APIServer CLOCKIFY_SETUP_FILE = os.path.abspath('../res/report_setup.json') with open(CLOCKIFY_SETUP_FILE, 'r', encoding='utf-8') as task: setup_dict = json.load(task) api_key = setup_dict['api_key'] url = "https://api.clockify.me/api/v1/" api_session = APISession(APIServer(url), api_key) WORKSPACE = [ ws for ws in api_session.get_workspaces() if ws.name == setup_dict['workspace_name'] ][0] # TODO practice generator CREDENTIALS_FILE = os.path.abspath( '../res/' + setup_dict['google_credentials_file']) # имя файла с закрытым ключом REPORT_SPREADSHEET_ID = setup_dict['report_spreadsheet_id'] REPORT_SHEET_ID = setup_dict['report_sheet_id'] DATA_LINE = 4 PROJECT_COLUMN = 1 weeks_in_RP = [9, 10, 11, 12, 13, 14]
def test_create_workspace(): api_key = '' api_server = APIServer('https://api.clockify.me/api/v1') api_session = APISession(api_server, api_key) workspace = api_session.make_workspace('dev1') assert workspace.name == 'dev1'