示例#1
0
    def test_from_yaml(self):
        yamlstring = (
            "title: The lord of the rings\n"
            "author: Tolkien\n"
        )
        yamlfile = tempfile.mktemp()
        epub = create_random_epub()
        with open(yamlfile, 'w+') as fd:
            fd.write(yamlstring)

        self.assertTrue(get_document_extension(epub) == 'epub')

        result = self.invoke([
            epub, '--from yaml', yamlfile
        ])

        db = papis.database.get()
        docs = db.query_dict({"author": "Tolkien"})
        self.assertTrue(len(docs) == 1)
        doc = docs[0]
        self.assertTrue(len(doc.get_files()) == 1)

        # This is the original epub file, it should still be there
        self.assertTrue(os.path.exists(epub))
        # and it should still be an epub
        self.assertTrue(get_document_extension(epub) == 'epub')
        self.assertTrue(get_document_extension(doc.get_files()[0]) == 'epub')
示例#2
0
def test_extension():
    docs = [
        [tests.create_random_pdf(), "pdf"],
        [tests.create_random_pdf(), "pdf"],
        [tests.create_random_file(), "data"],
        [tests.create_random_epub(), "epub"],
        [tests.create_random_file(suffix='.yaml'), "yaml"],
        [tests.create_random_file(suffix='.text'), "text"],
    ]
    for d in docs:
        assert(get_document_extension(d[0]) == d[1])