Skip to main content

Define a user story in the business transaction DSL

Project description

logo

azure-pipeline codecov docs gitter pypi black


The business transaction DSL

Installation

All released versions are hosted on the Python Package Index. You can install this package with following command.

pip install stories

Usage

stories provide a simple way to define a complex business scenario that include many processing steps.

>>> from stories import story, arguments, Success, Failure, Result
>>> from django_project.models import Category, Profile, Subscription

>>> class Subscribe:
...
...     @story
...     @arguments('category_id', 'profile_id')
...     def buy(I):
...
...         I.find_category
...         I.find_profile
...         I.check_balance
...         I.persist_subscription
...         I.show_subscription
...
...     def find_category(self, ctx):
...
...         ctx.category = Category.objects.get(pk=ctx.category_id)
...         return Success()
...
...     def find_profile(self, ctx):
...
...         ctx.profile = Profile.objects.get(pk=ctx.profile_id)
...         return Success()
...
...     def check_balance(self, ctx):
...
...         if ctx.category.cost < ctx.profile.balance:
...             return Success()
...         else:
...             return Failure()
...
...     def persist_subscription(self, ctx):
...
...         ctx.subscription = Subscription(category=ctx.category, profile=ctx.profile)
...         ctx.subscription.save()
...         return Success()
...
...     def show_subscription(self, ctx):
...
...         return Result(ctx.subscription)

>>> Subscribe().buy(category_id=1, profile_id=1)
<Subscription: Subscription object (8)>

This code style allow you clearly separate actual business scenario from implementation details.

License

Stories library is offered under the two clause BSD license.

— ⭐️ —

Drylabs maintains dry-python and helps those who want to use it inside their organizations.

Read more at drylabs.io

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

stories-0.15.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

stories-0.15.0-py2.py3-none-any.whl (29.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file stories-0.15.0.tar.gz.

File metadata

  • Download URL: stories-0.15.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/4.15.0-1077-azure

File hashes

Hashes for stories-0.15.0.tar.gz
Algorithm Hash digest
SHA256 8f09a0f131e382cfa4f9960e034e8844b51f1a01d3ef96ba4e1ed151a08c0f4c
MD5 1c1e615fdd0853cfa28c119160d21782
BLAKE2b-256 2f0cd7be1e2a2e3f49ff77ae2fd1c1c81e5f573da40e76940f19e9e431931afb

See more details on using hashes here.

File details

Details for the file stories-0.15.0-py2.py3-none-any.whl.

File metadata

  • Download URL: stories-0.15.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/4.15.0-1077-azure

File hashes

Hashes for stories-0.15.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6c5b7706f2aaf8d8d3bd4da3603c7c26e8a4fd8fcabd6d2731268f55ba088907
MD5 46f0a7908918e9b481a0068c18833dea
BLAKE2b-256 53aaeef21ba96ed5677ba7fcec97a6aee0df858d11be249d2b96aeb178b1d932

See more details on using hashes here.

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