Ejemplo n.º 1
0
    def test_指定した予約の予約時間帯を変更できること(self):
        builder = DummyReservationBuilder()
        reservation_A = builder.with_meeting_room_id(
            MeetingRoomId('A')).build()
        reservation_B = builder.with_meeting_room_id(
            MeetingRoomId('B')).build()
        reservation_C = builder.with_meeting_room_id(
            MeetingRoomId('C')).build()

        self.repository.reserve_new_meeting_room(reservation_A)
        self.repository.reserve_new_meeting_room(reservation_B)
        self.repository.reserve_new_meeting_room(reservation_C)

        new_time_range_to_reserve = TimeRangeToReserve(
            使用日時(2020, 4, 9, 15, 00), 使用日時(2020, 4, 9, 17, 00))
        self.usecase.change_time_range(reservation_B.id,
                                       new_time_range_to_reserve)

        expected = [
            reservation_A,
            dataclasses.replace(
                reservation_B,
                time_range_to_reserve=new_time_range_to_reserve), reservation_C
        ]

        actual = [
            self.repository.find_by_id(reservation_A.id),
            self.repository.find_by_id(reservation_B.id),
            self.repository.find_by_id(reservation_C.id)
        ]

        assert actual == expected
    def test_指定した予約の会議室を変更できること(self):
        builder = DummyReservationBuilder()
        reservation_A = builder.with_meeting_room_id(
            MeetingRoomId('A')).build()
        reservation_B = builder.with_meeting_room_id(
            MeetingRoomId('B')).build()
        reservation_C = builder.with_meeting_room_id(
            MeetingRoomId('C')).build()

        self.repository.reserve_new_meeting_room(reservation_A)
        self.repository.reserve_new_meeting_room(reservation_B)
        self.repository.reserve_new_meeting_room(reservation_C)

        meeting_room_id_Z = MeetingRoomId('Z')
        self.usecase.change_meeting_room(reservation_B.id, meeting_room_id_Z)

        expected = [
            reservation_A,
            dataclasses.replace(reservation_B,
                                meeting_room_id=meeting_room_id_Z),
            reservation_C
        ]

        actual = [
            self.repository.find_by_id(reservation_A.id),
            self.repository.find_by_id(reservation_B.id),
            self.repository.find_by_id(reservation_C.id)
        ]

        assert actual == expected
    def test_find_all(self):
        meeting_room_a = MeetingRoom(MeetingRoomId('A'), '大会議室')
        meeting_room_b = MeetingRoom(MeetingRoomId('B'), '中会議室')
        meeting_room_c = MeetingRoom(MeetingRoomId('C'), '小会議室')

        OratorMeetingRoomModel.to_orator_model(meeting_room_a).save()
        OratorMeetingRoomModel.to_orator_model(meeting_room_b).save()
        OratorMeetingRoomModel.to_orator_model(meeting_room_c).save()

        assert self.repository.find_all() == [
            meeting_room_a, meeting_room_b, meeting_room_c
        ]
    def test_既存の予約を別の会議室に変更ができること(self, reservation):
        expected = dataclasses.replace(reservation, meeting_room_id=MeetingRoomId('B'))

        self.repository.data[reservation.id] = reservation
        self.usecase.change_meeting_room(reservation.id, expected.meeting_room_id)

        assert expected == self.repository.data[reservation.id]
Ejemplo n.º 5
0
 def reservation(self) -> Reservation:
     """不正でないReservationインスタンスを作成するだけのfixture"""
     return Reservation(
         ReservationId(str(uuid.uuid4())),
         TimeRangeToReserve(使用日時(2020, 4, 2, 13, 00),
                            使用日時(2020, 4, 2, 14, 00)),
         NumberOfParticipants(4), MeetingRoomId('A'), EmployeeId('001'))
Ejemplo n.º 6
0
    def test_1(self, reservation: Reservation):
        # MeetingRoom に関する準備
        meeting_room_repository = InMemoryMeetingRoomRepository()
        meeting_room_domain_service = MeetingRoomDomainService(
            meeting_room_repository)
        find_meeting_room_usecase = FindMeetingRoomUseCase(
            meeting_room_repository, meeting_room_domain_service)
        meeting_room_id = MeetingRoomId('A')
        meeting_room = MeetingRoom(meeting_room_id, '大会議室')

        meeting_room_repository.data[meeting_room_id] = meeting_room

        # Employee に関する準備
        employee_repository = InMemoryEmployeeRepository()
        employee_domain_service = EmployeeDomainService(employee_repository)
        find_employee_usecase = FindEmployeeUseCase(employee_repository,
                                                    employee_domain_service)

        employee_id = EmployeeId('001')
        employee = Employee(employee_id, 'Bob')
        employee_repository.data[employee_id] = employee

        # こっから本編
        success_message_builder = CliNewReservationSuccessMessageBuilder(
            find_meeting_room_usecase, find_employee_usecase)

        success_message = success_message_builder.build(reservation)

        expected = 'Bobさん名義で、2020年04月02日 13:00-14:00 大会議室 を 4名で 予約しましたよ'
        assert expected == str(success_message)
