Exemplo n.º 1
0
    def test_regenerate_index(self):
        self.im = self.make_one()
        home, leaves = self.im.regenerate_all()
        pth = self.im.path
        file_structure = [(x.parent.name, x.name) for x in pth.walk()]
        index_name = u'%s-test-index' % self.count
        expected = [(index_name, u'dummypackage'),
                    (u'dummypackage', u'index.html'),
                    (path(u'dummypackage'), path(u'index.json')),
                    (index_name, u'dummypackage-0.0dev.tar.gz'),
                    (index_name, u'index.html')]

        assert len(leaves) == 1
        assert leaves[0].exists()
        assert leaves[0].name == 'index.json'
        assert leaves[0].parent.name == 'dummypackage'

        etxt = pprint(sorted(str(x) for x in expected))
        fstxt = pprint(sorted(str(x) for x in file_structure))
        assert set(expected).issubset(file_structure), \
               textwrap.dedent("""
               Expected not a subset of result::

               expected:

                %s

               actual:

                %s""") %(etxt, fstxt)
Exemplo n.º 2
0
    def test_regenerate_index(self):
        self.im = self.make_one()
        home, leaves = self.im.regenerate_all()
        pth = self.im.path
        file_structure = [(x.parent.name, x.name) for x in pth.walk()]
        index_name = u'%s-test-index' %self.count
        expected = [(index_name, u'dummypackage'),
                    (u'dummypackage', u'index.html'),
                    (path(u'dummypackage'), path(u'index.json')),
                    (index_name, u'dummypackage-0.0dev.tar.gz'),
                    (index_name, u'index.html')]

        assert len(leaves) == 1
        assert leaves[0].exists()
        assert leaves[0].name == 'index.json'
        assert leaves[0].parent.name == 'dummypackage'

        etxt = pprint(sorted(str(x) for x in expected))
        fstxt = pprint(sorted(str(x) for x in file_structure))
        assert set(expected).issubset(file_structure), \
               textwrap.dedent("""
               Expected not a subset of result::

               expected:

                %s

               actual:

                %s""") %(etxt, fstxt)
Exemplo n.º 3
0
    def test_add_version_to_leaf_w_remove_file_cleans_up_leafdata(self):
        idx = self.make_one()
        idx.write_html = False
        name = 'dummypackage'

        leafpath = idx.path / name
        distpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')

        idx.regenerate_leaf(name)
        distpath.copy(idx.path)

        assert len(leafpath.files()) == 2

        distpath = idx.path / distpath.name
        data = idx.add_version_to_leaf(distpath, name)

        distpath2 = idx.path / self.dum_whl.name
        self.dum_whl.copy(distpath2)
        data = idx.add_version_to_leaf(distpath2, name)

        assert len(data) == 3
        assert (leafpath / distpath.name).exists()

        distpath.remove()

        leafdata = idx.cleanup_leafdata(leafpath, leafpath / 'index.json')
        assert len(leafdata) == 2
Exemplo n.º 4
0
    def test_add_version_to_leaf_w_remove_file_cleans_up_leafdata(self):
        idx = self.make_one()
        idx.write_html = False
        name = 'dummypackage'

        leafpath = idx.path / name
        distpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')

        idx.regenerate_leaf(name)
        distpath.copy(idx.path)

        assert len(leafpath.files()) == 2

        distpath = idx.path / distpath.name
        data = idx.add_version_to_leaf(distpath, name)

        distpath2 = idx.path / self.dum_whl.name
        self.dum_whl.copy(distpath2)
        data = idx.add_version_to_leaf(distpath2, name)

        assert len(data) == 3
        assert (leafpath / distpath.name).exists()

        distpath.remove()

        leafdata = idx.cleanup_leafdata(leafpath, leafpath / 'index.json')
        assert len(leafdata) == 2
Exemplo n.º 5
0
 def file_root(self):
     test_dir = getattr(self, 'test_dir')
     if test_dir is None:
         test_dir = '%s-view-tests' %next(self.counter)
         self.test_dir = test_dir = path(__file__).parent / "test-indexes" / test_dir
         self.test_dir.mkdir_p()
         self.cleanup.append(test_dir)
     return self.test_dir
