Integration test
================

.. :doctest:
.. :setup: zest.releaser.tests.functional.setup
.. :teardown: zest.releaser.tests.functional.teardown

Several items are prepared for us.

A Bazaar directory (repository and checkout in one):

    >>> bzrsourcedir
    'TESTTEMP/tha.example-bzr'
    >>> import os
    >>> os.chdir(bzrsourcedir)

There are no tags yet:

    >>> from zest.releaser.utils import execute_command
    >>> print(execute_command("bzr tags"))

The changelog is unreleased:

    >>> bzrhead('CHANGES.txt')
    Changelog of tha.example
    ========================
    <BLANKLINE>
    0.1 (unreleased)
    ----------------

The version is at 0.1.dev0:

    >>> bzrhead('setup.py')
    from setuptools import setup, find_packages
    import os.path
    <BLANKLINE>
    version = '0.1.dev0'

Asking input on the prompt is not unittestable unless we use the prepared
testing hack in utils.py:

    >>> from zest.releaser import utils
    >>> utils.TESTMODE = True

Run the prerelease script:

    >>> from zest.releaser import prerelease
    >>> utils.test_answer_book.set_answers(['', '', '', '', ''])
    >>> prerelease.main()
    Question...
    Question: Enter version [0.1]:
    Our reply: <ENTER>
    Checking data dict
    Question: OK to commit this (Y/n)?
    Our reply: <ENTER>

The changelog now has a release date instead of ``(unreleased)``:

    >>> bzrhead('CHANGES.txt')
    Changelog of tha.example
    ========================
    <BLANKLINE>
    0.1 (2007-01-14)
    ----------------

And the version number is just 0.1 and has lost its dev marker:

    >>> bzrhead('setup.py')
    from setuptools import setup, find_packages
    import os.path
    <BLANKLINE>
    version = '0.1'

The release script tags the release and uploads it:

    >>> utils.test_answer_book.set_answers(['y', 'y', 'y', 'y', 'y', 'y', 'y', 'y'])
    >>> mock_pypi_available.append('tha.example')
    >>> from zest.releaser import release
    >>> release.main()
    Checking data dict
    Tag needed to proceed, you can use the following command:
    bzr tag 0.1
    Question: Run this command (Y/n)?
    Our reply: y
    RED Created tag 0.1.
    <BLANKLINE>
    Question: Check out the tag
        (for tweaks or pypi/distutils server upload) (Y/n)?
    Our reply: y
    <BLANKLINE>
    Question: Fix setup.cfg (and commit to tag if possible) (Y/n)?
    Our reply: y
    [egg_info]
    tag_build =
    tag_svn_revision = false
    <BLANKLINE>
    <BLANKLINE>
    Showing first few lines...
    running sdist
    running egg_info
    creating src/tha.example.egg-info
    ...
    creating dist
    Creating ...
    removing 'tha.example-0.1' ...
    Question: Upload to pypi (Y/n)?
    Our reply: y
    MOCK twine upload -r pypi dist/tha.example-0.1.tar.gz

There is now a tag:

    >>> print(execute_command("bzr tags"))
    0.1                  2

And the postrelease script ups the version:

    >>> utils.test_answer_book.set_answers(['', ''])
    >>> from zest.releaser import postrelease
    >>> postrelease.main()
    Current version is 0.1
    Question: Enter new development version ('.dev0' will be appended) [0.2]:
    Our reply: <ENTER>
    Checking data dict
    Question: OK to commit this (Y/n)?
    Our reply: <ENTER>

The commit will contain an extra message with in this case a hint for
Travis to skip the Continuous Integration build, because our pypirc
has asked this with the extra-message option::

    >>> from zest.releaser import lasttaglog
    >>> lasttaglog.main()
    bzr log...
        Back to development: 0.2
    <BLANKLINE>
        [ci skip]...

The changelog and setup.py are at 0.2 and indicate dev mode:

    >>> bzrhead('CHANGES.txt')
    Changelog of tha.example
    ========================
    <BLANKLINE>
    0.2 (unreleased)
    ----------------
    >>> bzrhead('setup.py')
    from setuptools import setup, find_packages
    import os.path
    <BLANKLINE>
    version = '0.2.dev0'
