def test_creator_metadata(fpath, lipsum_item): metadata = { # kiwix-mandatory "Name": "wikipedia_fr_football", "Title": "English Wikipedia", "Creator": "English speaking Wikipedia contributors", "Publisher": "Wikipedia user Foobar", "Date": "2009-11-21", "Description": "All articles (without images) from the english Wikipedia", "Language": "eng", # optional "Longdescription": ("This ZIM file contains all articles (without images) " "from the english Wikipedia by 2009-11-10." " The topics are ..."), "Licence": "CC-BY", "Tags": "wikipedia;_category:wikipedia;_pictures:no;" "_videos:no;_details:yes;_ftindex:yes", "Flavour": "nopic", "Source": "https://en.wikipedia.org/", "Counter": "image/jpeg=5;image/gif=3;image/png=2", "Scraper": "sotoki 1.2.3", } # ensure we can't add if not started c = Creator(fpath) with pytest.raises(RuntimeError, match="not started"): key = next(iter(metadata.keys())) c.add_metadata(key, metadata.get(key)) del c with Creator(fpath) as c: c.add_item(lipsum_item) for name, value in metadata.items(): if name == "Date": continue c.add_metadata(name, value) mdate = datetime.date( *[int(x) for x in metadata.get("Date").split("-")]) c.add_metadata("Date", mdate) zim = Archive(fpath) for name, value in metadata.items(): assert zim.get_metadata(name).decode("UTF-8") == value
def test_creator_nocontext(fpath, lipsum_item): """ensure we can use the creator linearily""" creator = Creator(fpath) exc_type, exc_val, exc_tb = None, None, None creator.__enter__() creator.add_metadata("Name", "name") creator.add_item(lipsum_item) with pytest.raises(RuntimeError): creator.config_verbose(True) creator.__exit__(exc_type, exc_val, exc_tb) # now with an exception creator = Creator(fpath) creator.__enter__() creator.add_item(lipsum_item) try: creator.add_redirection("A", HOME_PATH) except Exception: exc_type, exc_val, exc_tb = sys.exc_info() with pytest.raises(TypeError): raise creator.__exit__(exc_type, exc_val, exc_tb)