Esempio n. 1
0
 def test_persist(self):
     authors = Authors()
     authors.set_mappings({"Foo": "Bar"})
     authors.set_author({"Foo Bar": {"birth": 1234}})
     authors.persist()
     base_path = Path(__file__).parent.joinpath("mock_data")
     with open(str(base_path.joinpath("authors_mapping.json")),
               mode="r",
               encoding="utf8") as mapping:
         compare(True, "\"Foo\": \"Bar\"" in mapping.read())
     with open(str(base_path.joinpath("authors.json")),
               mode="r",
               encoding="utf8") as authors:
         compare(
             True, "  \"Foo Bar\": {\n    \"birth\": 1234\n  }"
             in authors.read())
Esempio n. 2
0
    def test_set_author(self):
        authors = Authors()

        author = authors.get_author_by_mapping("Abel", "I,1")
        compare("Herman Abel", author[0].name)
        compare(1998, author[0].death)
        compare(None, author[0].birth)
        authors.set_author({"Herman Abel": {"birth": 1900, "death": 1990}})
        author = authors.get_author_by_mapping("Abel", "I,1")
        compare("Herman Abel", author[0].name)
        compare(1990, author[0].death)
        compare(1900, author[0].birth)

        authors.set_author({"Abel2": {"birth": 1950}})
        author = authors._authors["Abel2"]
        compare("Abel2", author.name)
        compare(1950, author.birth)