-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DAG-2865 binary vs nonbinary artifact stream handling with unit test (#…
…155)
- Loading branch information
1 parent
f995b5b
commit 31839e4
Showing
8 changed files
with
141 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "evergreen.py" | ||
version = "3.6.14" | ||
version = "3.6.15" | ||
description = "Python client for the Evergreen API" | ||
authors = [ | ||
"Dev Prod DAG <[email protected]>", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "mongodb-arm64.tar.gz", | ||
"url": "https://mciuploads.s3.amazonaws.com/dsi/sys_perf_7e36a45d31a6d5f2c1edcd1a4f009a86bd209210/7e36a45d31a6d5f2c1edcd1a4f009a86bd209210/linux/mongodb-arm64-sys_perf_7e36a45d31a6d5f2c1edcd1a4f009a86bd209210.tar.gz", | ||
"visibility": "", | ||
"ignore_for_fetch": false, | ||
"content_type": "application/x-gzip" | ||
} |
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,7 @@ | ||
{ | ||
"name": "Documentation", | ||
"url": "https://mciuploads.s3.amazonaws.com/dsi/compile-amazon-linux2-arm64/7e36a45d31a6d5f2c1edcd1a4f009a86bd209210/sys_perf_compile_amazon_linux2_arm64_compile_7e36a45d31a6d5f2c1edcd1a4f009a86bd209210_23_09_20_15_55_48/sys_perf_7e36a45d31a6d5f2c1edcd1a4f009a86bd209210/logs/compile-sys_perf_compile_amazon_linux2_arm64_7e36a45d31a6d5f2c1edcd1a4f009a86bd209210_23_09_20_15_55_48-index.html", | ||
"visibility": "", | ||
"ignore_for_fetch": false, | ||
"content_type": "text/html" | ||
} |
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,64 @@ | ||
"""Unit tests for Artifact class streams in src/evergreen/task.py""" | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from requests.models import Response | ||
|
||
from evergreen.task import Artifact | ||
|
||
RESPONSE_DATA = [b"data\nwith\nnew\nlines", b"second\nchunck\nof\ndata"] | ||
|
||
|
||
@pytest.fixture | ||
def mocked_res(): | ||
mock_res = MagicMock(spec=Response) | ||
mock_res.request = MagicMock() | ||
mock_res.__enter__.return_value = mock_res | ||
mock_res.request.url = "url" | ||
mock_res.iter_content.return_value = iter(RESPONSE_DATA) | ||
mock_res.iter_lines.return_value = iter(RESPONSE_DATA) | ||
return mock_res | ||
|
||
|
||
class TestArtifactStream(object): | ||
def test_binary_artifact_stream(self, sample_binary_artifact, mocked_api, mocked_res): | ||
mocked_api.session.get = MagicMock(return_value=mocked_res) | ||
artifact = Artifact(sample_binary_artifact, mocked_api) | ||
|
||
stream_output = list(artifact.stream()) | ||
mocked_res.iter_content.assert_called_once() | ||
mocked_res.iter_lines.assert_not_called() | ||
assert stream_output == RESPONSE_DATA | ||
|
||
def test_binary_artifact_stream_with_params( | ||
self, sample_binary_artifact, mocked_api, mocked_res | ||
): | ||
mocked_api.session.get = MagicMock(return_value=mocked_res) | ||
artifact = Artifact(sample_binary_artifact, mocked_api) | ||
|
||
chunk_size = 2 | ||
|
||
stream_output = list(artifact.stream(decode_unicode=False, chunk_size=chunk_size)) | ||
mocked_res.iter_content.assert_called_once_with(decode_unicode=False, chunk_size=chunk_size) | ||
mocked_res.iter_lines.assert_not_called() | ||
assert stream_output == RESPONSE_DATA | ||
|
||
def test_nonbinary_artifact_stream(self, sample_nonbinary_artifact, mocked_api, mocked_res): | ||
mocked_api.session.get = MagicMock(return_value=mocked_res) | ||
artifact = Artifact(sample_nonbinary_artifact, mocked_api) | ||
|
||
stream_output = list(artifact.stream()) | ||
mocked_res.iter_lines.assert_called_once() | ||
mocked_res.iter_content.assert_not_called() | ||
assert stream_output == RESPONSE_DATA | ||
|
||
def test_artifact_stream_override(self, sample_binary_artifact, mocked_api, mocked_res): | ||
mocked_api.session.get = MagicMock(return_value=mocked_res) | ||
artifact = Artifact(sample_binary_artifact, mocked_api) | ||
artifact._is_binary = MagicMock() | ||
|
||
stream_output = list(artifact.stream(is_binary=False)) | ||
artifact._is_binary.assert_not_called() | ||
mocked_res.iter_lines.assert_called_once() | ||
mocked_res.iter_content.assert_not_called() | ||
assert stream_output == RESPONSE_DATA |