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

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

Several items are prepared for us.

An svn repository:

    >>> repo_url
    'file://TESTREPO'

An svn checkout of a project:

    >>> svnsourcedir
    'TESTTEMP/tha.example-svn'
    >>> import os
    >>> os.chdir(svnsourcedir)
    >>> from zest.releaser.utils import system
    >>> print system("svn info %s" % svnsourcedir)
    Path: ...tha.example-svn...
    file://TESTREPO/tha.example/trunk
    ...

There are no tags yet:

    >>> print system("svn list %s/tha.example/tags" % repo_url)

The changelog is unreleased:

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

The version is at 0.1.dev0:

    >>> svnhead('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.answers_for_testing = ['', '']
    >>> prerelease.main()
    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)``:

    >>> svnhead('CHANGES.txt')
    Changelog of tha.example
    =====================
    <BLANKLINE>
    0.1 (1996-08-24)
    ----------------

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

    >>> svnhead('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.answers_for_testing = ['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:
    svn cp file://TESTREPO/tha.example/trunk file://TESTREPO/tha.example/tags/0.1 -m "Tagging 0.1"
    Question: Run this command (Y/n)?
    Our reply: y
    <BLANKLINE>
    Committed revision 6...
    Question: Check out the tag (for tweaks or pypi/distutils server upload) (Y/n)?
    Our reply: y
    ...CHANGES.txt...
    Checked out revision 6.
    <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>
    Sending        setup.cfg
    Transmitting file data .
    Committed revision 7.
    <BLANKLINE>
    running sdist
    running egg_info
    ...
    creating tha.example-0.1
    ...
    creating dist
    creating 'dist/tha.example-0.1.zip'...
    removing 'tha.example-0.1' ...
    Question: Register and upload to PyPI (Y/n)?
    Our reply: y
    MOCK setup.py register sdist --formats=zip upload...

That last line might be something like "mregister sdist --formats=zip mupload -r
pypi" but we catch that with the test normalizer.

If collective.dist is installed, the last dots above could be saying
that we upload to alternative pypis as well.

There is now a tag:

    >>> print system("svn list %s/tha.example/tags" % repo_url)
    0.1/

And the postrelease script ups the version:

    >>> utils.answers_for_testing = ['', '']
    >>> 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 changelog and setup.py are at 0.2 and indicate dev mode:

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