Ejemplo n.º 7
0
    def test_会議室のIDを渡したら単一の会議室情報が取得できる(self):
        meeting_room_id = MeetingRoomId('A')
        meeting_room = MeetingRoom(meeting_room_id, '大会議室')
        command = FindMeetingRoomCommand('A')

        self.repository.data[meeting_room_id] = meeting_room

        assert meeting_room == self.usecase.find_meeting_room(command)
    def test_単一の正常なReservationを生成できる_予約時間帯は翌日13時から14時がデフォルトとなる(self):
        expected = Reservation(
            ReservationId('1'),
            TimeRangeToReserve(使用日時(2020, 4, 2, 13, 00),
                               使用日時(2020, 4, 2, 14, 00)),
            NumberOfParticipants(4), MeetingRoomId('A'), EmployeeId('001'))

        assert DummyReservationBuilder().build() == expected
Ejemplo n.º 9
0
    def _create_meeting_room_id(self, meeting_room_id: str) -> MeetingRoomId:
        meeting_room = self.meeting_room_repository.find_by_id(
            MeetingRoomId(meeting_room_id))

        if meeting_room is None:
            raise NotFoundMeetingRoomIdError('そんな会議室IDはありませんよ')

        return meeting_room.id
    def test_会議室変更後の予約が既存の予約とぶつかっていたらダメだよ(self, reservation):
        reservation2 = dataclasses.replace(reservation,
                                           id=ReservationId(str(uuid.uuid4())),
                                           meeting_room_id=MeetingRoomId('A'))

        self.repository.data[reservation.id] = reservation
        self.repository.data[reservation2.id] = reservation2

        with pytest.raises(その会議室はその時間帯では予約ができませんよエラー):
            self.usecase.change_meeting_room(reservation2.id, reservation.meeting_room_id)
Ejemplo n.º 11
0
    def __post_init__(self):
        # Pythonのデフォルト引数の罠を踏まないための実装
        if self.execute_date is None:
            self.execute_date = datetime.datetime.today()

        self.__dummy_reservation = Reservation(self._get_next_reservation_id(),
                                               self._default_time_to_range(),
                                               NumberOfParticipants(4),
                                               MeetingRoomId('A'),
                                               EmployeeId('001'))
    def test_指定した予約のみがキャンセルとなること(self):
        builder = DummyReservationBuilder()
        reservation_A = builder.with_meeting_room_id(MeetingRoomId('A')).build()
        reservation_B = builder.with_meeting_room_id(MeetingRoomId('B')).build()
        reservation_C = builder.with_meeting_room_id(MeetingRoomId('C')).build()

        self.repository.reserve_new_meeting_room(reservation_A)
        self.repository.reserve_new_meeting_room(reservation_B)
        self.repository.reserve_new_meeting_room(reservation_C)

        self.usecase.cancel_meeting_room(reservation_B.id)

        expected = [reservation_A,
                    dataclasses.replace(reservation_B, reservation_status=ReservationStatus.Canceled),
                    reservation_C]

        actual = [self.repository.find_by_id(reservation_A.id),
                  self.repository.find_by_id(reservation_B.id),
                  self.repository.find_by_id(reservation_C.id)]

        assert actual == expected
Ejemplo n.º 13
0
    def find_meeting_room(self,
                          command: FindMeetingRoomCommand) -> MeetingRoom:
        meeting_room_id = MeetingRoomId(command.meeting_room_id)

        if not self.domain_service.exists_id(meeting_room_id):
            raise NotFoundMeetingRoomIdError('そのような会議室IDはありません')

        meeting_room = self.repository.find_by_id(meeting_room_id)

        assert meeting_room

        return meeting_room
    def setup(self):
        employee_repository = InMemoryEmployeeRepository()
        employee_id = EmployeeId('001')
        employee = Employee(employee_id, 'Bob')
        employee_repository.data[employee_id] = employee

        meeting_room_repository = InMemoryMeetingRoomRepository()
        meeting_room_id = MeetingRoomId('A')
        meeting_room = MeetingRoom(meeting_room_id, '大会議室')
        meeting_room_repository.data[meeting_room_id] = meeting_room

        self.reservation_factory = ReservationFactory(meeting_room_repository,
                                                      employee_repository)
    def to_reservation(cls, source: OratorReservationModel) -> Reservation:
        start_yyyy_mm_dd_HH_MM = datetime.datetime.strptime(
            source.start_datetime, '%Y-%m-%d %H:%M:%S').timetuple()[:5]
        end_yyyy_mm_dd_HH_MM = datetime.datetime.strptime(
            source.end_datetime, '%Y-%m-%d %H:%M:%S').timetuple()[:5]
        time_range_to_reserve = TimeRangeToReserve(
            使用日時(*start_yyyy_mm_dd_HH_MM), 使用日時(*end_yyyy_mm_dd_HH_MM))

        return Reservation(
            ReservationId(source.id), time_range_to_reserve,
            NumberOfParticipants(source.number_of_participants),
            MeetingRoomId(source.meeting_room_id),
            EmployeeId(source.reserver_id),
            ReservationStatus.from_str(source.reservation_status))
