Skip to content

Commit f557f73

Browse files
remyleoneLaure-di
authored andcommitted
chore: add support for vcr.py
1 parent 7033567 commit f557f73

File tree

7 files changed

+39
-4
lines changed

7 files changed

+39
-4
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@ jobs:
4141
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
4242
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
4343
SCW_DEFAULT_REGION: ${{ secrets.SCW_DEFAULT_REGION }}
44-
run: poetry run python -m unittest discover -s tests -v
45-
44+
run: poetry run pytest --record-mode=none

scaleway-async/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ ruff = ">=0.5.0,<0.12.9"
3232
mypy = "^1.5.1"
3333
ty = "^0.0.1a15"
3434
pyrefly = ">=0.24.2,<0.27.0"
35+
pytest = "^8.4.1"
36+
pytest-recording = "^0.13.4"
3537

3638
[build-system]
3739
requires = ["poetry-core"]

scaleway-core/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ruff = ">=0.5.0,<0.12.8"
3434
mypy = "^1.5.1"
3535
ty = "^0.0.1a15"
3636
pyrefly = ">=0.24.2,<0.27.0"
37+
pytest = "^8.4.1"
3738

3839
[build-system]
3940
requires = ["poetry-core"]

scaleway-core/scaleway_core/api.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
Params = Mapping[str, Any]
1616

17+
from requests.adapters import HTTPAdapter
18+
from urllib3.util import Retry
19+
20+
1721

1822
@dataclass
1923
class APILogger:
@@ -154,6 +158,20 @@ def _request(
154158

155159
logger = APILogger(self._log, self.client._increment_request_count())
156160

161+
# define the retry strategy
162+
retry_strategy = Retry(
163+
total=3, # maximum number of retries
164+
status_forcelist=[
165+
500,
166+
], # the HTTP status codes to retry on
167+
)
168+
169+
# create an HTTP adapter with the retry strategy and mount it to the session
170+
adapter = HTTPAdapter(max_retries=retry_strategy)
171+
# create a new session object
172+
session = requests.Session()
173+
session.mount("https://", adapter)
174+
157175
logger.log_request(
158176
method=method,
159177
url=url,
@@ -163,7 +181,7 @@ def _request(
163181
if isinstance(raw_body, bytes)
164182
else raw_body,
165183
)
166-
response = requests.request(
184+
response = session.request(
167185
method=method,
168186
url=url,
169187
params=request_params,

scaleway/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ ruff = ">=0.5.0,<0.12.9"
3333
mypy = "^1.5.1"
3434
ty = "^0.0.1a15"
3535
pyrefly = ">=0.24.2,<0.27.0"
36+
pytest = "^8.4.1"
37+
pytest-recording = "^0.13.4"
3638

3739
[build-system]
3840
requires = ["poetry-core"]

scaleway/tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pytest
2+
3+
4+
@pytest.fixture(scope="session")
5+
def vcr_config():
6+
return {
7+
# Replace the Authorization request header with "DUMMY" in cassettes
8+
"filter_headers": ["x-auth-token"],
9+
}

scaleway/tests/test_vpc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import unittest
2+
3+
import pytest
4+
from vcr.unittest import VCRTestCase
25
from scaleway.vpc.v2 import VpcV2API
36
from scaleway_core.api import ScalewayException
47
from scaleway_core.client import Client
@@ -10,7 +13,8 @@
1013
created_vpc_count = 1
1114

1215

13-
class TestScalewayVPCV2(unittest.TestCase):
16+
@pytest.mark.vcr()
17+
class TestScalewayVPCV2(VCRTestCase):
1418
@classmethod
1519
def setUpClass(self):
1620
self.client = Client.from_config_file_and_env()

0 commit comments

Comments
 (0)