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
class Subscribe:
@story
@arguments('category_id', 'user_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(id=ctx.category_id)
return Success(category=category)
def find_profile(self, ctx):
profile = Profile.objects.get(user_id=ctx.user_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(ctx.category, ctx.profile)
subscription.save()
return Success(subscription=subscription)
def show_subscription(self, ctx):
return Result(ctx.subscription)
>>> Subscribe().buy(category_id=1, user_id=1)
<Subscription object>
>>> _
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.10.tar.gz
(12.2 kB
view hashes)
Built Distribution
stories-0.10-py2.py3-none-any.whl
(38.6 kB
view hashes)
Close
Hashes for stories-0.10-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11f1c2b969857e956718a69252fa10c7cffdea8ffdc66a2e5d1bd19969eba914 |
|
MD5 | 26334eef1f0c3bf7074c4e1b0d510f49 |
|
BLAKE2b-256 | a463173f84a837a3fd573effc01f5926f20cdcf9f9f63a5083ffa18c5f67d913 |