Skip to content

Commit

Permalink
🤡 mocks: fix get sensors records count params of sensors records repo…
Browse files Browse the repository at this point in the history
…sitory
  • Loading branch information
JohnPetros committed Jul 4, 2024
1 parent 436b412 commit 741e384
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def get_last_sensors_records(self, count) -> list[SensorsRecord]: ...
def get_sensors_record_by_id(self, id: str) -> SensorsRecord | None: ...

@abstractmethod
def get_sensors_records_count(self) -> int: ...
def get_sensors_records_count(
self, plant_id: str, start_date: date, end_date: date, page_number: int = 1
) -> int: ...

@abstractmethod
def update_sensors_record_by_id(self, sensors_record: SensorsRecord) -> None: ...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, date
from datetime import date

from pytest import fixture, raises

Expand All @@ -16,9 +16,7 @@

def fake_request(base_fake_request: dict):
return {
"fertilizer_expiration_date": datetime(
year=2024, month=3, day=16, hour=12, minute=0
),
"fertilizer_expiration_date": date(year=2024, month=3, day=16),
"date": date(year=2024, month=12, day=12),
"hour": 12,
"illuminance": 12,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, date
from datetime import date, time

from pytest import fixture, raises

Expand All @@ -16,7 +16,7 @@

def fake_request(base_fake_request: dict):
return {
"time": datetime(year=2024, month=12, day=12, hour=12, minute=52),
"time": time(hour=12, minute=52),
"date": date(year=2024, month=12, day=12),
"soil_humidity": 32,
"ambient_humidity": 55,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, date
from datetime import time, date

from pytest import fixture, raises

Expand All @@ -7,7 +7,11 @@
SensorRecordsRepositoryMock,
)
from core.entities.tests.fakers import SensorsRecordsFaker, PlantsFaker
from core.errors.validation import SensorsRecordNotValidError, DatetimeNotValidError
from core.errors.validation import (
SensorsRecordNotValidError,
DatetimeNotValidError,
DateNotValidError,
)
from core.errors.sensors_records import SensorsRecordNotFoundError
from core.errors.plants import PlantNotFoundError

Expand All @@ -16,7 +20,7 @@

def fake_request(base_fake_request: dict):
return {
"time": datetime(year=2024, month=12, day=12, hour=12, minute=52),
"time": time(hour=12, minute=52),
"date": date(year=2024, month=12, day=12),
"soil_humidity": 32,
"ambient_humidity": 55,
Expand Down Expand Up @@ -64,14 +68,27 @@ def it_should_throw_error_if_no_sensors_record_is_found_in_repository(
request=fake_request({"sensors_record_id": fake_record.id})
)

def it_should_throw_error_if_date_from_request_is_not_valid(
def it_should_throw_error_if_time_from_request_is_not_valid(
sensors_records_repository: SensorRecordsRepositoryMock,
use_case: UpdateSensorsRecord,
):
fake_record = SensorsRecordsFaker.fake()
sensors_records_repository.create_sensors_record(fake_record)
request = fake_request(
{"time": "not valid time", "sensors_record_id": fake_record.id}
)

with raises(DatetimeNotValidError):
use_case.execute(request)

def it_should_throw_error_if_date_from_request_is_not_valid(
sensors_records_repository: SensorRecordsRepositoryMock,
use_case: UpdateSensorsRecord,
):
fake_record = SensorsRecordsFaker.fake()
sensors_records_repository.create_sensors_record(fake_record)

with raises(DateNotValidError):
use_case.execute(
request=fake_request(
{"sensors_record_id": fake_record.id, "date": None}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def get_sensors_record_by_id(self, id: str) -> SensorsRecord | None:

return None

def get_sensors_records_count(self) -> int:
def get_sensors_records_count(
self, plant_id: str, start_date: date, end_date: date, page_number: int = 1
) -> int:
return len(self._sensors_records)

def update_sensors_record_by_id(self, sensors_record: SensorsRecord):
Expand Down

0 comments on commit 741e384

Please sign in to comment.