def test_categories_with_misc(): # create several categories, but leave at lease one (1) view not in any # category. categories = { "Employees": ["listEmployees", "topSalesmen"], "Customers": ["topCustomer"], } report = Report(paths={ "database": TEST_PATH, "report_dir": "." }, categories=categories) rendered = report.render() for v, html in rendered.items(): soup = BeautifulSoup(html, features="html.parser") buttons = soup.find_all("button", class_="dropbtn theme-d5 hover-theme") # compare the length of rendered categories and input categories. The # rendered categories should be one more than the input categories # since it will have the automatically added Misc category assert ( len(categories) == len(buttons) - 1), "number of rendered categories does not match input categories" for category, button in zip(categories, buttons): assert (category == button.text ), "input category does not match rendered category"
def test_titles(db_connection, views): report = Report( paths={"database": TEST_PATH}, titles={view: view.upper() for view in views}, ) rendered = report.render() for view, html in rendered.items(): soup = BeautifulSoup(html, features="html.parser") title = soup.find("title") assert title.text == view.upper(), "title does match expected value"
def test_captions(db_connection, views): report = Report( paths={"database": TEST_PATH}, captions={view: f"caption for view {view}" for view in views}, ) rendered = report.render() for view, html in rendered.items(): soup = BeautifulSoup(html, features="html.parser") caption = soup.find("caption") assert (caption.text == f"caption for view {view}" ), "caption does match expected value"
def test_descriptions(db_connection, views): description = "description for view {}" report = Report( paths={"database": TEST_PATH}, descriptions={view: description.format(view) for view in views}, ) rendered = report.render() for view, html in rendered.items(): soup = BeautifulSoup(html, features="html.parser") description_tag = soup.find("p", class_="description") assert description_tag.text == description.format( view), "descriptions do not match"
def test_init_with_both_layout_path_and_kwargs(): with pytest.raises(ValueError): # only the path to the layout file is given as a positional argument. # The remaining parameters are parameters from the layout file given as # keyword arguments. If any keyword arguments are given, the path to # the layout file must be None Report("layout_path.json", path="any_keyword_argument_db.db")
def test_init_with_non_existent_layout(): with pytest.raises(FileNotFoundError): Report("layout_that_does_not_exist.json")
def test_database_connection(db_connection): with pytest.raises(FileNotFoundError): Report(paths={"database": "database_that_does_not_exist.db"})