Skip to content

improve python-client tests#50

Open
nebay-abraha wants to merge 13 commits into
masterfrom
test-codeql
Open

improve python-client tests#50
nebay-abraha wants to merge 13 commits into
masterfrom
test-codeql

Conversation

@nebay-abraha

@nebay-abraha nebay-abraha commented Apr 16, 2026

Copy link
Copy Markdown
Contributor
  • migrate pytest configuration to pyproject.toml and align test dependencies
  • bump pytest
  • support Python 3.9+ and update development guidance
  • replace the Playwright + rspace-docker CI flow with a from-source rspace-web build using Maven/Jetty and
  • GitHub Actions services, eliminating browser automation, external Docker dependencies, and stored credentials
  • improve CI reliability by warming up the built-in sysadmin account before integration tests
  • fix Inventory identifier-settings API calls to match the actual endpoint contract and correct Datacite connection testing
  • strengthen integration tests and update assertions to match the real API behavior
  • document the new CI provisioning flow and equivalent local integration test setup
  • improve test robustness and add additional integration test coverage

Comment thread .github/scripts/get_rspace_api_key.py Fixed
Comment thread .github/scripts/get_rspace_api_key.py Fixed
@nebay-abraha nebay-abraha marked this pull request as draft April 16, 2026 13:10
Comment thread .github/scripts/get_rspace_api_key.py Fixed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes the Python client’s testing and CI setup by separating unit vs. integration tests, updating pytest configuration/dependencies, and improving inventory/ELN integration test robustness (including bootstrapping an RSpace Docker instance in GitHub Actions).

Changes:

  • Migrate pytest configuration into pyproject.toml, add an integration marker, and update dev/test dependencies (pytest, playwright, setuptools pin).
  • Make integration tests more robust by ensuring prerequisite data exists and by using safer temp-file handling.
  • Add a GitHub Actions integration-test job that boots rspace-docker and generates an API key via Playwright automation.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
rspace_client/tests/sample_post_test.py Adds unit tests for SamplePost location + barcode serialization behavior.
rspace_client/tests/invapi_test.py Marks as integration and reduces brittleness of assertions; updates barcode test expectations.
rspace_client/tests/inv_lom_test.py Marks LOM API test as integration.
rspace_client/tests/elnapi_test.py Marks as integration; improves robustness via temp files and pre-creating test data.
rspace_client/inv/inv.py Updates Barcode dataclass serialization and adds location support to SamplePost.
pytest.ini Removes legacy pytest config (moved to pyproject.toml).
pyproject.toml Updates Python baseline/deps and defines pytest options + integration marker.
DEVELOPING.md Updates Python version guidance and clarifies unit vs. integration test commands.
.github/workflows/codeql-and-tests.yml Adds unit-test matrix and new integration-test job with RSpace Docker bootstrapping.
.github/scripts/get_rspace_api_key.py New Playwright-based script to generate an RSpace API key in CI.
.env.example Adds username/password entries to support API key generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rspace_client/inv/inv.py Outdated
import pprint
import requests
from typing import Optional, Sequence, Union, List, TypedDict, BinaryIO
from typing import Optional, Sequence, Union, List, TypedDict, BinaryIO, ClassVar
Comment thread rspace_client/inv/inv.py Outdated
Comment on lines +34 to +40
@dataclass
class Barcode:
data: str
format: BarcodeFormat
data: Optional[str] = None
format: Optional[BarcodeFormat] = None
description: str = ""
newBarcodeRequest: bool = True
id: Optional[str] = ""
new_barcode_request: bool = True
id: Optional[str] = None
Comment thread rspace_client/tests/invapi_test.py Outdated
Comment on lines +695 to +701
"SA12345", outfile="out10.png", barcode_type=inv.BarcodeFormat.QR
)
self.assertEqual(293, len(qr_bytes))
self.assertTrue(len(qr_bytes) > 0)
self.assertTrue(qr_bytes.startswith(b"\x89PNG\r\n\x1a\n"))
self.assertTrue(os.path.exists("out10.png"))
self.assertTrue(os.path.getsize("out10.png") > 0)
os.remove("out10.png")
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
Comment thread .github/workflows/codeql-and-tests.yml Outdated
Comment on lines +154 to +161
- name: Generate RSpace API Key
id: generate_key
run: poetry run python .github/scripts/get_rspace_api_key.py
env:
RSPACE_URL: http://localhost:8080
RSPACE_USERNAME: ${{ secrets.RSPACE_USERNAME }}
RSPACE_PASSWORD: ${{ secrets.RSPACE_PASSWORD }}

Comment thread .github/scripts/get_rspace_api_key.py Outdated
match = re.search(r"Key:\s*([A-Za-z0-9]{32})", info_text)
if not match:
raise RuntimeError(
f"API key regex did not match — text length {len(info_text)}, starts with: {repr(info_text[:20])}"
Comment thread .github/scripts/get_rspace_api_key.py Outdated
import os
import re
import sys
from playwright.sync_api import sync_playwright, expect
nebay-abraha and others added 12 commits July 7, 2026 20:25
- bump pytest and pin setuptools
- add RSpace bootstrapping and python playwright api key generation
- update development and test run guidance
- python version baseline and clearer unit vs integration instructions
- make test more robust
- run integration tests against rspace-docker container
- update barcode data class to align with rspace-java-client
- add sample_post tests
…ct to init rspace instance"

This reverts commit e3ab722.

Replicating rspace-web's e2e.yml boot mechanism required a full Maven/Node
rebuild of rspace-web on every CI run (jetty:run-war forks a full "package"
phase regardless of -Dmaven.war.skip), which is far more expensive than the
docker-compose flow it replaced. Reverting to the known-working setup.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
this avoids constant failure due to ui changes which playwright ui depends on
…alidate the boolean response, and updated the related tests to match the corrected API behavior

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Comment thread rspace_client/tests/invapi_test.py Outdated
Comment on lines +694 to +701
qr_bytes = self.invapi.barcode(
"SA12345", outfile="out10.png", barcode_type=inv.Barcode.QR
"SA12345", outfile="out10.png", barcode_type=inv.BarcodeFormat.QR
)
self.assertEqual(293, len(qr_bytes))
self.assertTrue(len(qr_bytes) > 0)
self.assertTrue(qr_bytes.startswith(b"\x89PNG\r\n\x1a\n"))
self.assertTrue(os.path.exists("out10.png"))
self.assertTrue(os.path.getsize("out10.png") > 0)
os.remove("out10.png")
Comment thread rspace_client/inv/inv.py
Comment on lines 2753 to 2759
try:
response = requests.get(url, headers=headers)
return response.status_code == 200
if response.status_code != 200:
return False
return bool(response.json())
except requests.exceptions.RequestException:
return False
Comment thread rspace_client/inv/inv.py Outdated
Comment thread .github/workflows/codeql-and-tests.yml Outdated
id: rspace_web_release
run: |
set -euo pipefail
latest_tag=$(curl -fsSL https://api.github.com/repos/rspace-os/rspace-web/releases/latest | jq -r '.tag_name')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants