Example #1
0
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)
Example #2
0
"""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}")
Example #3
0
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()