-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Change date params type for search ReportTimeEntry method * Add check for too old date params for listing TimeEntries
- Loading branch information
Showing
11 changed files
with
334 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from typing import TYPE_CHECKING | ||
|
||
from toggl_python.schemas.project import ProjectResponse | ||
|
||
# Necessary to mark all tests in module as integration | ||
from tests.integration import pytestmark # noqa: F401 - imported but unused | ||
|
||
|
||
if TYPE_CHECKING: | ||
from toggl_python.entities.workspace import Workspace | ||
|
||
|
||
def test_get_projects__without_query_params(i_authed_workspace: Workspace) -> None: | ||
# Later Create project and init and delete it at the end | ||
# Now this actions are not implemented | ||
workspace_id = int(os.environ["WORKSPACE_ID"]) | ||
expected_result = set(ProjectResponse.model_fields.keys()) | ||
|
||
result = i_authed_workspace.get_projects(workspace_id) | ||
|
||
assert result[0].model_fields_set == expected_result | ||
|
||
|
||
def test_get_project_by_id(i_authed_workspace: Workspace) -> None: | ||
# Later Create project and init and delete it at the end | ||
# Now this actions are not implemented | ||
workspace_id = int(os.environ["WORKSPACE_ID"]) | ||
project_id = int(os.environ["PROJECT_ID"]) | ||
expected_result = set(ProjectResponse.model_fields.keys()) | ||
|
||
result = i_authed_workspace.get_project(workspace_id, project_id) | ||
|
||
assert result.model_fields_set == expected_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from datetime import timedelta | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
from toggl_python.schemas.report_time_entry import ( | ||
SearchReportTimeEntriesResponse, | ||
) | ||
|
||
from tests.conftest import fake | ||
|
||
# Necessary to mark all tests in module as integration | ||
from tests.integration import pytestmark # noqa: F401 - imported but unused | ||
|
||
|
||
if TYPE_CHECKING: | ||
from toggl_python.entities.report_time_entry import ReportTimeEntry | ||
from toggl_python.entities.workspace import Workspace | ||
|
||
|
||
try: | ||
import zoneinfo | ||
except ImportError: | ||
from backports import zoneinfo | ||
|
||
|
||
@pytest.mark.parametrize( | ||
argnames="use_dates_repr", | ||
argvalues=(True, False), | ||
ids=("str date arguments", "date date arguments"), | ||
) | ||
def test_search_report_time_entries__with_start_and_end_dates( | ||
use_dates_repr: bool, | ||
i_authed_report_time_entry: ReportTimeEntry, | ||
i_authed_workspace: Workspace, | ||
) -> None: | ||
workspace_id = int(os.environ["WORKSPACE_ID"]) | ||
timezone_name = fake.timezone() | ||
tz = zoneinfo.ZoneInfo(timezone_name) | ||
start_date = fake.date_this_decade() | ||
delta = fake.random_int(min=1, max=364) | ||
end_date = start_date + timedelta(days=delta) | ||
time_entry = i_authed_workspace.create_time_entry( | ||
workspace_id, | ||
start_datetime=fake.date_time_between_dates(start_date, end_date, tzinfo=tz), | ||
created_with=fake.word(), | ||
) | ||
|
||
expected_result = set(SearchReportTimeEntriesResponse.model_fields.keys()) | ||
|
||
result = i_authed_report_time_entry.search( | ||
workspace_id, | ||
start_date=start_date.isoformat() if use_dates_repr else start_date, | ||
end_date=end_date.isoformat() if use_dates_repr else end_date, | ||
) | ||
|
||
assert result[0].model_fields_set == expected_result | ||
|
||
_ = i_authed_workspace.delete_time_entry(workspace_id, time_entry.id) | ||
|
||
|
||
def test_search_report_time_entries__not_found( | ||
i_authed_report_time_entry: ReportTimeEntry, | ||
) -> None: | ||
workspace_id = int(os.environ["WORKSPACE_ID"]) | ||
# Set explicit date range to avoid finding unexpected existing test TimeEntries | ||
time_entry_start_date = fake.date_between(start_date="-15y", end_date="-2y") | ||
delta = fake.random_int(min=1, max=364) | ||
end_date = time_entry_start_date + timedelta(days=delta) | ||
start_date = fake.date_between_dates(time_entry_start_date, end_date) | ||
|
||
result = i_authed_report_time_entry.search( | ||
workspace_id, | ||
start_date=start_date, | ||
end_date=end_date, | ||
) | ||
|
||
assert result == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from typing import TYPE_CHECKING | ||
|
||
from toggl_python.schemas.workspace import WorkspaceResponse | ||
|
||
# Necessary to mark all tests in module as integration | ||
from tests.integration import pytestmark # noqa: F401 - imported but unused | ||
|
||
|
||
if TYPE_CHECKING: | ||
from toggl_python.entities.workspace import Workspace | ||
|
||
|
||
def test_get_workspace_by_id(i_authed_workspace: Workspace) -> None: | ||
workspace_id = int(os.environ["WORKSPACE_ID"]) | ||
expected_result = set(WorkspaceResponse.model_fields.keys()) | ||
|
||
result = i_authed_workspace.get(workspace_id) | ||
|
||
assert result.model_fields_set == expected_result | ||
|
||
|
||
def test_get_workspaces__without_query_params(i_authed_workspace: Workspace)-> None: | ||
expected_result = set(WorkspaceResponse.model_fields.keys()) | ||
|
||
result = i_authed_workspace.list() | ||
|
||
assert result[0].model_fields_set == expected_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.