forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pandas_web.py
82 lines (67 loc) · 1.93 KB
/
test_pandas_web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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,
},
]
@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 = [str(release["name"]) for release in context["releases"]]
assert release_versions == ["2.1.3", "2.0.0", "1.5.6"]