Exemplo n.º 1
0
def test_change(fs):
    path = str(Path(__file__).parent.joinpath('test.pdf'))
    fs.add_real_file(path, read_only=False)
    acc = PDFAccessor(path)
    acc.edit(SetTitleCmd(path, 'Why Donuts Are Great'))
    acc.edit(
        SetCreatedCmd(path,
                      datetime.fromisoformat('1999-02-04T06:08:10+00:00')))
    acc.edit(AddTagCmd(path, 'tag3'))
    acc.edit(DelTagCmd(path, 'tag2'))
    assert acc.save()
    with open(path, 'rb') as file:
        pdf = PdfFileReader(file)
        assert 'I like donuts' in pdf.getPage(0).extractText()
        # Make sure we didn't destroy preexisting metadata
        assert pdf.getDocumentInfo()['/Creator'] == 'Pages'
    info = PDFAccessor(path).info()
    assert info.title == 'Why Donuts Are Great'
    assert info.created == datetime.fromisoformat('1999-02-04T06:08:10+00:00')
    assert info.tags == {'tag1', 'tag3'}
Exemplo n.º 2
0
def test_change_metadata_tags(fs):
    doc = """---
keywords:
- one
- two
---

text"""
    expected = """---
keywords:
- three
- two
---

text"""
    path = '/fakenotes/test.md'
    fs.create_file(path, contents=doc)
    acc = MarkdownAccessor(path)
    acc.edit(AddTagCmd(path, 'THREE'))
    acc.edit(DelTagCmd(path, 'ONE'))
    assert acc.save()
    assert Path(path).read_text() == expected
Exemplo n.º 3
0
 def add_tag(self, path: str, tag: str) -> None:
     """Convenience method equivalent to calling change with one :class`notesdir.models.AddTagCmd`"""
     self.change([AddTagCmd(path, tag)])