Exemplo n.º 6
0
 def file_root(self):
     test_dir = getattr(self, 'test_dir')
     if test_dir is None:
         test_dir = '%s-view-tests' % next(self.counter)
         self.test_dir = test_dir = path(
             __file__).parent / "test-indexes" / test_dir
         self.test_dir.mkdir_p()
         self.cleanup.append(test_dir)
     return self.test_dir
Exemplo n.º 7
0
    def test_add_version_to_leaf_html_free(self):
        idx = self.make_one()
        idx.write_html = False

        name = 'dummypackage'
        idx.regenerate_leaf(name)

        distpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        distpath.copy(idx.path / distpath.name)
        data = idx.add_version_to_leaf(distpath, name)
        assert len(data) == 2
        assert all(x.islink() for x in (idx.path / name).files("*.gz"))
Exemplo n.º 8
0
    def test_rebuild_leaf_subscriber_existing_leaf(self):
        from cheeseprism.event import PackageAdded
        from cheeseprism.index import rebuild_leaf
        self.im = self.make_one()

        self.im.regenerate_leaf('dummypackage')

        distpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        event = PackageAdded(self.im, path=distpath)
        out = rebuild_leaf(event)

        assert len(out) == 2
Exemplo n.º 9
0
    def test_regenerate_leaf(self):
        self.im = self.make_one()
        [x for x in self.im.regenerate_all()]
        leafindex = self.im.path / 'dummypackage/index.html'
        new_arch = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        new_arch.copy(self.im.path)

        added = self.im.path / new_arch.name
        before_txt = leafindex.text()
        info = self.im.pkginfo_from_file(added)
        out = self.im.regenerate_leaf(info.name)
        assert before_txt != out.text()
Exemplo n.º 10
0
    def test_add_version_to_leaf_html_free(self):
        idx = self.make_one()
        idx.write_html = False

        name = 'dummypackage'
        idx.regenerate_leaf(name)

        distpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        distpath.copy(idx.path / distpath.name)
        data = idx.add_version_to_leaf(distpath, name)
        assert len(data) == 2
        assert all(x.islink() for x in (idx.path / name).files("*.gz"))
Exemplo n.º 11
0
    def test_regenerate_leaf(self):
        self.im = self.make_one()
        [x for x in self.im.regenerate_all()]
        leafindex = self.im.path / 'dummypackage/index.html'
        new_arch = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        new_arch.copy(self.im.path)

        added = self.im.path / new_arch.name
        before_txt = leafindex.text()
        info = self.im.pkginfo_from_file(added)
        out = self.im.regenerate_leaf(info.name)
        assert before_txt != out.text()
Exemplo n.º 12
0
    def test_rebuild_leaf_subscriber_existing_leaf(self):
        from cheeseprism.event import PackageAdded
        from cheeseprism.index import rebuild_leaf
        self.im = self.make_one()

        self.im.regenerate_leaf('dummypackage')

        distpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        event = PackageAdded(self.im, path=distpath)
        out = rebuild_leaf(event)

        assert len(out) == 2
Exemplo n.º 13
0
 def test_upload(self, wb):
     from cheeseprism.views import upload
     self.setup_event()
     context, request = self.base_cr
     request.method = 'POST'
     request.POST['content'] = FakeFS(path('dummypackage/dist/dummypackage-0.0dev.tar.gz'))
     with patch('cheeseprism.index.IndexManager.pkginfo_from_file',
                return_value=stuf(name='dummycode', version='0.0dev')) as pkif:
         res = upload(context, request)
         assert pkif.called
         assert 'PackageAdded' in self.event_results
         assert self.event_results['PackageAdded'][0].name == pkif.return_value.name
     assert res.headers == {'X-Swalow-Status': 'SUCCESS'}
