Skip to content

Commit

Permalink
Format duration using the hh:mm format
Browse files Browse the repository at this point in the history
The 'human' format is nice, but it make reading durations at glance
harder.

refs: #6
  • Loading branch information
zmoog committed Feb 3, 2023
1 parent 8de0868 commit 64fd771
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 148 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ Now install the dependencies and test dependencies:
To run the tests:

pytest

If you need to send other requests to Toggl API, you can capture responses using:

pytest --record-mode=once
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def get_long_description():
""",
install_requires=[
"click",
"humanize",
"pydantic",
"requests",
"rich",
Expand Down
81 changes: 0 additions & 81 deletions tests/cassettes/test_entries/test_entries.yaml

This file was deleted.

81 changes: 81 additions & 0 deletions tests/cassettes/test_entries_group_by/test_group_by_tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.28.2
method: GET
uri: https://api.track.toggl.com/api/v9/me/time_entries?start_date=2023-01-26T00%3A00%3A00Z&end_date=2023-01-27T00%3A00%3A00Z
response:
body:
string: !!binary |
H4sIAAAAAAAEA82Z3YrjNhTHX0X4thnQh+UP3W1nurDQ0sIUCl2WQRNrEm8c27XlTWdL36CFXpdC
r/oCfbI+Qo+deGxFqSeT2mYhN5FNIp3f+Z8vvf3JiSNH0ICEhHIc+gtnlxWbMpdLdVc/IQHhmAQL
Jy+y92qp94t+4DLuU1jWstw0a2mVJAvnPk4SeZ8oRzzIpFQLp9Sy0I5wKKbsCpMr6n1LqaBcMP4Z
xgJjp34ny61XuCsY+x6eRlUhdZylsBefwT9GqlwWcb5fcq6z7bZKY/0o0KskyXYol0UZpyuUPaA3
33zwkIyiQpWlKlGcwmelSo3yOFdJnCr4dS1XpSPeOvo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PNnyQgQbODzjN0bNKbdKakzllltrSS07zC0
zHZWxP+fEcbyjhH9/mTFhGHcPMsdAQE9Q8ExNAYje0ZHjl+P048ByLrGpQJGx80NQWWNjVeZTE6q
gJ2hgsM2ZlOB7weM1jcyk0cfDN2fK8hgz3HgZKogxHacHz36WB4ysfP7Pob8CvnrDLuHHNPQq5v0
C+7HsA/3ccLtpTOrWwAy8CHHI2DmQfY3g4/OVqvkShdyuRHQK8AFSn15gqBBKGLV6xGMHPC817cb
mMTrW+v1Uq4PQw8cgj0nN37ThfIhnwc+MGfARwMr4gXWRddUxj9sYD7jM7gdPi/vtuXSZZ7v1eXO
YNqtc249vjUDDuXuicLyr9/Q54WSmwfoyLrC56WebjnEiHGmtZbh6QRD4zuDp9f3ucM9FRi74WEa
m9HQGu9N5emWQ4xo/Kcw8+5fyIRd7gYhAAA=
headers:
Alt-Svc:
- h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Cache-Control:
- no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0
Content-Encoding:
- gzip
Content-Type:
- application/json; charset=utf-8
Date:
- Fri, 03 Feb 2023 07:02:08 GMT
Instance:
- time-public-api2
Referrer-Policy:
- strict-origin-when-cross-origin
Server:
- nginx
Strict-Transport-Security:
- max-age=15552000; includeSubDomains
Transfer-Encoding:
- chunked
Vary:
- Accept-Encoding
Via:
- 1.1 google
X-Content-Type-Options:
- nosniff
X-Request-ID:
- fcc935dc52862c5105bcd3754c37f105
X-Service-Level:
- GREEN
X-Toggl-Request-Id:
- fcc935dc52862c5105bcd3754c37f105
X-We-are-hiring:
- https://toggl.com/jobs/
status:
code: 200
message: OK
version: 1
81 changes: 81 additions & 0 deletions tests/cassettes/test_entries_list/test_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.28.2
method: GET
uri: https://api.track.toggl.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oZsxq980
fTpCOmx/EnZPxjfguSF3wVOnj4IcKgVB3O5oNrwDXxPeCSHdFFmO1kpGqkBJtkJ1H1u3ttdJVkWv
oT/VCCSU6rIT0SjNLbEccOo453oEE8jwc+DBTLhDzS2cviFo4qEesbT1RSJLKNW+TptKTqAfKpg4
wPiiRA9FtkU3Ko0/ouus3FTp+ISOvGxqQtQnvj+LgJjAZHhkRGBeBGWUZxLizLUb2FopUFvD1Cgr
6mR0hb5TagNznWbs042DtkppeG6Og8KQeZDgnm9S2w11op8aB8zHuO+dJZg2l12WiyigEGyo94Gi
D6Z7xzSIG4bHuQjq5z/Ql1W6XHfmf2H5DH8G6HkvvI5o6dZS/cRBaMDrsdb0kYkKDGlxsATbwyCm
34MrWH5fPqbLzsaHpFCvGeY+jDvJGQ5++Of5HBz73PNnyQgQbODzjN0bNKbdKakzllltrSS07zC0
zHZWxP+fEcbyjhH9/mTFhGHcPMsdAQE9Q8ExNAYje0ZHjl+P048ByLrGpQJGx80NQWWNjVeZTE6q
gJ2hgsM2ZlOB7weM1jcyk0cfDN2fK8hgz3HgZKogxHacHz36WB4ysfP7Pob8CvnrDLuHHNPQq5v0
C+7HsA/3ccLtpTOrWwAy8CHHI2DmQfY3g4/OVqvkShdyuRHQK8AFSn15gqBBKGLV6xGMHPC817cb
mMTrW+v1Uq4PQw8cgj0nN37ThfIhnwc+MGfARwMr4gXWRddUxj9sYD7jM7gdPi/vtuXSZZ7v1eXO
YNqtc249vjUDDuXuicLyr9/Q54WSmwfoyLrC56WebjnEiHGmtZbh6QRD4zuDp9f3ucM9FRi74WEa
m9HQGu9N5emWQ4xo/Kcw8+5fyIRd7gYhAAA=
headers:
Alt-Svc:
- h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Cache-Control:
- no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0
Content-Encoding:
- gzip
Content-Type:
- application/json; charset=utf-8
Date:
- Fri, 03 Feb 2023 07:02:09 GMT
Instance:
- time-public-api2
Referrer-Policy:
- strict-origin-when-cross-origin
Server:
- nginx
Strict-Transport-Security:
- max-age=15552000; includeSubDomains
Transfer-Encoding:
- chunked
Vary:
- Accept-Encoding
Via:
- 1.1 google
X-Content-Type-Options:
- nosniff
X-Request-ID:
- a62a2f942c009e485790366413698216
X-Service-Level:
- GREEN
X-Toggl-Request-Id:
- a62a2f942c009e485790366413698216
X-We-are-hiring:
- https://toggl.com/jobs/
status:
code: 200
message: OK
version: 1
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def vcr_config():
@pytest.fixture()
def save_to_tmp():
"""Saves the result object to the filesystem for inspection."""
def wrapper(output: Any):
with open("/tmp/output.txt", "w") as f:
def wrapper(output: Any, name: str = "result"):
with open(f"/tmp/{name}.out.txt", "w") as f:
f.write(str(output))
return wrapper
38 changes: 38 additions & 0 deletions tests/test_entries_group_by.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
from click.testing import CliRunner

from toggl_track.cli import cli


env = {
"TOGGL_API_TOKEN": "1234567890abcdef1234567890abcdef", # fake token for testing
}


@pytest.mark.vcr
@pytest.mark.block_network
def test_group_by_tags():
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
cli,
["entries", "group-by", "--field", "tags", "--start-date", "2023-01-26", "--end-date", "2023-01-27"],
env=env,
)
assert result.exit_code == 0
assert (
result.output
== """ Time Entries
tags Duration
─────────────────────────
type:support 5:44
5:14
type:sync 3:00
type:meeting 2:04
type:goal 0:35
"""
)

Loading

0 comments on commit 64fd771

Please sign in to comment.