Skip to content

Commit

Permalink
fix: Ensure requests caching can be enabled (#199)
Browse files Browse the repository at this point in the history
* fix: Ensure requests caching can be enabled

* Add job dependency
  • Loading branch information
edgarrmondragon authored Oct 19, 2023
1 parent e745723 commit e141c51
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 3 deletions.
52 changes: 51 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
fetch-depth: 0

- name: Set up Python
uses: actions/[email protected]
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 }}
Expand All @@ -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"}
Expand Down Expand Up @@ -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 }}
Expand Down
15 changes: 14 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,27 @@
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",
"tests",
)


@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."""
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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 = """
Expand Down
8 changes: 8 additions & 0 deletions requests_cache.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"requests_cache": {
"enabled": true,
"config": {
"expire_after": 3600
}
}
}
7 changes: 7 additions & 0 deletions tap_jotform/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit e141c51

Please sign in to comment.