From e141c51d02808926bfbc71681dda40ef2ee53542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Thu, 19 Oct 2023 11:04:59 -0600 Subject: [PATCH] fix: Ensure requests caching can be enabled (#199) * fix: Ensure requests caching can be enabled * Add job dependency --- .github/workflows/test.yml | 52 +++++++++++++++++++++++++++++++++++++- noxfile.py | 15 ++++++++++- pyproject.toml | 8 ++++++ requests_cache.config.json | 8 ++++++ tap_jotform/client.py | 7 +++++ tests/test_core.py | 11 +++++++- 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 requests_cache.config.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d003be..2c91e4a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,8 +27,53 @@ concurrency: cancel-in-progress: true jobs: + run: + runs-on: ubuntu-latest + env: + PIP_CONSTRAINT: .github/workflows/constraints.txt + FORCE_COLOR: "1" + NOXSESSION: run + NOXPYTHON: "3.11" + steps: + - name: Checkout code + uses: actions/checkout@v4.1.0 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v4.7.0 + with: + python-version: 3.11 + + - name: Install Poetry + run: | + pipx install poetry + pipx inject poetry poetry-dynamic-versioning[plugin] + poetry --version + poetry self show plugins + + - name: Install Nox + run: | + pipx install nox + pipx inject nox nox-poetry + nox --version + + - name: Run Nox + env: + TAP_JOTFORM_API_KEY: ${{ secrets.TAP_JOTFORM_API_KEY }} + TAP_JOTFORM_API_URL: "https://api.jotform.com" + run: | + nox + + - name: Upload request cache + uses: actions/upload-artifact@v3 + with: + name: requests-cache + path: http_cache.sqlite + tests: runs-on: ubuntu-latest + needs: run env: PIP_CONSTRAINT: .github/workflows/constraints.txt NOXSESSION: ${{ matrix.session }} @@ -37,7 +82,7 @@ jobs: strategy: matrix: include: - - {python-version: "3.10", session: "mypy"} + - {python-version: "3.11", session: "mypy"} - {python-version: "3.11", session: "tests"} - {python-version: "3.10", session: "tests"} - {python-version: "3.9", session: "tests"} @@ -72,6 +117,11 @@ jobs: pipx inject nox nox-poetry nox --version + - name: Download request cache + uses: actions/download-artifact@v3 + with: + name: requests-cache + - name: Run Nox env: TAP_JOTFORM_API_KEY: ${{ secrets.TAP_JOTFORM_API_KEY }} diff --git a/noxfile.py b/noxfile.py index 9acd23b..e5f653b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -22,7 +22,7 @@ tests_dir = "tests" python_versions = ["3.11", "3.10", "3.9", "3.8"] -main_python_version = "3.10" +main_python_version = "3.11" locations = src_dir, tests_dir, "noxfile.py" nox.options.sessions = ( "mypy", @@ -30,6 +30,19 @@ ) +@session(python=main_python_version) +def run(session: Session) -> None: + """Run the tap with request caching enabled.""" + session.install(".") + session.run( + "tap-jotform", + "--config", + "requests_cache.config.json", + "--config", + "ENV", + ) + + @session(python=python_versions) def mypy(session: Session) -> None: """Check types with mypy.""" diff --git a/pyproject.toml b/pyproject.toml index 5833883..3965726 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,9 @@ select = ["ALL"] src = ["tap_jotform", "tests", "noxfile.py"] target-version = "py38" +[tool.ruff.flake8-annotations] +allow-star-arg-any = true + [tool.ruff.isort] known-first-party = ["tap_jotform"] @@ -53,6 +56,11 @@ known-first-party = ["tap_jotform"] [tool.ruff.pydocstyle] convention = "google" +[tool.pytest.ini_options] +addopts = [ + "-vvv", +] + [tool.poetry-dynamic-versioning] enable = true format-jinja = """ diff --git a/requests_cache.config.json b/requests_cache.config.json new file mode 100644 index 0000000..422a5dc --- /dev/null +++ b/requests_cache.config.json @@ -0,0 +1,8 @@ +{ + "requests_cache": { + "enabled": true, + "config": { + "expire_after": 3600 + } + } +} diff --git a/tap_jotform/client.py b/tap_jotform/client.py index 380e95f..3582fb5 100644 --- a/tap_jotform/client.py +++ b/tap_jotform/client.py @@ -38,6 +38,13 @@ class JotformStream(RESTStream): INTEGER_FIELDS: tuple[str, ...] = () + _requests_session: requests.Session | None + + def __init__(self, *args: t.Any, **kwargs: t.Any) -> None: + """Initialize the stream object.""" + super().__init__(*args, **kwargs) + self._requests_session = None + @property def url_base(self) -> str: """Return the API URL root, configurable via tap settings. diff --git a/tests/test_core.py b/tests/test_core.py index 02974a9..2362d27 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -8,6 +8,15 @@ from tap_jotform.tap import TapJotform -SAMPLE_CONFIG: dict[str, Any] = {} +SAMPLE_CONFIG: dict[str, Any] = { + "requests_cache": { + "enabled": True, + "config": { + "expire_after": 3600, + }, + }, + "start_date": "2021-01-01T00:00:00Z", +} + TestTapJotform = get_tap_test_class(TapJotform, config=SAMPLE_CONFIG)