def test_find_all(self):
        employee_a = Employee(EmployeeId('001'), 'Bob')
        employee_b = Employee(EmployeeId('002'), 'Tom')
        employee_c = Employee(EmployeeId('003'), 'Ken')

        OratorEmployeeModel.to_orator_model(employee_a).save()
        OratorEmployeeModel.to_orator_model(employee_b).save()
        OratorEmployeeModel.to_orator_model(employee_c).save()

        assert self.repository.find_all() == [
            employee_a, employee_b, employee_c
        ]
Example #2
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'))
Example #3
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)
Example #4
0
    def test_社員のIDを渡したら単一の社員情報が取得できる(self):
        employee_id = EmployeeId('001')
        employee = Employee(employee_id, 'Bob')
        self.repository.data[employee_id] = employee

        command = FindEmployeeCommand('001')
        assert employee == self.usecase.find_employee(command)
Example #5
0
    def _create_employee_id(self, reserver_id: str) -> EmployeeId:
        employee = self.employee_repository.find_by_id(EmployeeId(reserver_id))

        if employee is None:
            raise NotFoundEmployeeIdError('そんな社員IDはありませんよ')

        return employee.id
    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
Example #7
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'))
Example #8
0
    def find_employee(self, command: FindEmployeeCommand) -> Employee:
        employee_id = EmployeeId(command.employee_id)

        if not self.domain_service.exists_id(employee_id):
            raise NotFoundEmployeeIdError('そのような社員IDはないぞ')

        employee = self.repository.find_by_id(employee_id)

        assert employee

        return employee
    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))
Example #11
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)
Example #12
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
 def test_find_by_id_return_None_when_not_exist_id(self):
     assert self.repository.find_by_id(EmployeeId('999')) is None
    def test_find_by_id(self):
        employee = Employee(EmployeeId('001'), 'Bob')

        OratorEmployeeModel.to_orator_model(employee).save()

        assert self.repository.find_by_id(employee.id) == employee
 def test_社員IDは0埋めの3桁の数字でなければなりません(self, value: str):
     with pytest.raises(InvalidFormatEmployeeIdError):
         EmployeeId(value)
 def to_employee(cls, source: OratorEmployeeModel) -> Employee:
     return Employee(EmployeeId(source.id), source.name)