.. -*- Mode: doctest -*-

Doctest for domain/station.txt

Create a new store used in this doctest

    >>> from stoqlib.lib.translation import stoqlib_gettext as _

    >>> from stoqlib.database.runtime import new_store
    >>> store = new_store()

A BranchStation represents a computer Stoq is ran on.

We'll need a branch to operate on in this test, so let's create one:

    >>> from stoqlib.domain.exampledata import create_branch
    >>> branch = create_branch(store)


Creating a new branch station
=============================

    >>> from stoqlib.domain.station import BranchStation

When we start out, there are no stations registered in our branch:

    >>> list(store.find(BranchStation, branch=branch))
    []

    To create a new branch station, use the classmethod create to which you
need to send in a branch and a name:

    >>> station = BranchStation.create(store, branch=branch, name=u"comp")

    >>> station
    <BranchStation ...>
    >>> station.name
    u'comp'

We can now query for the station:

    >>> results = store.find(BranchStation, branch=branch)
    >>> list(results)
    [<BranchStation ...]

    >>> station = results[0]
    >>> station.name
    u'comp'
    >>> station.branch == branch
    True

We cannot create a new branch with the same name in the same branch:

    >>> BranchStation.create(store, branch=branch, name=u"comp")
    Traceback (most recent call last):
        ...
    StoqlibError: There is already a station registered as `comp'.

Fetching a station
==================

You can fetch a previously created station using get_station:

    >>> stations = BranchStation.get_active_stations(store)

    >>> list(stations)
    [<BranchStation...>, ...]

If we inactivate the status, it will of not be included in the list
of active stations:

    >>> station.inactivate()
    >>> station in BranchStation.get_active_stations(store)
    False

If we activate it, it will show up:

    >>> station.activate()
    >>> station in BranchStation.get_active_stations(store)
    True


Status
======

The station is at this point inactive, so get_status_string() will
say so:

    >>> station.get_status_string() == _('Active')
    True

Inactivating the station will change the status string:

    >>> station.inactivate()
    >>> station.get_status_string() == _('Inactive')
    True


Branch name
===========

We can get the name of the branch from the station by calling get_branch_name():

    >>> station.get_branch_name()
    u'Dummy shop'


    Finally close the stire we used in the test

    >>> store.close()

