Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import datetime | ||
import uuid | ||
|
||
from src.domain.repo.i_calendar_repo import ICalendarRepo | ||
from src.domain.repo.i_db_context import IDBContext | ||
|
||
|
||
class UpdateCalendar: | ||
def __init__(self, db_context: IDBContext, calendar_repo: ICalendarRepo) -> None: | ||
self.db_context = db_context | ||
self.calendar_repo = calendar_repo | ||
|
||
def run( | ||
self, calendar_id: uuid.UUID, name: str, birthday: datetime.date, lifespan: int | ||
) -> None: | ||
with self.db_context.begin_tx(): | ||
calendar = self.calendar_repo.get_or_error(calendar_id) | ||
calendar.update_basic_info(name, birthday, lifespan) |
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,28 @@ | ||
import datetime | ||
from unittest.mock import MagicMock | ||
|
||
from src.appl.update_calendar import UpdateCalendar | ||
from src.domain.entity.calendar import Calendar | ||
from src.domain.repo.i_calendar_repo import ICalendarRepo | ||
from src.domain.repo.i_db_context import IDBContext | ||
|
||
|
||
class TestUpdateCalendar: | ||
def test_run(self): | ||
calendar = self._create_calendar() | ||
db_context = MagicMock(spec=IDBContext) | ||
calendar_repo = MagicMock(spec=ICalendarRepo) | ||
calendar_repo.get_or_error.return_value = calendar | ||
command = UpdateCalendar(db_context, calendar_repo) | ||
|
||
name = "뉴고도" | ||
birthday = datetime.date(2000, 6, 21) | ||
lifespan = 100 | ||
command.run(calendar.id, name, birthday, lifespan) | ||
|
||
assert calendar.name == name | ||
assert calendar.birthday == birthday | ||
assert calendar.lifespan == lifespan | ||
|
||
def _create_calendar(self) -> Calendar: | ||
return Calendar.create("고도", datetime.date(1988, 6, 21), 80) |