Exemplo n.º 14
0
 def test_leafdata(self):
     self.im = self.make_one()
     fpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
     dist = Mock(name='dist')
     distinfo = dist.name, dist.version = 'distname', 'version'
     data = self.im.leafdata(fpath, dist)
     assert distinfo == (data['name'], data['version'])
     assert data['md5'] == fpath.md5hex
     assert data['size'] == fpath.size
     assert data['filename'] == fpath.name
     assert 'mtime' in data
     assert data['ctime'] == fpath.ctime
     assert 'atime' in data
Exemplo n.º 15
0
 def test_leafdata(self):
     self.im = self.make_one()
     fpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
     dist = Mock(name='dist')
     distinfo = dist.name, dist.version = 'distname', 'version'
     data = self.im.leafdata(fpath, dist)
     assert distinfo == (data['name'], data['version'])
     assert data['md5'] == fpath.md5hex
     assert data['size'] == fpath.size
     assert data['filename'] == fpath.name
     assert 'mtime' in data
     assert data['ctime'] == fpath.ctime
     assert 'atime' in data
Exemplo n.º 16
0
    def test_rebuild_leaf_subscriber(self):
        """
        Cover event subscriber
        """
        from cheeseprism.event import PackageAdded
        from cheeseprism.index import rebuild_leaf
        self.im = self.make_one()
        event = PackageAdded(self.im,  here / path('dummypackage2/dist/dummypackage-0.1.tar.gz'))

        with patch('cheeseprism.index.IndexManager.regenerate_leaf') as rl:
            out = rebuild_leaf(event)
        assert out is not None
        assert rl.call_args == (('dummypackage',), {})
Exemplo n.º 17
0
    def test_rebuild_leaf_subscriber(self):
        """
        Cover event subscriber
        """
        from cheeseprism.event import PackageAdded
        from cheeseprism.index import rebuild_leaf
        self.im = self.make_one()
        event = PackageAdded(
            self.im, here / path('dummypackage2/dist/dummypackage-0.1.tar.gz'))

        with patch('cheeseprism.index.IndexManager.regenerate_leaf') as rl:
            out = rebuild_leaf(event)
        assert out is not None
        assert rl.call_args == (('dummypackage', ), {})
Exemplo n.º 18
0
    def test_add_version_to_leaf_nodups(self):
        idx = self.make_one()

        name = 'dummypackage'
        idx.regenerate_leaf(name)

        distpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        distpath.copy(idx.path / distpath.name)

        data = idx.add_version_to_leaf(distpath, name)
        assert idx.path.exists()

        data = idx.add_version_to_leaf(distpath, name)
        assert len(data) == 2
Exemplo n.º 19
0
 def test_upload_raises_packageadded(self):
     """
     If adding the package raises an error, an exception should be logged
     """
     from cheeseprism.views import upload
     self.setup_event()
     context, request = self.base_cr
     request.method = 'POST'
     request.POST['content'] = FakeFS(path('dummypackage2/dist/dummypackage-0.1.tar.gz'))
     with patch('cheeseprism.views.event.PackageAdded',
                side_effect=RuntimeError('Kaboom')):
         with patch('path.path.write_bytes'):
             with self.assertRaises(RuntimeError):
                 upload(context, request)
Exemplo n.º 20
0
    def test_add_version_to_leaf_nodups(self):
        idx = self.make_one()

        name = 'dummypackage'
        idx.regenerate_leaf(name)

        distpath = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        distpath.copy(idx.path / distpath.name)

        data = idx.add_version_to_leaf(distpath, name)
        assert idx.path.exists()


        data = idx.add_version_to_leaf(distpath, name)
        assert len(data) == 2
Exemplo n.º 21
0
 def test_upload_raises_packageadded(self):
     """
     If adding the package raises an error, an exception should be logged
     """
     from cheeseprism.views import upload
     self.setup_event()
     context, request = self.base_cr
     request.method = 'POST'
     request.POST['content'] = FakeFS(
         path('dummypackage2/dist/dummypackage-0.1.tar.gz'))
     with patch('cheeseprism.views.event.PackageAdded',
                side_effect=RuntimeError('Kaboom')):
         with patch('path.path.write_bytes'):
             with self.assertRaises(RuntimeError):
                 upload(context, request)
