1
1
from __future__ import annotations
2
2
3
- from datetime import datetime , timezone
4
- from typing import TYPE_CHECKING , Dict , Union
3
+ from typing import TYPE_CHECKING , Union
5
4
6
5
import pytest
7
6
from httpx import Response
8
7
from pydantic import ValidationError
9
8
from toggl_python .schemas .report_time_entry import SearchReportTimeEntriesResponse
10
9
10
+ from tests .conftest import fake
11
11
from tests .responses .report_time_entry_post import SEARCH_REPORT_TIME_ENTRY_RESPONSE
12
12
13
13
14
14
if TYPE_CHECKING :
15
+ from datetime import date
16
+
15
17
from respx import MockRouter
16
18
from toggl_python .entities .report_time_entry import ReportTimeEntry
17
19
@@ -26,29 +28,30 @@ def test_search_report_time_entries__without_params(
26
28
27
29
28
30
@pytest .mark .parametrize (
29
- argnames = "request_body, start_date, end_date" ,
31
+ argnames = "start_date, end_date" ,
30
32
argvalues = (
31
33
(
32
- {"start_date" : "2020-06-10T00:00:00+00:00" , "end_date" : "2020-10-01T00:00:00+00:00" },
33
- datetime (2020 , 6 , 10 , tzinfo = timezone .utc ),
34
- datetime (2020 , 10 , 1 , tzinfo = timezone .utc ),
34
+ fake .date_this_decade (before_today = True ).isoformat (),
35
+ fake .date_this_decade (before_today = True ).isoformat (),
35
36
),
36
37
(
37
- {"start_date" : "2023-09-12T00:00:00-03:00" , "end_date" : "2023-10-12T00:00:00-01:00" },
38
- "2023-09-12T00:00:00-03:00" ,
39
- "2023-10-12T00:00:00-01:00" ,
38
+ fake .date_this_decade (before_today = True ),
39
+ fake .date_this_decade (before_today = True ),
40
40
),
41
41
),
42
42
)
43
43
def test_search_report_time_entries__with_start_and_end_date (
44
- request_body : Dict [str , str ],
45
- start_date : Union [datetime , str ],
46
- end_date : Union [datetime , str ],
44
+ start_date : Union [date , str ],
45
+ end_date : Union [date , str ],
47
46
response_report_mock : MockRouter ,
48
47
authed_report_time_entry : ReportTimeEntry ,
49
48
) -> None :
50
49
fake_workspace_id = 123
51
50
uri = f"/{ fake_workspace_id } /search/time_entries"
51
+ request_body = {
52
+ "start_date" : start_date if isinstance (start_date , str ) else start_date .isoformat (),
53
+ "end_date" : end_date if isinstance (end_date , str ) else end_date .isoformat (),
54
+ }
52
55
mocked_route = response_report_mock .post (uri , json = request_body ).mock (
53
56
return_value = Response (status_code = 200 , json = [SEARCH_REPORT_TIME_ENTRY_RESPONSE ]),
54
57
)
@@ -57,7 +60,9 @@ def test_search_report_time_entries__with_start_and_end_date(
57
60
]
58
61
59
62
result = authed_report_time_entry .search (
60
- workspace_id = fake_workspace_id , start_date = start_date , end_date = end_date
63
+ workspace_id = fake_workspace_id ,
64
+ start_date = start_date ,
65
+ end_date = end_date ,
61
66
)
62
67
63
68
assert mocked_route .called is True
@@ -68,14 +73,15 @@ def test_search_report_time_entries__with_all_params(
68
73
response_report_mock : MockRouter ,
69
74
authed_report_time_entry : ReportTimeEntry ,
70
75
) -> None :
71
- fake_workspace_id = 123
76
+ fake_workspace_id = fake .random_int (min = 1 )
77
+ page_size = fake .random_int (min = 1 , max = 100 )
72
78
request_body = {
73
- "start_date" : "2021-12-20T00:00:00+00:00" ,
74
- "end_date" : "2021-12-30T00:00:00+00:00" ,
75
- "user_ids" : [30809356 ],
76
- "project_ids" : [202793182 ],
77
- "page_size" : 10 ,
78
- "first_row_number" : 11 ,
79
+ "start_date" : fake . date () ,
80
+ "end_date" : fake . date () ,
81
+ "user_ids" : [fake . random_int () ],
82
+ "project_ids" : [fake . random_int () ],
83
+ "page_size" : page_size ,
84
+ "first_row_number" : page_size + 1 ,
79
85
}
80
86
uri = f"/{ fake_workspace_id } /search/time_entries"
81
87
mocked_route = response_report_mock .post (uri , json = request_body ).mock (
0 commit comments