Ejemplo n.º 16
0
    def setup(self):
        database_manager = DatabaseManager(TEST_DB_CONFIG)
        Model.set_connection_resolver(database_manager)
        migrate_in_memory(database_manager)

        employee_repository = OratorEmployeeRepository()
        employee_id = EmployeeId('001')
        employee = Employee(employee_id, 'Bob')
        OratorEmployeeModel.to_orator_model(employee).save()

        meeting_room_repository = OratorMeetingRoomRepository()
        meeting_room_id = MeetingRoomId('A')
        meeting_room = MeetingRoom(meeting_room_id, '大会議室')
        OratorMeetingRoomModel.to_orator_model(meeting_room).save()

        self.reservation_factory = ReservationFactory(meeting_room_repository,
                                                      employee_repository)
Ejemplo n.º 17
0
    def test_Reservationが作れるよ(self):
        reservation_id = 'データクラス同士の比較のために、やっているよ'

        actual = self.reservation_factory.create(date='20200402',
                                                 start_time='1100',
                                                 end_time='1300',
                                                 meeting_room_id='A',
                                                 reserver_id='001',
                                                 number_of_participants='5',
                                                 reservation_id=reservation_id)

        expected = Reservation(
            ReservationId(reservation_id),
            TimeRangeToReserve(使用日時(2020, 4, 2, 11, 00),
                               使用日時(2020, 4, 2, 13, 00)),
            NumberOfParticipants(5), MeetingRoomId('A'), EmployeeId('001'))

        assert actual == expected
    def test_複雑なReservationもメソッドチェーンでつくりやすいよ(self):
        another_time_range_to_reserve = TimeRangeToReserve(
            使用日時(2020, 4, 15, 13, 00), 使用日時(2020, 4, 15, 14, 00))
        another_meeting_room_id = MeetingRoomId('Z')
        another_employee_id_999 = EmployeeId('999')

        expected = Reservation(ReservationId('1'),
                               another_time_range_to_reserve,
                               NumberOfParticipants(4),
                               another_meeting_room_id,
                               another_employee_id_999,
                               ReservationStatus.Canceled)

        actual = DummyReservationBuilder() \
            .with_time_range_to_reserve(another_time_range_to_reserve) \
            .with_meeting_room_id(another_meeting_room_id) \
            .with_reserver_id(another_employee_id_999) \
            .with_cancel() \
            .build()

        assert actual == expected
Ejemplo n.º 19
0
    def test_指定IDのReservationが1件だけ取得できる(self, reservation: Reservation):
        self.repository.data[reservation.id] = reservation
        self.repository.data[ReservationId('B')] = dataclasses.replace(reservation, meeting_room_id=MeetingRoomId('B'))
        self.repository.data[ReservationId('C')] = dataclasses.replace(reservation, meeting_room_id=MeetingRoomId('C'))

        assert self.usecase.find_reservation(reservation.id) == reservation
    def test_find_by_id(self):
        meeting_room = MeetingRoom(MeetingRoomId('A'), '大会議室')

        OratorMeetingRoomModel.to_orator_model(meeting_room).save()

        assert self.repository.find_by_id(meeting_room.id) == meeting_room
 def test_find_by_id_return_None_when_not_exist_id(self):
     assert self.repository.find_by_id(MeetingRoomId('Z')) is None
 def to_meeting_room(cls, source: OratorMeetingRoomModel) -> MeetingRoom:
     return MeetingRoom(MeetingRoomId(source.id), source.name)
 def test_存在しない予約に対する会議室変更依頼はダメだよ(self, reservation):
     with pytest.raises(NotFoundReservationError):
         self.usecase.change_meeting_room(reservation.id, MeetingRoomId('A'))
 def test_会議室IDは大文字のアルファベット1字でなければなりません(self, value: str):
     with pytest.raises(InvalidFormatMeetingRoomIdError):
         MeetingRoomId(value)