-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List time entries #4
Comments
The Time Entries API seems a good fit. Here's a sample document: $ curl -u "${TOGGL_API_TOKEN}:api_token" https://api.track.toggl.com/api/v9/me/time_entries | jq
[
{
"id": 2815158339,
"workspace_id": 1815018,
"project_id": 178435728,
"task_id": null,
"billable": false,
"start": "2023-01-24T17:54:00+00:00",
"stop": "2023-01-24T18:30:21Z",
"duration": 2181,
"description": "community: https://github.com/elastic/beats/issues/34330",
"tags": [
"type:support"
],
"tag_ids": [
12078060
],
"duronly": true,
"at": "2023-01-24T19:30:36+00:00",
"server_deleted_at": null,
"user_id": 2621333,
"uid": 2621333,
"wid": 1815018,
"pid": 178435728
}
] Weird. The |
I am designing the table output with some hard-coded data: @entries.command(name="list")
def list_entries():
"entries list command description"
table = Table(title="Time Entries", box=box.SIMPLE)
table.add_column("Description")
table.add_column("Duration")
table.add_column("Tags")
table.add_row(
"community: https://github.com/elastic/beats/issues/34330",
"2181",
"type:support"
)
# turn table into a string using the Console
console = Console(file=io.StringIO())
console.print(table)
click.echo(console.file.getvalue()) The result is: $ tgl entries list
Time Entries
Description Duration Tags
────────────────────────────────────────────────────────────────────────────────────
community: https://github.com/elastic/beats/issues/34330 2181 type:support
|
Updating the table layout with more data: $ tgl entries list
Time Entries
Date Description Start Stop Duration Tags
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2023-01-25 community: https://github.com/elastic/beats/issues/34330 11:04 PM 11:27 PM 0:22:59 type:support
|
Now we have a real Toggl client for the time entries endpoint. The next step is to update the CLI to use the client instead of the hard-coded value. I need to control the API response, so I plan to use the pytest-recording package to disable network access and use recorded responses like I did in https://github.com/zmoog/axios/blob/1e5ee3e241a0ae4fe4138a30b628c96173fd6c6f/tests/test_axios.py#L25-L35 |
With pytest-recording, we need to collect the actual network traffic into 'vcr cassettes' for a later use during tests. $ pytest --record-mode=once tests/test_entries.py To avoid capturing credentials, I added the following configuration: # tests/conftest.py
import pytest
@pytest.fixture(scope="module")
def vcr_config():
return {"filter_headers": ["authorization"]} If you're making changes to the code, you can re-capture the network traffic again and again by using the record mode $ pytest --record-mode=rewrite tests/test_entries.py |
- We use the actual TimeEntries API to fetch data from Toggl - Record and replay network traffic using pytest-recording refs: #4
- We use the actual TimeEntries API to fetch data from Toggl - Record and replay network traffic using pytest-recording refs: #4
- We use the actual TimeEntries API to fetch data from Toggl - Record and replay network traffic using pytest-recording refs: #4
The |
Simple demonstration of the only available command :) refs: #4
* Mock a simple list of time entries refs #4 * Add TimeEntries client Ref: #4 * Switch from hard-coded to actual Toggl API calls - We use the actual TimeEntries API to fetch data from Toggl - Record and replay network traffic using pytest-recording refs: #4 * Add missing TOGGL_API_TOKEN environment variable * Move output formatting into a result module refs: #4 * Add a 'entries list' command usage example Simple demonstration of the only available command :) refs: #4 * Improve help messages add clean up default options Default values for date-related options were a little messy. I hope this change makes the date logic a little more readable.
record network call to Toggl API using pytest-recording
Toggl API documentation
The text was updated successfully, but these errors were encountered: