Skip to main content

Action-based request handling and workflow engine for ViUR modules.

Project description

viur-actions

Action-based request handling for ViUR modules.

Tests License: MIT

Features

  • @action decorator and ActionModule mixin
  • Class-init hook wiring (can<X> / on<X> / then<X> / <X>Skel), falling back to the suffix-less defaults (can / on / then / skel)
  • Envelope-v2 via a versioned renderer — mounted under /json/v2/ · /vi/v2/ by install(), selected per-URL. No monkey-patch, no global switch. By default the unversioned /json/ · /vi/ follow the newest version (v2); pass alias_to_newest=False to keep them on v1.

Multi-step workflows (drafts, sliding TTL, optimistic locking, cleanup task) live in the sibling viur-workflow package. See CHANGELOG.md for the running summary.

Requirements

  • Python ≥ 3.12
  • viur-core ≥ 3.8, < 4

Install

pip install spltz-viur-actions

Quick taste

Serve the envelope by mounting the versioned renderer after setup():

from viur.core import setup
import viur.actions
import modules

app = setup(modules)
viur.actions.install()          # mounts /json/v2/… + /vi/v2/…; unversioned /json/ · /vi/ follow v2

Declare actions and hooks on a module:

from viur.core.prototypes import List
from viur.actions import action, ActionModule

class Example(ActionModule, List):

    @action
    def edit(self, key, **kwargs):
        ...

    # Fallback hooks — every action without specific hooks lands here.
    # (No `skel`: on a SkelModule viur-core's own `skel` is the base
    #  skeleton factory, so defining one here would shadow it and recurse.)
    def can(self, skel): ...
    def on(self, skel): ...
    def then(self, skel): ...

    # Action-specific overrides — picked up automatically:
    def canEdit(self, skel): ...
    def editSkel(self): ...

The class-init wiring (__init_subclass__) checks at class definition time which hooks the module provides, and resolves missing ones to the suffix-less default chain. Lookup at runtime is constant-time.

Note: these hooks are resolved for your own @action bodies (via the runtime helpers). viur-core's built-in view/edit/… still call their own canView/onEdited/… directly — can is not a global policy for them.

Development

Two test layers, run separately:

Unit (fast, mocked) — tests/, 100 % coverage gate:

git clone https://github.com/sprengplatz/viur-actions
cd viur-actions
pip install --no-deps -e .
pip install pytest pytest-cov 'coverage[toml]' 'spltz-viur-light-mock>=0.2.0'
pytest                  # 100% coverage required

spltz-viur-light-mock provides the viur.core.* stand-ins so these run without the App Engine stack.

Integration (real core) — integration/, no coverage gate:

pip install "viur-core>=3.8,<4" rsa pytest      # NOT spltz-viur-light-mock
pip install --no-deps -e .
python -m pytest -c integration/pytest.ini integration

Runs the envelope + signature-parity tests against the real framework — the layer that catches mock-vs-core drift. See integration/README.md.

Coverage policy. The 100 % gate applies to the unit layer only. The integration layer runs without a coverage requirement — a coverage target there would pressure mocking the very framework it exists to exercise.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spltz_viur_actions-0.2.1.tar.gz (32.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spltz_viur_actions-0.2.1-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file spltz_viur_actions-0.2.1.tar.gz.

File metadata

  • Download URL: spltz_viur_actions-0.2.1.tar.gz
  • Upload date:
  • Size: 32.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spltz_viur_actions-0.2.1.tar.gz
Algorithm Hash digest
SHA256 00d0f986955050ce1d2b03192220df257a8dbca2aa287ac351abd055e80ad139
MD5 b7ad5c81dd356bb714c21efa6d4270ad
BLAKE2b-256 667dc61c0c0c5604d698e9619bd1b1742857ef61d0b42386a32f623530f140a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for spltz_viur_actions-0.2.1.tar.gz:

Publisher: release.yml on sprengplatz/viur-actions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spltz_viur_actions-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for spltz_viur_actions-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6cda8744254069a89a179a2c182911f3b3ddec0fa1a83efabe40e19ac4b73073
MD5 aee329bd2bd01d003784e3111c55a4ff
BLAKE2b-256 8f062db6b80d317315198c1afa73352f0131ad3cd1839fe924e57df9c597b7d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for spltz_viur_actions-0.2.1-py3-none-any.whl:

Publisher: release.yml on sprengplatz/viur-actions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page