Repository navigation
Test pins against multiple Connect versions with with-connect #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
966bf01
223289a
7997e0c
0b1620a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,26 +20,26 @@ jobs: | |
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python: ["3.9", "3.10", "3.11", "3.12", "3.13"] | ||
| python: ["3.10", "3.11", "3.12", "3.13", "3.14"] | ||
| os: ["ubuntu-latest"] | ||
| pytest_opts: ["--workers 4 --tests-per-worker 1"] | ||
| requirements: [""] | ||
| include: | ||
| - os: "ubuntu-latest" | ||
| - os: "ubuntu-24.04" | ||
| python: "3.9" | ||
| requirements: "requirements/minimum.txt" | ||
| - os: "macos-latest" | ||
| python: "3.10" | ||
| python: "3.14" | ||
| # ignore doctests, as they involve calls to github, and all mac machines | ||
| # use the same IP address | ||
| pytest_opts: "-k pins/tests" | ||
| - os: "windows-latest" | ||
| python: "3.10" | ||
| python: "3.14" | ||
| # ignore doctests | ||
| pytest_opts: "-k pins/tests" | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/setup-python@v4 | ||
| - uses: actions/checkout@v7 | ||
| - uses: actions/setup-python@v7 | ||
| with: | ||
| python-version: ${{ matrix.python }} | ||
| - name: Install dependencies | ||
|
|
@@ -54,12 +54,14 @@ jobs: | |
|
|
||
| python -m pip install -e .[test] | ||
|
|
||
| - name: Authenticate to Google Cloud | ||
| uses: google-github-actions/auth@v3 | ||
| with: | ||
| credentials_json: ${{ secrets.GCP_SA_KEY }} | ||
| - name: Set up Cloud SDK | ||
| uses: google-github-actions/setup-gcloud@v0 | ||
| uses: google-github-actions/setup-gcloud@v3 | ||
| with: | ||
| project_id: siuba-tests | ||
| service_account_key: ${{ secrets.GCP_SA_KEY }} | ||
| export_default_credentials: true | ||
| - name: Run tests | ||
| shell: bash | ||
| run: | | ||
|
|
@@ -80,12 +82,27 @@ jobs: | |
| no_proxy: "*" | ||
|
|
||
| test-connect: | ||
| name: "Test Posit Connect" | ||
| name: "Test Posit Connect (${{ matrix.connect-version }})" | ||
| runs-on: ubuntu-latest | ||
| if: ${{ !github.event.pull_request.head.repo.fork }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| connect-version: | ||
| - "preview" | ||
| - "release" | ||
| # Six-month samples within the 18-month support window. | ||
| - "2026.07.0" | ||
| - "2026.01.1" | ||
| - "2025.07.0" | ||
| # One release per year outside the support window. | ||
| - "2024.06.0" | ||
| - "2023.07.0" | ||
| # with-connect's bootstrap authentication requires 2022.10.0 or newer. | ||
| - "2022.10.0" | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/setup-python@v4 | ||
| - uses: actions/checkout@v7 | ||
| - uses: actions/setup-python@v7 | ||
| with: | ||
| python-version: "3.10" | ||
| - name: Install dependencies | ||
|
|
@@ -95,14 +112,15 @@ jobs: | |
| python -m pip install -e . | ||
|
|
||
| - name: Run tests | ||
| uses: posit-dev/with-connect@main | ||
| uses: posit-dev/with-connect@0783dabdd24e360e985a4588ce1239c3dc31c542 # main | ||
| env: | ||
| ALLOW_RSC_SHORT_NAME: 1 | ||
| with: | ||
| # License file is valid until 2026-11-05 | ||
| version: ${{ matrix.connect-version }} | ||
| license: ${{ secrets.CONNECT_LICENSE }} | ||
| config-file: "script/setup-rsconnect/rstudio-connect.gcfg" | ||
| command: | | ||
| set -e | ||
| python script/setup-rsconnect/dump_api_keys.py pins/tests/rsconnect_api_keys.json | ||
| pytest pins -m "fs_rsc and not skip_on_github" | ||
|
|
||
|
|
@@ -112,8 +130,8 @@ jobs: | |
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.pull_request.head.repo.fork }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/setup-python@v4 | ||
| - uses: actions/checkout@v7 | ||
| - uses: actions/setup-python@v7 | ||
| with: | ||
| python-version: "3.10" | ||
| - name: Install dependencies | ||
|
|
@@ -131,8 +149,8 @@ jobs: | |
| name: "Build Docs" | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/setup-python@v4 | ||
| - uses: actions/checkout@v7 | ||
| - uses: actions/setup-python@v7 | ||
| with: | ||
| python-version: "3.10" | ||
| - name: Install dependencies | ||
|
|
@@ -148,7 +166,7 @@ jobs: | |
| run: | | ||
| make docs-build | ||
| - name: Save docs artifact | ||
| uses: actions/upload-artifact@v4 | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: docs-html | ||
| path: docs/_site | ||
|
|
@@ -160,7 +178,7 @@ jobs: | |
| if: "${{github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork }}" | ||
|
|
||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| - uses: actions/download-artifact@v8 | ||
| with: | ||
| name: docs-html | ||
| path: docs/_site | ||
|
|
@@ -177,14 +195,13 @@ jobs: | |
| # create deployment ---- | ||
|
|
||
| - name: Create Github Deployment | ||
| uses: bobheadxi/deployments@v0.4.3 | ||
| uses: bobheadxi/deployments@v1 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from 🤖: this step requires Also note that in v1, finish defaults to |
||
| id: deployment | ||
| with: | ||
| step: start | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| env: ${{ env.RELEASE_NAME }} | ||
| ref: ${{ github.head_ref }} | ||
| transient: true | ||
| logs: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' | ||
|
|
||
| # push docs ---- | ||
|
|
@@ -203,7 +220,7 @@ jobs: | |
| # update deployment ---- | ||
|
|
||
| - name: Update Github Deployment | ||
| uses: bobheadxi/deployments@v0.4.3 | ||
| uses: bobheadxi/deployments@v1 | ||
| if: ${{ always() }} | ||
| with: | ||
| step: finish | ||
|
|
@@ -219,11 +236,11 @@ jobs: | |
| needs: ["build-docs", "tests", "test-connect"] | ||
| if: github.ref == 'refs/heads/main' | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| - uses: actions/download-artifact@v8 | ||
| with: | ||
| name: docs-html | ||
| path: docs/_site | ||
| - uses: peaceiris/actions-gh-pages@v3 | ||
| - uses: peaceiris/actions-gh-pages@v4 | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| publish_dir: docs/_site | ||
|
|
@@ -234,8 +251,8 @@ jobs: | |
| if: github.event_name == 'release' | ||
| needs: [build-docs, tests] | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/setup-python@v4 | ||
| - uses: actions/checkout@v7 | ||
| - uses: actions/setup-python@v7 | ||
| with: | ||
| python-version: "3.10" | ||
| - name: "Build Package" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import json | ||
|
|
||
| import pytest | ||
| import requests | ||
|
|
||
| from pins.rsconnect.api import LoginConnectApi, RsConnectApiRequestError | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "key_status,legacy_status,json_error", | ||
| [ | ||
| (200, None, False), | ||
| (200, None, True), | ||
| (404, 200, False), | ||
| (404, 200, True), | ||
| (403, None, False), | ||
| (403, None, True), | ||
| (500, None, False), | ||
| (404, 403, False), | ||
| ], | ||
| ) | ||
| def test_login_create_api_key(monkeypatch, key_status, legacy_status, json_error): | ||
| calls = [] | ||
| responses = [ | ||
| (200, {}), | ||
| (200, {"guid": "test-user"}), | ||
| ( | ||
| key_status, | ||
| {"key": "modern-key"} if key_status == 200 and not json_error else None, | ||
| ), | ||
| ] | ||
| if legacy_status is not None: | ||
| responses.append( | ||
| (legacy_status, {"key": "legacy-key"} if legacy_status == 200 else None) | ||
| ) | ||
|
|
||
| def request(method, url, **kwargs): | ||
| calls.append((method, url, kwargs)) | ||
| status, payload = responses.pop(0) | ||
| if payload is None and json_error: | ||
| payload = {"code": 3, "error": "request failed"} | ||
| response = requests.Response() | ||
| response.status_code = status | ||
| response.url = url | ||
| response._content = ( | ||
| json.dumps(payload).encode() if payload is not None else b"request failed" | ||
| ) | ||
| return response | ||
|
|
||
| session = requests.Session() | ||
| monkeypatch.setattr(session, "request", request) | ||
| client = LoginConnectApi("user", "password", "http://connect.test", session=session) | ||
|
|
||
| error_status = legacy_status if key_status == 404 else key_status | ||
| if key_status == 200 and json_error: | ||
| with pytest.raises(RsConnectApiRequestError): | ||
| client.create_api_key("test-key") | ||
| elif error_status == 200: | ||
| assert client.create_api_key("test-key") == ( | ||
| "legacy-key" if legacy_status is not None else "modern-key" | ||
| ) | ||
| else: | ||
| with pytest.raises(requests.HTTPError) as error: | ||
| client.create_api_key("test-key") | ||
| assert error.value.response.status_code == error_status | ||
|
|
||
| expected_routes = [ | ||
| ("POST", "__login__"), | ||
| ("GET", "v1/user"), | ||
| ("POST", "v1/users/test-user/keys"), | ||
| ] | ||
| if legacy_status is not None: | ||
| expected_routes.append(("POST", "keys")) | ||
| assert [(method, url) for method, url, _ in calls] == [ | ||
| (method, f"http://connect.test/__api__/{route}") | ||
| for method, route in expected_routes | ||
| ] | ||
| for _, _, kwargs in calls[2:]: | ||
| assert kwargs["json"] == {"name": "test-key"} | ||
| assert "Authorization" not in kwargs["headers"] | ||
| assert not responses |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ test = [ | |
| "fastparquet", | ||
| "pip-tools", | ||
| "pyarrow", | ||
| "pytest==7.1.3", | ||
| "pytest>=8.4.2,<9", # pytest 9 requires Python 3.10. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with pytest 8, we'll need to drop the |
||
| "pytest-cases", | ||
| "pytest-dotenv", | ||
| "pytest-parallel", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as on pins-r: this is great but I think we can dial it back a little and still have the coverage we need.