Skip to content

Commit 81fda9c

Browse files
committed
fix: TT-404 search by int in get_by_id
1 parent f2e1435 commit 81fda9c

File tree

8 files changed

+38
-16
lines changed

8 files changed

+38
-16
lines changed

V2/tests/api/azure/time_entry_azure_endpoints_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,21 @@ def test__time_entry_azure_endpoint__returns_an_time_entry__when_time_entry_matc
3838

3939
assert response.status_code == 200
4040
assert time_entry_json_data == json.dumps(time_entries_json[0])
41+
42+
43+
def test__get_time_entries_azure_endpoint__returns_a_status_code_400__when_time_entry_recive_invalid_id(
44+
create_temp_time_entries,
45+
):
46+
tmp_directory = create_temp_time_entries
47+
time_entries._get_time_entries.JSON_PATH = tmp_directory
48+
req = func.HttpRequest(
49+
method="GET",
50+
body=None,
51+
url=TIME_ENTRY_URL,
52+
route_params={"id": "invalid id"},
53+
)
54+
55+
response = time_entries.get_time_entries(req)
56+
57+
assert response.status_code == 400
58+
assert response.get_body() == b'Invalid Format ID'

V2/tests/integration/daos/time_entries_json_dao_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
fake_time_entries = [
1010
{
11-
"id": Faker().uuid4(),
11+
"id": Faker().pyint(),
1212
"start_date": str(Faker().date_time()),
1313
"owner_id": Faker().uuid4(),
1414
"description": Faker().sentence(),

V2/time_tracker/time_entries/_application/_time_entries/_get_time_entries.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ def get_time_entries(req: func.HttpRequest) -> func.HttpResponse:
1515
status_code = 200
1616

1717
if time_entry_id:
18-
response = _get_by_id(time_entry_id)
19-
if response == b'Not Found':
20-
status_code = 404
18+
try:
19+
response = _get_by_id(int(time_entry_id))
20+
if response == b'Not Found':
21+
status_code = 404
22+
except ValueError:
23+
response = b'Invalid Format ID'
24+
status_code = 400
2125
else:
2226
response = _get_all()
2327

@@ -26,7 +30,7 @@ def get_time_entries(req: func.HttpRequest) -> func.HttpResponse:
2630
)
2731

2832

29-
def _get_by_id(id: str) -> str:
33+
def _get_by_id(id: int) -> str:
3034
time_entry_use_case = _use_cases.GetTimeEntryUseCase(
3135
_create_time_entry_service(JSON_PATH)
3236
)

V2/time_tracker/time_entries/_domain/_persistence_contracts/_time_entries_dao.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class TimeEntriesDao(abc.ABC):
88
@abc.abstractmethod
9-
def get_by_id(self, id: str) -> TimeEntry:
9+
def get_by_id(self, id: int) -> TimeEntry:
1010
pass
1111

1212
@abc.abstractmethod

V2/time_tracker/time_entries/_domain/_services/_time_entry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class TimeEntryService:
66
def __init__(self, time_entry_dao: TimeEntriesDao):
77
self.time_entry_dao = time_entry_dao
88

9-
def get_by_id(self, id: str) -> TimeEntry:
9+
def get_by_id(self, id: int) -> TimeEntry:
1010
return self.time_entry_dao.get_by_id(id)
1111

1212
def get_all(self) -> typing.List[TimeEntry]:

V2/time_tracker/time_entries/_domain/_use_cases/_get_time_entry_by_id_use_case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ class GetTimeEntryUseCase:
55
def __init__(self, time_entry_service: TimeEntryService):
66
self.time_entry_service = time_entry_service
77

8-
def get_time_entry_by_id(self, id: str) -> TimeEntry:
8+
def get_time_entry_by_id(self, id: int) -> TimeEntry:
99
return self.time_entry_service.get_by_id(id)

V2/time_tracker/time_entries/_infrastructure/_data_persistence/_time_entries_dao.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, json_data_file_path: str):
1111
self.json_data_file_path = json_data_file_path
1212
self.time_entry_key = [field.name for field in dataclasses.fields(TimeEntry)]
1313

14-
def get_by_id(self, id: str) -> TimeEntry:
14+
def get_by_id(self, id: int) -> TimeEntry:
1515
time_entry = {
1616
time_entry.get('id'): time_entry
1717
for time_entry in self.__get_time_entries_from_file()

V2/time_tracker/time_entries/_infrastructure/_data_persistence/time_entries_data.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[{
2-
"id": "c61a4a49-3364-49a3-a7f7-0c5f2d15072b",
2+
"id": 1,
33
"start_date": "12/07/2021",
44
"owner_id": 2,
55
"tenant_id": "asdasdsa",
@@ -12,7 +12,7 @@
1212
"timezone_offset": "asdasdsa",
1313
"project_id": 1
1414
}, {
15-
"id": "c61a4a49-3364-49a3-a7f7-0c5f2d15072c",
15+
"id": 2,
1616
"start_date": "12/07/2021",
1717
"owner_id": 2,
1818
"tenant_id": "asdasdsa",
@@ -25,7 +25,7 @@
2525
"timezone_offset": "asdasdsa",
2626
"project_id": 1
2727
}, {
28-
"id": "c61a4a49-3364-49a3-a7f7-0c5f2d15072e",
28+
"id": 3,
2929
"start_date": "12/07/2021",
3030
"owner_id": 2,
3131
"tenant_id": "asdasdsa",
@@ -38,7 +38,7 @@
3838
"timezone_offset": "asdasdsa",
3939
"project_id": 1
4040
}, {
41-
"id": "c61a4a49-3364-49a3-a7f7-0c5f2d15072f",
41+
"id": 4,
4242
"start_date": "12/07/2021",
4343
"owner_id": 2,
4444
"tenant_id": "asdasdsa",
@@ -51,7 +51,7 @@
5151
"timezone_offset": "asdasdsa",
5252
"project_id": 1
5353
}, {
54-
"id": "c61a4a49-3364-49a3-a7f7-0c5f2d15072g",
54+
"id": 5,
5555
"start_date": "12/07/2021",
5656
"owner_id": 2,
5757
"tenant_id": "asdasdsa",
@@ -64,7 +64,7 @@
6464
"timezone_offset": "asdasdsa",
6565
"project_id": 1
6666
}, {
67-
"id": "c61a4a49-3364-49a3-a7f7-0c5f2d15072h",
67+
"id": 6,
6868
"start_date": "12/07/2021",
6969
"owner_id": 2,
7070
"tenant_id": "asdasdsa",
@@ -77,7 +77,7 @@
7777
"timezone_offset": "asdasdsa",
7878
"project_id": 1
7979
}, {
80-
"id": "c61a4a49-3364-49a3-a7f7-0c5f2d15072i",
80+
"id": 7,
8181
"start_date": "12/07/2021",
8282
"owner_id": 2,
8383
"tenant_id": "asdasdsa",

0 commit comments

Comments
 (0)