def insert(self): if self.validate(): extensions.set_max_id(extensions.get_max_id() + 1) self.id = extensions.get_max_id() self.date = datetime.now() data = { "type": self.type, "desc": self.desc, "title": str(self.title), "date": self.date.strftime("%x").replace("/", "-"), "tags": self.tags, "id": self.id, "path": self.path } if self.type == "bookmarks" or self.type == "pocket_bookmarks": data["url"] = self.url # convert to markdown file dataobj = frontmatter.Post(self.content) dataobj.metadata = data self.fullpath = create( frontmatter.dumps(dataobj), str(self.id) + "-" + dataobj["date"] + "-" + dataobj["title"], path=self.path, ) add_to_index(current_app.config['INDEX_NAME'], self) return self.id return False
def insert(self): if self.validate(): self.id = extensions.get_max_id() data = { "type": self.type, "desc": self.desc, "title": str(self.title), "date": self.date.strftime("%x").replace("/", "-"), "tags": self.tags, "id": self.id, "path": self.path } if self.type == "bookmarks" or self.type == "pocket_bookmarks": data["url"] = self.url extensions.set_max_id(self.id + 1) # convert to markdown dataobj = frontmatter.Post(self.content) dataobj.metadata = data create(frontmatter.dumps(dataobj), str(self.id) + "-" + dataobj["date"] + "-" + dataobj["title"], path=self.path) add_to_index(Config.INDEX_NAME, self) return self.id return False
def test_new_note(test_app, note_fixture): """ Check that a new note is correctly saved into the filesystem with the right attributes and the right id. """ with test_app.app_context(): max_id = get_max_id() assert note_fixture.id == max_id saved_file = frontmatter.load(note_fixture.fullpath) for attr in attributes: assert getattr(note_fixture, attr) == saved_file[attr]
def test_bookmark_sanitization(test_app, client, mocked_responses, bookmark_fixture): """Tests bookmark contents are correctly saved and converted to proper Markdown""" with test_app.app_context(): assert bookmark_fixture.id == get_max_id() saved_file = frontmatter.load(bookmark_fixture.fullpath) for attr in attributes: assert getattr(bookmark_fixture, attr) == saved_file[attr] assert bookmark_fixture.url == saved_file["url"] # remove buggy newlines that interfere with checks: bookmark_fixture.content = bookmark_fixture.content.replace("\n", "") # test script is sanitized assert bookmark_fixture.content.find("<script>") == -1 # test relative urls in the HTML are remapped to an absolute urls assert bookmark_fixture.content.find("example.com/images/image1.png") != -1 assert bookmark_fixture.content.find( "example.com/testing-absolute-url") != -1