Skip to content
Define a user story in the business transaction DSL.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src/stories
tests
.gitignore
.python-version
.travis.yml
LICENSE
README.rst
pyproject.toml
setup.cfg
tox.ini

README.rst

https://raw.githubusercontent.com/dry-python/brand/master/logo/stories.png

travis 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

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.

You can’t perform that action at this time.