-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WEB: Better management of releases (#56207)
- Loading branch information
Showing
3 changed files
with
105 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from unittest.mock import ( | ||
mock_open, | ||
patch, | ||
) | ||
|
||
import pytest | ||
import requests | ||
|
||
from web.pandas_web import Preprocessors | ||
|
||
|
||
class MockResponse: | ||
def __init__(self, status_code: int, response: dict): | ||
self.status_code = status_code | ||
self._resp = response | ||
|
||
def json(self): | ||
return self._resp | ||
|
||
@staticmethod | ||
def raise_for_status(): | ||
return | ||
|
||
|
||
@pytest.fixture | ||
def context() -> dict: | ||
return { | ||
"main": {"github_repo_url": "pandas-dev/pandas"}, | ||
"target_path": "test_target_path", | ||
} | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def mock_response(monkeypatch, request): | ||
def mocked_resp(*args, **kwargs): | ||
status_code, response = request.param | ||
return MockResponse(status_code, response) | ||
|
||
monkeypatch.setattr(requests, "get", mocked_resp) | ||
|
||
|
||
_releases_list = [ | ||
{ | ||
"prerelease": False, | ||
"published_at": "2024-01-19T03:34:05Z", | ||
"tag_name": "v1.5.6", | ||
"assets": None, | ||
}, | ||
{ | ||
"prerelease": False, | ||
"published_at": "2023-11-10T19:07:37Z", | ||
"tag_name": "v2.1.3", | ||
"assets": None, | ||
}, | ||
{ | ||
"prerelease": False, | ||
"published_at": "2023-08-30T13:24:32Z", | ||
"tag_name": "v2.1.0", | ||
"assets": None, | ||
}, | ||
{ | ||
"prerelease": False, | ||
"published_at": "2023-04-30T13:24:32Z", | ||
"tag_name": "v2.0.0", | ||
"assets": None, | ||
}, | ||
{ | ||
"prerelease": True, | ||
"published_at": "2023-01-19T03:34:05Z", | ||
"tag_name": "v1.5.3xd", | ||
"assets": None, | ||
}, | ||
{ | ||
"prerelease": False, | ||
"published_at": "2027-01-19T03:34:05Z", | ||
"tag_name": "v10.0.1", | ||
"assets": None, | ||
}, | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("mock_response", [(200, _releases_list)], indirect=True) | ||
def test_web_preprocessor_creates_releases(mock_response, context): | ||
m = mock_open() | ||
with patch("builtins.open", m): | ||
context = Preprocessors.home_add_releases(context) | ||
release_versions = [release["name"] for release in context["releases"]] | ||
assert release_versions == ["10.0.1", "2.1.3", "2.0.0", "1.5.6"] |