Exemplo n.º 22
0
def test_envfactory_makes_loaders():
    from cheeseprism.index import EnvFactory
    env = EnvFactory.from_str(
        'pkg:cheeseprism pkg:cheeseprism#templates/fake file:/tmp/ %s' %
        path(__file__).parent)
    assert isinstance(env.loader, jinja2.loaders.ChoiceLoader)
    assert len(env.loader.loaders) == 5
    # is this backwards?
    assert env.loader.loaders[0].searchpath[0].endswith(
        'tests'), env.loader.loaders[1].searchpath
    assert env.loader.loaders[1].searchpath == ['/tmp/']
    assert env.loader.loaders[
        -1].package_path == 'templates/index', env.loader.loaders[
            -1].package_path
    assert env.loader.loaders[-2].package_path == 'templates'
    assert env.loader.loaders[-3].package_path == 'templates/fake'
Exemplo n.º 23
0
 def test_upload(self, wb):
     from cheeseprism.views import upload
     self.setup_event()
     context, request = self.base_cr
     request.method = 'POST'
     request.POST['content'] = FakeFS(
         path('dummypackage/dist/dummypackage-0.0dev.tar.gz'))
     with patch('cheeseprism.index.IndexManager.pkginfo_from_file',
                return_value=stuf(name='dummycode',
                                  version='0.0dev')) as pkif:
         res = upload(context, request)
         assert pkif.called
         assert 'PackageAdded' in self.event_results
         assert self.event_results['PackageAdded'][
             0].name == pkif.return_value.name
     assert res.headers == {'X-Swalow-Status': 'SUCCESS'}
Exemplo n.º 24
0
    def test_regenerate_leaf_html_free(self):
        self.im = self.make_one()
        self.im.write_html = False
        [x for x in self.im.regenerate_all()]

        new_arch = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        new_arch.copy(self.im.path)
        added = self.im.path / new_arch.name

        info = self.im.pkginfo_from_file(added)
        out = self.im.regenerate_leaf(info.name)
        with open(out) as fd:
            data = json.load(fd)
        assert new_arch.name in set([x['filename'] for x in data])
        symlink = out.parent / new_arch.name
        assert symlink.exists() is True
Exemplo n.º 25
0
    def test_regenerate_leaf_html_free(self):
        self.im = self.make_one()
        self.im.write_html = False
        [x for x in self.im.regenerate_all()]

        new_arch = here / path('dummypackage2/dist/dummypackage-0.1.tar.gz')
        new_arch.copy(self.im.path)
        added = self.im.path / new_arch.name

        info = self.im.pkginfo_from_file(added)
        out = self.im.regenerate_leaf(info.name)
        with open(out) as fd:
            data = json.load(fd)
        assert new_arch.name in set([x['filename'] for x in data])
        symlink = out.parent / new_arch.name
        assert symlink.exists() is True
Exemplo n.º 26
0
    def test_upload_w_rename(self):
        from cheeseprism.views import upload
        self.setup_event()
        context, request = self.base_cr

        request._namer = utils.strip_master
        request.method = 'POST'
        request.POST['content'] = FakeFS(path('mastertest-0.0-master.tar.gz'))

        def test_pkif(p, moe):
            assert p.basename() == u'mastertest-0.0.tar.gz'
            return stuf(name='mastertest', version='0.0-master')

        with patch('cheeseprism.index.IndexManager.pkginfo_from_file',
                   side_effect=test_pkif) as pkif:

            res = upload(context, request)
            assert pkif.called

        assert res.headers == {'X-Swalow-Status': 'SUCCESS'}
