Define a user story in the business transaction DSL
Project description
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.
Project details
Release history Release notifications | RSS feed
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.13.0.tar.gz
(23.4 kB
view hashes)
Built Distribution
Close
Hashes for stories-0.13.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 686e8b86cba8171a8a9f796071319ed089caeb832d3e3e70c9f78294e4830965 |
|
MD5 | 94c764f35c1cdae0f868f781cedc8d5f |
|
BLAKE2b-256 | aecb484fe5195c061a714d6c698af53aa528d558f60b1cee8474de5cb5840f7d |