Skip to content

Commit

Permalink
fix: prevent network error when uploading files
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Jun 3, 2022
1 parent 102fbcf commit c6bacc0
Show file tree
Hide file tree
Showing 12 changed files with 586 additions and 462 deletions.
14 changes: 12 additions & 2 deletions enex2notion/enex_uploader_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ def _upload_file(new_block, resource: EvernoteResource):
set size and title for FileBlock
"""

post_data = {
"bucket": "secure",
"name": resource.file_name,
"contentType": resource.mime,
"record": {
"table": "block",
"id": new_block.id,
"spaceId": new_block.space_info["spaceId"],
},
}

upload_data = new_block._client.post( # noqa: WPS437
"getUploadFileUrl",
{"bucket": "secure", "name": resource.file_name, "contentType": resource.mime},
"getUploadFileUrl", post_data
).json()

response = requests.put(
Expand Down
2 changes: 1 addition & 1 deletion tests/cassettes/test_file_upload.uuid4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["dd54a653-5d63-4710-b3ff-49612311a353", "34a215ad-7cdc-408c-b1fb-8a0f119f512e"]
["7d56ee74-f9da-4eae-9129-c7cc364c697a", "4f1270e8-24f5-4441-ab60-34d28f616b7f"]
170 changes: 99 additions & 71 deletions tests/cassettes/test_file_upload.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/cassettes/test_resized_image.uuid4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["cbef4b79-a97e-4c74-9581-843975a4e8ba", "1912ae9c-ecfc-49c1-8318-9efbda74662e"]
["cef8974c-b816-4287-b610-cbbfea35d44b", "abeaa3f7-59f7-4168-a7b4-afe727a0336c"]
154 changes: 91 additions & 63 deletions tests/cassettes/test_resized_image.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/cassettes/test_resized_image_only_width.uuid4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["4e1fd6af-c8ef-4c7a-bd04-59e3e10e049b", "0dcf5b85-f627-4898-af9c-4bd06b3c76e6"]
["7cda1c68-8f89-46ad-bf2e-65edd2140517", "b0534afc-9a13-4a72-bd84-dce8d213a79e"]
154 changes: 91 additions & 63 deletions tests/cassettes/test_resized_image_only_width.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/cassettes/test_upload_note_db.uuid4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["7e3fbf0a-f976-4c0b-8802-6ca00ea7b1ba", "f9b2d177-eba7-4548-a11b-bfd6493e058c", "55d28a90-be0e-4bf4-89c3-b0bed18dfa16", "94314b26-0014-4c95-b84d-546daf1bd5bd", "411932de-e3d0-4ac0-9833-84cd1115b597", "06f9a6fa-1b33-4520-b0a0-fab449e15f1b"]
["30e94935-9e55-49ac-9bdd-6c5f169cfe51", "abdadafb-d3b2-4471-b118-88cf06450b2c", "a46e4e3f-1fa4-49a1-85aa-a8833cccf57e", "402e3a54-2e64-43e6-b05a-ecaf2f186891", "073b3f56-97cc-44bd-8702-461ff37b8f13", "1cd0484f-a55b-4ae0-91c3-fa370e410a4f"]
310 changes: 155 additions & 155 deletions tests/cassettes/test_upload_note_db.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/cassettes/test_upload_note_with_file.uuid4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["f06bd880-a490-4293-9fea-7b261577fb43", "1bd49f77-8152-4a9d-963c-b78c23b96a52", "905fe845-b976-4885-888f-579b73e79219"]
["4b836bd4-3f19-4cd4-a51a-b14545033770", "e24f098f-c6c3-4524-be61-2480e4145f5e", "b94d5b24-f798-4b65-b7d4-76d3f95818a2"]
230 changes: 129 additions & 101 deletions tests/cassettes/test_upload_note_with_file.yaml

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions tests/test_enex_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ def test_upload_note_db(notion_test_page, parse_rules):

assert test_row.title == "test1"

assert test_row.created == datetime(2021, 11, 18, 0, 0, 0)
assert test_row.updated == datetime(2021, 11, 19, 0, 0, 0)
assert test_row.columns.created == datetime(2021, 11, 18, 0, 0, 0)
assert test_row.columns.updated == datetime(2021, 11, 19, 0, 0, 0)
assert test_row.columns.tags == [""]
assert test_row.columns.url == ""

assert len(test_row.children) == 1
assert isinstance(test_row.children[0], TextBlock)
Expand Down

0 comments on commit c6bacc0

Please sign in to comment.