|
| 1 | +import base64 |
1 | 2 | import datetime |
2 | 3 | import logging |
3 | 4 | from pathlib import Path |
@@ -547,6 +548,72 @@ def test_iter_notes_single_with_resource(fs): |
547 | 548 | assert notes[0].resource_by_md5("000") is None |
548 | 549 |
|
549 | 550 |
|
| 551 | +def test_iter_notes_single_with_huge_resource(fs, caplog): |
| 552 | + test_enex_head = b"""<?xml version="1.0" encoding="UTF-8"?> |
| 553 | + <!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export4.dtd"> |
| 554 | + <en-export export-date="20211218T085932Z" application="Evernote" version="10.25.6"> |
| 555 | + <note> |
| 556 | + <title>test1</title> |
| 557 | + <created>20211118T085332Z</created> |
| 558 | + <updated>20211118T085920Z</updated> |
| 559 | + <note-attributes> |
| 560 | + </note-attributes> |
| 561 | + <content>test</content> |
| 562 | + <resource> |
| 563 | + <data encoding="base64"> |
| 564 | + """ |
| 565 | + test_enex_tail = b""" |
| 566 | + </data> |
| 567 | + <mime>image/gif</mime> |
| 568 | + <resource-attributes> |
| 569 | + <file-name>smallest.gif</file-name> |
| 570 | + </resource-attributes> |
| 571 | + </resource> |
| 572 | + </note> |
| 573 | + </en-export> |
| 574 | + """ |
| 575 | + test_enex_file = fs.create_file("test.enex", contents=test_enex_head) |
| 576 | + |
| 577 | + # 10 MB |
| 578 | + big_binary = b"\x00" * 10 * 1024 * 1024 |
| 579 | + big_binary_hash = "f1c9645dbc14efddc7d8a322685f26eb" |
| 580 | + |
| 581 | + with Path("test.enex").open("ab+") as f: |
| 582 | + f.write(base64.b64encode(big_binary)) |
| 583 | + f.write(test_enex_tail) |
| 584 | + |
| 585 | + with caplog.at_level(logging.WARNING, logger="enex2notion"): |
| 586 | + notes_count = count_notes(Path("test.enex")) |
| 587 | + |
| 588 | + notes = list(iter_notes(Path("test.enex"))) |
| 589 | + |
| 590 | + expected_resource = EvernoteResource( |
| 591 | + data_bin=big_binary, |
| 592 | + size=len(big_binary), |
| 593 | + md5=big_binary_hash, |
| 594 | + mime="image/gif", |
| 595 | + file_name="smallest.gif", |
| 596 | + ) |
| 597 | + |
| 598 | + assert caplog.text == "" |
| 599 | + assert notes_count == 1 |
| 600 | + assert notes == [ |
| 601 | + EvernoteNote( |
| 602 | + title="test1", |
| 603 | + created=datetime.datetime(2021, 11, 18, 8, 53, 32, tzinfo=tzutc()), |
| 604 | + updated=datetime.datetime(2021, 11, 18, 8, 59, 20, tzinfo=tzutc()), |
| 605 | + content="test", |
| 606 | + tags=[], |
| 607 | + author="", |
| 608 | + url="", |
| 609 | + is_webclip=False, |
| 610 | + resources=[expected_resource], |
| 611 | + ), |
| 612 | + ] |
| 613 | + assert notes[0].resource_by_md5(big_binary_hash) == expected_resource |
| 614 | + assert notes[0].resource_by_md5("000") is None |
| 615 | + |
| 616 | + |
550 | 617 | def test_iter_notes_single_with_noext_resource(fs): |
551 | 618 | test_enex = """<?xml version="1.0" encoding="UTF-8"?> |
552 | 619 | <!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export4.dtd"> |
|
0 commit comments