Skip to content

Commit 588ffc4

Browse files
committed
test repository pagination
1 parent 1356204 commit 588ffc4

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

tests/conftest.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
3+
from tests.fixtures import REPORT_TIME_ENTRIES_RESPONSE, TIME_ENTRIES_RESPONSE
4+
from toggl_python import ReportTimeEntries, TimeEntries
5+
6+
7+
@pytest.fixture
8+
def patch_report_time_entries(monkeypatch):
9+
class MockResponse:
10+
def __init__(self, *args, **kwargs):
11+
pass
12+
13+
@staticmethod
14+
def json():
15+
return REPORT_TIME_ENTRIES_RESPONSE
16+
17+
monkeypatch.setattr(ReportTimeEntries, "get", MockResponse, raising=False)
18+
19+
20+
@pytest.fixture
21+
def patch_time_entries(monkeypatch):
22+
class MockResponse:
23+
def __init__(self, *args, **kwargs):
24+
pass
25+
26+
@staticmethod
27+
def json():
28+
return TIME_ENTRIES_RESPONSE
29+
30+
monkeypatch.setattr(TimeEntries, "get", MockResponse, raising=False)

tests/fixtures.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
REPORT_TIME_ENTRIES_RESPONSE = {
2+
"total_grand": 0,
3+
"total_billable": None,
4+
"total_currencies": [{"currency": None, "amount": None}],
5+
"total_count": 1,
6+
"per_page": 50,
7+
"data": [
8+
{
9+
"id": 45675345,
10+
"pid": 44556545,
11+
"tid": None,
12+
"uid": 123456,
13+
"description": "",
14+
"start": "2020-08-24T15:43:11+03:00",
15+
"end": "2020-08-24T15:43:19+03:00",
16+
"updated": "2020-08-24T15:43:19+03:00",
17+
"dur": 8000,
18+
"user": "Test User",
19+
"use_stop": True,
20+
"client": "test-client",
21+
"project": "test project",
22+
"project_color": "0",
23+
"project_hex_color": "#990099",
24+
"task": None,
25+
"billable": None,
26+
"is_billable": False,
27+
"cur": None,
28+
"tags": [],
29+
}
30+
],
31+
}
32+
33+
TIME_ENTRIES_RESPONSE = [
34+
{
35+
"id": 45675345,
36+
"guid": "3ab9166aac16cbf1374edda1cb652f69",
37+
"wid": 4581172,
38+
"pid": 44556545,
39+
"billable": False,
40+
"start": "2020-08-24T12:43:11+00:00",
41+
"stop": "2020-08-24T12:43:19+00:00",
42+
"duration": 8,
43+
"duronly": False,
44+
"at": "2020-08-24T12:43:19+00:00",
45+
"uid": 123456,
46+
},
47+
]

tests/test_repositories.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from toggl_python import (
2+
ReportTimeEntries,
3+
TokenAuth,
4+
ReportTimeEntry,
5+
TimeEntries,
6+
TimeEntry,
7+
)
8+
from tests.fixtures import REPORT_TIME_ENTRIES_RESPONSE, TIME_ENTRIES_RESPONSE
9+
10+
11+
def test_report_time_entries_pagination(patch_report_time_entries):
12+
auth = TokenAuth("token")
13+
report_time_entries = ReportTimeEntries(auth=auth).list()
14+
total_count = REPORT_TIME_ENTRIES_RESPONSE["total_count"]
15+
per_page = REPORT_TIME_ENTRIES_RESPONSE["per_page"]
16+
assert report_time_entries.total_count == total_count
17+
assert report_time_entries.per_page == per_page
18+
assert len(report_time_entries) == len(REPORT_TIME_ENTRIES_RESPONSE["data"])
19+
for report_time_entry in report_time_entries:
20+
assert isinstance(report_time_entry, ReportTimeEntry)
21+
22+
23+
def test_time_entries_no_pagination(patch_time_entries):
24+
auth = TokenAuth("token")
25+
time_entries = TimeEntries(auth=auth).list()
26+
assert not hasattr(time_entries, "total_count")
27+
assert not hasattr(time_entries, "per_page")
28+
assert len(time_entries) == len(TIME_ENTRIES_RESPONSE)
29+
for time_entry in time_entries:
30+
assert isinstance(time_entry, TimeEntry)

0 commit comments

Comments
 (0)