Test re-import of exported note

This commit is contained in:
Kovid Goyal 2023-09-17 13:34:39 +05:30
parent d3ae36a965
commit 0f76bf19f8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 2 deletions

View File

@ -58,8 +58,8 @@ def import_note(shtml: str | bytes, basedir: str, add_resource) -> dict:
img.set('data-pre-import-src', src) img.set('data-pre-import-src', src)
if src.startswith('data:'): if src.startswith('data:'):
d = src.split(':', 1)[-1] d = src.split(':', 1)[-1]
menc, payload = d.partition(',') menc, payload = d.partition(',')[::2]
mt, enc = menc.partition(';') mt, enc = menc.partition(';')[::2]
if enc != 'base64': if enc != 'base64':
continue continue
try: try:

View File

@ -140,6 +140,17 @@ def test_cache_api(self: 'NotesTest'):
from html5_parser import parse from html5_parser import parse
root = parse(exported) root = parse(exported)
self.ae(root.xpath('//img/@data-filename'), ['r 1.png', 'r 2.png']) self.ae(root.xpath('//img/@data-filename'), ['r 1.png', 'r 2.png'])
cache.set_notes_for('authors', author_id, '')
with open(os.path.join(tdir, 'e.html'), 'wb') as f:
f.write(exported.encode('utf-8'))
cache.import_note('authors', author_id, f.name)
note_id = cache.import_note('authors', author_id, f.name)
self.assertGreater(note_id, 0)
self.assertIn('<p>test simple exim <img', cache.notes_for('authors', author_id))
res = set()
for x in cache.notes_resources_used_by('authors', author_id):
res.add(cache.get_notes_resource(x)['name'])
self.ae(res, {'r 1.png', 'r 2.png'})
def test_fts(self: 'NotesTest'): def test_fts(self: 'NotesTest'):