Skip to content

Commit

Permalink
add legifrance credentials to ci pytest runs (#87)
Browse files Browse the repository at this point in the history
* add legifrance credentials to ci pytest runs

* improve _get_legifrance_credentials
  • Loading branch information
rprimet authored Feb 17, 2024
1 parent 3778f0f commit e00d1e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ jobs:
run: tox r --skip-pkg-install
env:
PYTEST_ADDOPTS: "-vv --durations=10"
CATLEG_LF_CLIENT_ID: ${{ secrets.CATLEG_LF_CLIENT_ID }}
CATLEG_LF_CLIENT_SECRET: ${{ secrets.CATLEG_LF_CLIENT_SECRET }}
12 changes: 12 additions & 0 deletions src/catleg/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import functools
import logging
import re
from collections.abc import Iterable
from datetime import date, datetime, timedelta, timezone
from typing import Protocol
Expand All @@ -28,6 +29,10 @@ def _lf_timestamp_to_datetime(ts):
# Legifrance uses 2999-01-01 to mark a non-expired or non-expiring text
END_OF_TIME = _lf_timestamp_to_datetime(32472144000000)

LF_TOKEN_REGEX = re.compile(
r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
)


class Backend(Protocol):
async def article(self, id_or_url: str) -> Article | None:
Expand Down Expand Up @@ -208,6 +213,13 @@ def to_markdown(self) -> str:
def _get_legifrance_credentials(*, raise_if_missing=True):
client_id = settings.get("lf_client_id")
client_secret = settings.get("lf_client_secret")

if not LF_TOKEN_REGEX.match(client_id):
client_id = None

if not LF_TOKEN_REGEX.match(client_secret):
client_secret = None

if raise_if_missing:
if (client_id is None) or (client_secret is None):
raise ValueError(
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ deps =
pytest-sugar
commands =
pytest {posargs:tests}
passenv =
CATLEG_LF_CLIENT_SECRET
CATLEG_LF_CLIENT_ID

[testenv:type]
description = run type checks
Expand Down

0 comments on commit e00d1e8

Please sign in to comment.