-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
lib/dl_file_uploader_lib/dl_file_uploader_lib/yadocuments_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import requests | ||
|
||
|
||
class YaDocumentsClient: | ||
headers = { | ||
"Content-Type": "application/json", | ||
"Accept": "application/json", | ||
} | ||
|
||
def get_spreadsheet_public(self, link): | ||
resp = requests.get( | ||
f"https://cloud-api.yandex.net/v1/disk/public/resources/download/?public_key={link}", | ||
headers=self.headers, | ||
) | ||
return resp.json()["href"] | ||
|
||
def get_spreadsheet_public_meta(self, link): | ||
resp = requests.get( | ||
f"https://cloud-api.yandex.net/v1/disk/public/resources/?public_key={link}", | ||
headers=self.headers, | ||
) | ||
return resp.json() | ||
|
||
def get_spreadsheet_private(self, path, token): | ||
headers_with_token = self._create_headers_with_token(token) | ||
resp = requests.get( | ||
f"https://cloud-api.yandex.net/v1/disk/resources/download/?path={path}", | ||
headers=headers_with_token, | ||
) | ||
return resp.json()["href"] | ||
|
||
def get_spreadsheet_private_meta(self, path, token): | ||
headers_with_token = self._create_headers_with_token(token) | ||
resp = requests.get( | ||
f"https://cloud-api.yandex.net/v1/disk/resources/?path={path}", | ||
headers=headers_with_token, | ||
) | ||
return resp.json() | ||
|
||
def _create_headers_with_token(self, token: str): | ||
headers_with_token = self.headers.copy() | ||
headers_with_token.update({"Authorization": "OAuth " + token}) | ||
return headers_with_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
lib/dl_file_uploader_worker_lib/dl_file_uploader_worker_lib_tests/ext/test_yadocuments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
|
||
from dl_constants.enums import FileProcessingStatus | ||
from dl_file_uploader_lib.enums import FileType | ||
from dl_file_uploader_lib.redis_model.models import ( | ||
DataFile, | ||
YaDocumentsUserSourceProperties, | ||
) | ||
from dl_file_uploader_task_interface.tasks import DownloadYaDocumentsTask | ||
from dl_task_processor.state import wait_task | ||
from dl_testing.s3_utils import s3_file_exists | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_download_yadocs_task( | ||
task_processor_client, | ||
task_state, | ||
s3_client, | ||
redis_model_manager, | ||
s3_tmp_bucket, | ||
): | ||
df = DataFile( | ||
filename="", | ||
file_type=FileType.yadocuments, | ||
manager=redis_model_manager, | ||
status=FileProcessingStatus.in_progress, | ||
user_source_properties=YaDocumentsUserSourceProperties(public_link="https://disk.yandex.lt/i/OyzdmFI0MUEEgA"), | ||
) | ||
await df.save() | ||
|
||
task = await task_processor_client.schedule(DownloadYaDocumentsTask(file_id=df.id)) | ||
result = await wait_task(task, task_state) | ||
|
||
assert result[-1] == "success" | ||
assert await s3_file_exists(key=df.s3_key, bucket=s3_tmp_bucket, s3_client=s3_client) |