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):
...
...         category = Category.objects.get(pk=ctx.category_id)
...         return Success(category=category)
...
...     def find_profile(self, ctx):
...
...         profile = Profile.objects.get(pk=ctx.profile_id)
...         return Success(profile=profile)
...
...     def check_balance(self, ctx):
...
...         if ctx.category.cost < ctx.profile.balance:
...             return Success()
...         else:
...             return Failure()
...
...     def persist_subscription(self, ctx):
...
...         subscription = Subscription(category=ctx.category, profile=ctx.profile)
...         subscription.save()
...         return Success(subscription=subscription)
...
...     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.

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.11.2.tar.gz (22.5 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.11.2-py2.py3-none-any.whl (35.8 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: stories-0.11.2.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.1 Linux/4.15.0-1071-azure

File hashes

Hashes for stories-0.11.2.tar.gz
Algorithm Hash digest
SHA256 27093750f398d166a8dcac9a4a1453059c98f5f562ade751a2ad081409b71a24
MD5 3c4eabfdc6b25f440db0020c6cb66964
BLAKE2b-256 3362b80cdea769bca8eaeeffd104577209a1a0bafd214c03210d7a72d4272c6d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for stories-0.11.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 107beee9e507db80c9c2225cdddbcd571352e91ec3803507549dde50820ddbe4
MD5 8907e6d84b1778bbb181194125232233
BLAKE2b-256 22d52753d36f805d2b08b0ce3448f118f19037b68814464acdd113387730b9aa

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