Skip to content

Commit

Permalink
fix(tests): Expect tests to fail if GH API limit reached
Browse files Browse the repository at this point in the history
A bit of a hack...
  • Loading branch information
alexpovel committed Sep 3, 2022
1 parent 5b44cda commit b6c97b5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pydeps = "^1.10.18"
pytest-cov = "^3.0.0"
pytest-aiohttp = "^1.0.4"
pytest-rerunfailures = "^10.2"
requests = "^2.28.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
21 changes: 21 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
import os
from pathlib import Path

import pytest
import requests

TESTS_DIR = Path(__file__).parent
DATA_DIR = TESTS_DIR / "test_data"
RESUMES_DIR = DATA_DIR / "resumes"
RESUMES = {p.name: p for p in RESUMES_DIR.iterdir()}

GH_TOKEN = os.environ.get("GH_TOKEN", None)

# Probably a terrible idea to do IO using the GH API in unit tests, but it does test the
# full thing instead of just some mock.
headers = {
"Accept": "application/vnd.github+json",
"User-Agent": "ancv-pytest",
}
if GH_TOKEN is not None:
headers["Authorization"] = f"Bearer {GH_TOKEN}"

resp = requests.get(
"https://api.github.com/rate_limit",
headers=headers,
)
gh_rate_limited = pytest.mark.xfail(
condition=resp.json()["resources"]["core"]["remaining"] == 0,
reason="GitHub API rate limit reached. If you haven't already, set the 'GH_TOKEN' env var to a PAT.",
)
3 changes: 2 additions & 1 deletion tests/web/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ancv.reflection import METADATA
from ancv.timing import Stopwatch
from ancv.web.client import get_resume
from tests import GH_TOKEN
from tests import GH_TOKEN, gh_rate_limited


@pytest.fixture(scope="function")
Expand Down Expand Up @@ -68,6 +68,7 @@ async def gh_api(client_session):
],
)
@pytest.mark.asyncio
@gh_rate_limited
async def test_get_resume_validations(
username: str,
client_session: aiohttp.ClientSession,
Expand Down
3 changes: 3 additions & 0 deletions tests/web/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from aiohttp.web import Application

from ancv.web.server import server_timing_header
from tests import gh_rate_limited


@pytest.mark.filterwarnings("ignore:Request.message is deprecated") # No idea...
Expand Down Expand Up @@ -84,6 +85,7 @@ async def test_root_endpoint(
),
],
)
@gh_rate_limited
async def test_username_endpoint(
self,
username: str,
Expand All @@ -107,6 +109,7 @@ async def test_username_endpoint(
("alexpovel", "Experience"),
],
)
@gh_rate_limited
async def test_return_content(
self,
username: str,
Expand Down

0 comments on commit b6c97b5

Please sign in to comment.