Skip to content

improve python-client tests#50

Open
nebay-abraha wants to merge 6 commits intomasterfrom
test-codeql
Open

improve python-client tests#50
nebay-abraha wants to merge 6 commits intomasterfrom
test-codeql

Conversation

@nebay-abraha
Copy link
Copy Markdown
Contributor

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

  • migrate pytest config to pyproject and align test dependencies
  • bump pytest and pin setuptools
  • python 3.7 and 3.8 aren't actively support, so we are supporting v3.9 and later
  • 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

Test steps:

  • run rspace-docker locally
  • run both unit and integration tests, instructions in the DEVELOPING.md

Comment thread .github/scripts/get_rspace_api_key.py Fixed
Comment thread .github/scripts/get_rspace_api_key.py Dismissed
@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
@nebay-abraha nebay-abraha marked this pull request as ready for review April 16, 2026 14:06
- 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
Copy link
Copy Markdown

Copilot AI left a comment

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 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 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 nebay-abraha requested a review from tilorspace April 20, 2026 13:46
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