view tests/doctest.txt @ 54:73e6956c670a

ensure all the files are in the right place
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 01 Mar 2012 15:04:27 -0800
parents a40f050812cb
children 143adebe4caa
line wrap: on
line source

Test simpypi
============

The obligatory imports::

    >>> import os
    >>> import pkginfo
    >>> import shutil
    >>> import simpypi
    >>> import tarfile
    >>> import tempfile
    >>> from paste.fixture import TestApp

The directory is initially empty::

    >>> os.listdir(directory)
    []

Make a test application::

    >>> app = simpypi.SimPyPI(directory)
    >>> testapp = TestApp(app)

Upload a package::

    >>> field = 'package'
    >>> filename = 'HelloWorld-0.0.tar.gz'
    >>> contents = file(os.path.join(here, filename)).read()
    >>> response = testapp.post('/', upload_files=[(field, filename, contents)])

Ensure that package is in the right place::

    >>> os.listdir(directory)
    ['HelloWorld']
    >>> os.listdir(os.path.join(directory, 'HelloWorld'))
    ['HelloWorld-0.0.tar.gz']

Ensure the package is what you expect it to be::

    >>> path = os.path.join(directory, 'HelloWorld', 'HelloWorld-0.0.tar.gz')
    >>> sdist = pkginfo.sdist.SDist(path)
    >>> sdist.name
    'HelloWorld'
    >>> sdist.version
    '0.0'
    >>> sdist.home_page
    'http://helloworld.example.com/'
    >>> sdist.author
    'Jeff Hammel'

Install the package and inspect the installation::

    >>> tmpdir = tempfile.mkdtemp()
    >>> archive = tarfile.TarFile.open(path)
    >>> for member in archive.getmembers():
    ...     archive.extract(member, path=tmpdir)
    >>> os.listdir(tmpdir)
    ['HelloWorld-0.0']
    >>> srcdir = os.path.join(tmpdir, 'HelloWorld-0.0')
    >>> os.path.exists(os.path.join(srcdir, 'setup.py'))
    True
    >>> 'helloworld' in os.listdir(srcdir)
    True
    >>> os.listdir(os.path.join(srcdir, 'helloworld'))
    ['__init__.py']
    >>> shutil.rmtree(tmpdir)

Upload the same package but with the wrong name::

    >>> shutil.rmtree(os.path.join(directory, 'HelloWorld'))
    >>> os.listdir(directory)
    []
    >>> response = testapp.post('/', upload_files=[(field, 'MisleadingName.tar.gz', contents)])
    >>> os.listdir(directory)
    ['HelloWorld']
    >>> os.listdir(os.path.join(directory, 'HelloWorld'))
    ['HelloWorld-0.0.tar.gz']
    >>> shutil.rmtree(os.path.join(directory, 'HelloWorld'))
    >>> os.listdir(directory)
    []
    >>> filename = 'MisleadingFilename.tar.gz'
    >>> contents = file(os.path.join(here, filename)).read()
    >>> response = testapp.post('/', upload_files=[(field, filename, contents)])
    >>> os.listdir(directory)
    ['HelloWorld']
    >>> os.listdir(os.path.join(directory, 'HelloWorld'))
    ['HelloWorld-0.0.tar.gz']