def test_sort(self): books = RentalBooks([]) books.append(RentalBook("test3", "2017/01/05", True, "hoge")) books.append(RentalBook("test1", "2017/01/03", True, "hoge")) book = RentalBook("test1", "2017/01/02", True, "hoge") books.append(book) books.apply_filter(RentalBookExpireFilter(xdays="5")) assert books.len == 3 assert books.get(0) == book # メモリ比較
def test_filter_to_rental_books_expired(self): books = RentalBooks([]) book = RentalBook("test1", "2017/01/01", True, "hoge") books.append(book) books.append(RentalBook("test2", "9999/01/02", True, "hoge")) books.append(RentalBook("test3", "9999/01/07", True, "hoge")) books.apply_filter(RentalBookExpiredFilter()) assert books.len == 1 assert books.get(0) == book # メモリ比較
def get_rental_books_message(self, format: str = "text") -> str: message = "" date_keyed_books_dict = RentalBooks.get_date_keyed_books_dict( self.rental_books) data = {"user": self, "date_keyed_books_dict": date_keyed_books_dict} message += Message.create( os.path.join(format, RentalBooks.TEMPLATE_RENTAL_BOOKS), data) return message
def __init__(self, data_json: str) -> None: data = json.loads(data_json) self.num: str = data.get("num") self.name: str = data.get("name") self.id: str = data.get("id") self.password: str = data.get("password") self.rental_books_count: int = 0 self.reserved_books_count: int = 0 self.rental_books: RentalBooks = RentalBooks() self.reserved_books: ReservedBooks = ReservedBooks()
class TestHtmlParser: def setup(self): KBot("wisteria") @pytest.mark.slow def test_get_rental_books(self): page = HtmlPage() user = User(os.environ["USER1"]) html = page.fetch_login_page(Library.LIBRALY_HOME_URL, user) HtmlParser.get_books(html, RentalBooks()) @pytest.mark.parametrize("books, books_class", [(RentalBooks(), RentalBooks), (ReservedBooks(), ReservedBooks)]) def test_get_books_no_table(self, books, books_class): with patch( "kbot.library.html_parser.HtmlParser._HtmlParser__get_books_table" ) as method, patch( "kbot.library.html_parser.HtmlParser._HtmlParser__get_soup"): method.return_value = None books = HtmlParser.get_books(None, books) assert isinstance(books, books_class) assert books.len == 0 @pytest.mark.parametrize("target, table_name", [(RentalBooks(), "FormLEND"), (ReservedBooks(), "FormRSV")]) def test_get_books_table(self, target, table_name): with patch("kbot.library.html_parser.HtmlParser._HtmlParser__get_table" ) as mock: soup_mock = MagicMock() HtmlParser._HtmlParser__get_books_table(soup_mock, target) mock.assert_called_once_with(soup_mock, table_name) def test_get_table_empty(self): soup = HtmlParser._HtmlParser__get_soup("<html></html>") result = HtmlParser._HtmlParser__get_table(soup, "empty") assert result is None
def test_get_rental_books(self): page = HtmlPage() user = User(os.environ["USER1"]) html = page.fetch_login_page(Library.LIBRALY_HOME_URL, user) HtmlParser.get_books(html, RentalBooks())
def test_basic(self): books = RentalBooks([]) books.append(RentalBook("test1", "2017/01/01", True, "hoge")) books.append(RentalBook("test2", "9999/01/02", True, "hoge")) assert books.len == 2
def __create_empty_books(cls, books_class_name): if books_class_name in {"RentalBooks"}: return RentalBooks() elif books_class_name == "ReservedBooks": return ReservedBooks()