Exemplo n.º 1
0
 def test_get_spesific_books(self, library1, users1):
     mmaker = MessageMaker()
     for user in users1:
         # 指定ユーザの借りている本で2日以内に期限切れの本を取得
         expire_books = library1.get_expire_rental_books(user,
                                                         param={"xdays": 2})
         print("====================")
         print("期限切れ間近の本のみ取得")
         print("====================")
         if expire_books is not None or len(expire_books.list) == 0:
             print(expire_books)
             print(
                 mmaker.get_rental_books_message(
                     UserBookInfo(user, rental_books=expire_books)))
         # 指定ユーザの予約本で「準備完了」「移送中」の本を取得
         prepared_reserved_books = library1.get_prepared_reserved_books(
             user)
         print("====================")
         print("準備できた予約本のみ取得")
         print("====================")
         if prepared_reserved_books is not None or len(
                 prepared_reserved_books.list):
             print(prepared_reserved_books)
             print(
                 mmaker.get_reserved_books_message(
                     UserBookInfo(user,
                                  reserved_books=prepared_reserved_books)))
Exemplo n.º 2
0
    def test_get_all_books(self, library1, users1):
        mmaker = MessageMaker()
        for user in users1:
            # 指定ユーザの借りている本を全て取得
            rental_books = library1.get_all_rental_books(user)
            print("====================")
            print("指定ユーザの借りている本を全て取得")
            print("====================")
            print(rental_books)
            print(
                mmaker.get_rental_books_message(
                    UserBookInfo(user, rental_books=rental_books)))
            # 指定ユーザの予約本を全て取得
            reserved_books = library1.get_all_reserved_books(user)
            print("====================")
            print("指定ユーザの予約している本を全て取得")
            print("====================")
            print(reserved_books)
            print(
                mmaker.get_reserved_books_message(
                    UserBookInfo(user, reserved_books=reserved_books)))

            print("====================")
            print("指定ユーザの借り本・予約本を全て表示")
            print("====================")
            info = UserBookInfo(user,
                                rental_books=rental_books,
                                reserved_books=reserved_books)
            print(mmaker.get_rental_and_reserved_books_message(info))
Exemplo n.º 3
0
def search_rental(params: Dict) -> Union[List[str], List[UserBookInfo]]:
    library: Library = Library()
    message_maker: MessageMaker = MessageMaker()
    rental_infos: List[UserBookInfo] = []
    messages: List[str] = []

    users = _fix_users(params)
    for user in users:
        if params.get("mode", "rental") == "expire":
            # 指定ユーザの借りている本で2日以内に期限切れの本を取得
            rental_books = library.get_expire_rental_books(user,
                                                           param={"xdays": 2})
        else:
            # 指定ユーザの借りている本を全て取得
            rental_books = library.get_all_rental_books(user)

        info = UserBookInfo(user, rental_books=rental_books)
        if params.get("separate", False):
            _append_message(
                messages, message_maker.get_rental_books_message(info, params))

        rental_infos.append(info)

    if params.get("separate", False) is False:
        # 各ユーザの借り本をまとめて表示
        _append_message(
            messages,
            message_maker.get_all_users_rental_books_message(
                rental_infos, params))

    if params.get("result_type", "message") == "message":
        return messages
    else:
        return rental_infos
Exemplo n.º 4
0
def search_reserve(params: Dict) -> Union[List[str], List[UserBookInfo]]:
    library: Library = Library()
    message_maker: MessageMaker = MessageMaker()
    reserved_infos: List[UserBookInfo] = []
    messages: List[str] = []

    users = _fix_users(params)
    for user in users:
        if params.get("mode", "reserve") == "prepare":
            # 指定ユーザの借りている本を全て取得
            rental_books = library.get_all_rental_books(user)
            # 指定ユーザの予約本で「準備完了」「移送中」の本を取得
            reserved_books = library.get_prepared_reserved_books(user)
            info = UserBookInfo(user,
                                rental_books=rental_books,
                                reserved_books=reserved_books)
        else:
            # 指定ユーザの予約本を全て取得
            reserved_books = library.get_all_reserved_books(user)
            info = UserBookInfo(user, reserved_books=reserved_books)

        if params.get("separate", False):
            if params.get("mode", "reserve") == "prepare":
                _append_message(
                    messages,
                    message_maker.get_rental_and_reserved_books_message(
                        info, params))
            else:
                _append_message(
                    messages,
                    message_maker.get_reserved_books_message(info, params))

        reserved_infos.append(info)

    if params.get("separate", False) is False:
        # 各ユーザの予約本をまとめて表示
        _append_message(
            messages,
            message_maker.get_all_users_reserved_books_message(
                reserved_infos, params))

    if params.get("result_type", "message") == "message":
        return messages
    else:
        return reserved_infos
Exemplo n.º 5
0
    def test_prepared_message(self, message_maker1: MessageMaker):
        reserved_books = ReservedBooks()

        book = ReservedBook("ご用意できました", "", "title", "kind", "yoyaku_date",
                            "torioki_date", "receive")
        reserved_books.append(book)

        info = UserBookInfo(User("{}"), reserved_books=reserved_books)
        message_maker1.get_all_users_reserved_books_message([info])
Exemplo n.º 6
0
    def test_to_string(self):
        reserved_books = ReservedBooks()

        book = ReservedBook("ご用意できました", "", "title", "kind", "yoyaku_date",
                            "torioki_date", "receive")
        reserved_books.append(book)

        info = UserBookInfo(User('{"disp_name":"hoge"}'),
                            reserved_books=reserved_books)
        print(info)
Exemplo n.º 7
0
 def test_empty(self, zero_behavior, message_maker1: MessageMaker):
     rental_books = RentalBooks()
     reserved_books = ReservedBooks()
     empty_info = UserBookInfo(User("{}"),
                               rental_books=rental_books,
                               reserved_books=reserved_books)
     message_maker1.get_all_users_rental_books_message(
         [empty_info], params={"zero": zero_behavior})
     message_maker1.get_all_users_reserved_books_message(
         [empty_info], params={"zero": zero_behavior})
     message_maker1.get_rental_books_message(empty_info,
                                             params={"zero": zero_behavior})
     message_maker1.get_reserved_books_message(
         empty_info, params={"zero": zero_behavior})
     message_maker1.get_rental_and_reserved_books_message(
         empty_info, params={"zero": zero_behavior})
Exemplo n.º 8
0
    def test_get_all_users_books(self, library1, users1):
        infos = []
        mmaker = MessageMaker()
        for user in users1:
            # 指定ユーザの借りている本を全て取得
            rental_books = library1.get_all_rental_books(user)
            # 指定ユーザの予約本を全て取得
            reserved_books = library1.get_all_reserved_books(user)

            info = UserBookInfo(user,
                                rental_books=rental_books,
                                reserved_books=reserved_books)
            infos.append(info)

        # 各ユーザの借り本・予約本をまとめて表示
        print(mmaker.get_all_users_rental_books_message(infos))
        print(mmaker.get_all_users_reserved_books_message(infos))