diff --git a/pyproject.toml b/pyproject.toml index 6f9724a..827f3f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,6 +83,9 @@ exclude = [ [tool.hatch.build.targets.wheel] packages = ["src/fymail"] +[tool.pytest.ini_options] +asyncio_mode = "auto" + [tool.coverage.run] source_pkgs = ["fymail"] branch = true diff --git a/src/fymail/providers/base/rule_base.py b/src/fymail/providers/base/rule_base.py index a56da2c..55d1700 100644 --- a/src/fymail/providers/base/rule_base.py +++ b/src/fymail/providers/base/rule_base.py @@ -27,6 +27,7 @@ class RuleBase(metaclass=RuleBaseMeta): name = None path = None headers = None + check_resp: bool = True def __init__(self, base_url: str): self.base_url = base_url @@ -44,7 +45,8 @@ async def run(self, session: ClientSession, iden: str, params: dict | None = Non if self.headers: session.headers.update(self.headers) async with session.get(self.build_url(iden), params=params) as response: - response.raise_for_status() + if self.check_resp: + response.raise_for_status() return await self.parse(response) @abstractmethod diff --git a/src/fymail/providers/github/rules/profile.py b/src/fymail/providers/github/rules/profile.py index 68fd632..873419f 100644 --- a/src/fymail/providers/github/rules/profile.py +++ b/src/fymail/providers/github/rules/profile.py @@ -21,6 +21,7 @@ class Profile(RuleBase): name = "GH10" path = "repos" + check_resp: bool = False def build_url(self, iden: str) -> str: return f"{super().build_url(iden)}/{iden}/readme" diff --git a/tests/integration/test_github.py b/tests/integration/test_github.py index e3443ee..53cdb80 100644 --- a/tests/integration/test_github.py +++ b/tests/integration/test_github.py @@ -7,6 +7,8 @@ from fymail import FyMail +logger = logging.getLogger(__name__) + logging.basicConfig() logging.getLogger().setLevel(logging.INFO) @@ -20,20 +22,50 @@ @pytest.mark.parametrize( - ("iden", "rule"), + ("idens", "rule"), [ - ("zhongjiajie", ""), - ("pnasrat", ""), - ("pfmoore", ""), - ("piwai", ""), + ( + ( + "zhongjiajie", + "freddrake", + "vstinner", + ), + "", + ), + ( + ( + "pnasrat", + "eladkal", + ), + "", + ), + ( + ( + "pfmoore", + "piwai", + "loewis", + ), + "", + ), + (("dstandish", "kantandane", "GeumBinLee", "svlandeg"), ""), ], ) @pytest.mark.asyncio -async def test_gh_rules_users(iden, rule, caplog): +async def test_gh_rules_users(idens, rule, caplog): + """ + Test GitHub rules for users, pass at least one of iden contain specific rule message + """ with caplog.at_level(logging.INFO): - email = await fymail.get(iden=iden, provider=provider, auth=token) - assert email is not None - assert rule in caplog.text + for iden in idens: + email = await fymail.get(iden=iden, provider=provider, auth=token) + assert email is not None + # pass at least one of iden contain specific rule message + try: + assert rule is not caplog.text + break + except AssertionError: + logger.info("Attempt %s unable get expect rule %s with message: %s", iden, rule, caplog.text) + continue @pytest.mark.parametrize(