Exemplo n.º 27
0
    def test_upload_w_rename(self):
        from cheeseprism.views import upload
        self.setup_event()
        context, request = self.base_cr

        request._namer = utils.strip_master
        request.method = 'POST'
        request.POST['content'] = FakeFS(path('mastertest-0.0-master.tar.gz'))

        def test_pkif(p, moe):
            assert p.basename() == 'mastertest-0.0.tar.gz'
            return stuf(name='mastertest', version='0.0-master')

        with patch('cheeseprism.index.IndexManager.pkginfo_from_file',
                   side_effect=test_pkif) as pkif:

            res = upload(context, request)
            assert pkif.called

        assert res.headers == {'X-Swalow-Status': 'SUCCESS'}
Exemplo n.º 28
0
from cheeseprism.utils import path

here = path(__name__).parent
testdir = here / 'test-indexes/test-main'

def test_main():
    """
    sanity check for code that creates wsgi app
    """
    from cheeseprism.wsgiapp import main
    globconf = dict()
    app = main(globconf, **{'cheeseprism.index_templates':'',
                            'cheeseprism.file_root': testdir,
                            'cheeseprism.data_json': 'data.json'})
    assert app

def teardown():
    if testdir.exists():
        testdir.rmtree()
Exemplo n.º 29
0
 def get_base(cls):
     return path(resource_spec(cls.index_parent))
Exemplo n.º 30
0
from ConfigParser import ConfigParser
from cheeseprism.utils import path
from cheeseprism.utils import resource_spec
from itertools import count
from mock import patch
from pprint import pformat as pprint
from pyramid.decorator import reify
import logging
import time
import unittest


logger = logging.getLogger(__name__)
here = path(__file__).parent


class FunctionalTests(unittest.TestCase):
    testdir = here / 'test-indexes'
    dummy = here / "dummypackage/dist/dummypackage-0.0dev.tar.gz"
    counter = count()
    index_parent = here / "test-indexes"
    pipcache = here / "pipcache"
    devini = here / 'development.ini'

    dummy = here / "dummypackage/dist/dummypackage-0.0dev.tar.gz"

    @classmethod
    def get_base(cls):
        return path(resource_spec(cls.index_parent))

    base = reify(lambda self: self.get_base())
Exemplo n.º 31
0
from cheeseprism.utils import path

here = path(__name__).parent
testdir = here / 'test-indexes/test-main'


def test_main():
    """
    sanity check for code that creates wsgi app
    """
    from cheeseprism.wsgiapp import main
    globconf = dict()
    app = main(
        globconf, **{
            'cheeseprism.index_templates': '',
            'cheeseprism.file_root': testdir,
            'cheeseprism.data_json': 'data.json'
        })
    assert app


def teardown():
    if testdir.exists():
        testdir.rmtree()
Exemplo n.º 32
0
from cheeseprism.resources import App
from cheeseprism.utils import path
from contextlib import contextmanager
from mock import Mock
from mock import patch
from pyramid import testing
from pyramid.decorator import reify
from pyramid.events import subscriber
from pyramid.httpexceptions import HTTPFound
from stuf import stuf
from .test_pipext import PipExtBase
import futures
import itertools
import unittest

here = path(__file__).parent


def test_instructions():
    from cheeseprism.views import instructions
    assert instructions(None, None)


class ViewTests(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

    def setup_event(self):
        self.event_results = {}
        from cheeseprism.event import IPackageEvent
Exemplo n.º 33
0
def test_envfactory_makes_loaders():
    from cheeseprism.index import EnvFactory
    env = EnvFactory.from_str('pkg:cheeseprism pkg:cheeseprism#templates/fake file:/tmp/ %s' %path(__file__).parent)
    assert isinstance(env.loader, jinja2.loaders.ChoiceLoader)
    assert len(env.loader.loaders) == 5
    # is this backwards?
    assert env.loader.loaders[0].searchpath[0].endswith('tests'),  env.loader.loaders[1].searchpath
    assert env.loader.loaders[1].searchpath == ['/tmp/']
    assert env.loader.loaders[-1].package_path == 'templates/index', env.loader.loaders[-1].package_path
    assert env.loader.loaders[-2].package_path == 'templates'
    assert env.loader.loaders[-3].package_path == 'templates/fake'
Exemplo n.º 34
0
 def get_base(cls):
     return path(resource_spec(cls.index_parent))