def test_root_thead_pip_sync(self): with patch.dict('os.environ', {'PIP_DOWNLOAD_CACHE': resource_spec(self.pipcache)}): testapp = self.makeone({ 'cheeseprism.futures': 'thread', 'cheeseprism.pipcache_mirror': 'true' }) res = testapp.get('/index', status=200) assert 'WUT' in res.body
def makeone(self, xtra=None, index_name='test-func-index', count=None): from cheeseprism.wsgiapp import main cp = ConfigParser(dict(here=self.base)) with open(resource_spec(self.devini)) as fp: cp.readfp(fp) defaults = dict((x, cp.get('DEFAULT', x)) for x in cp.defaults()) count = count is None and self.count or count self.idxpath = index_path = self.base / ("%s-%s" %(count, index_name)) settings = { 'cheeseprism.file_root': index_path, 'cheeseprism.data_json': 'data.json' } settings = xtra and dict(settings, **xtra) or settings app = main(defaults, **settings) self.executor = app.registry['cp.executor'] from webtest import TestApp return TestApp(app)
def makeone(self, xtra=None, index_name='test-func-index', count=None): from cheeseprism.wsgiapp import main cp = ConfigParser(dict(here=self.base)) with open(resource_spec(self.devini)) as fp: cp.readfp(fp) defaults = dict((x, cp.get('DEFAULT', x)) for x in cp.defaults()) count = count is None and self.count or count self.idxpath = index_path = self.base / ("%s-%s" % (count, index_name)) settings = { 'cheeseprism.file_root': index_path, 'cheeseprism.data_json': 'data.json' } settings = xtra and dict(settings, **xtra) or settings app = main(defaults, **settings) self.executor = app.registry['cp.executor'] from webtest import TestApp return TestApp(app)
def get_base(cls): return path(resource_spec(cls.index_parent))
def test_root_thead_pip_sync(self): with patch.dict('os.environ', {'PIP_DOWNLOAD_CACHE': resource_spec(self.pipcache)}): testapp = self.makeone({'cheeseprism.futures':'thread', 'cheeseprism.pipcache_mirror':'true'}) res = testapp.get('/index', status=200) assert 'WUT' in res.body
class IndexTestCase(unittest.TestCase): counter = count() index_parent = "egg:CheesePrism#tests/test-indexes" tdir = path(resource_spec('egg:CheesePrism#tests')) dummy = here / "dummypackage/dist/dummypackage-0.0dev.tar.gz" @classmethod def get_base(cls): return path(resource_spec(cls.index_parent)) @property def base(self): return self.get_base() def make_one(self, index_name='test-index'): from cheeseprism import index self.count = next(self.counter) index_path = self.base / ("%s-%s" % (self.count, index_name)) return index.IndexManager(index_path) def setUp(self): #@@ factor out im creation self.im = self.make_one() self.dummy.copy(self.im.path) self.dummypath = self.im.path / self.dummy.name def test_register_archive(self): pkgdata, md5 = self.im.register_archive(self.dummypath) assert md5 == '3ac58d89cb7f7b718bc6d0beae85c282' assert pkgdata idxjson = self.im.data_from_path(self.im.datafile_path) assert md5 in idxjson assert idxjson[md5] == pkgdata def test_write_datafile(self): """ create and write archive data to index.json """ data = self.im.write_datafile(hello='computer') assert 'hello' in data assert self.im.datafile_path.exists() assert 'hello' in self.im.data_from_path(self.im.datafile_path) def test_write_datafile_w_existing_datafile(self): """ write data to an existing datafile """ data = self.im.write_datafile(hello='computer') assert self.im.datafile_path.exists() data = self.im.write_datafile(hello='operator') assert data['hello'] == 'operator' assert self.im.data_from_path( self.im.datafile_path)['hello'] == 'operator' def test_regenerate_index(self): 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.html' 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) @patch('cheeseprism.index.IndexManager.regenerate_leaf') def test_regenerate_leaf_event(self, rl): """ Cover event subscriber """ from cheeseprism.event import PackageAdded from cheeseprism.index import rebuild_leaf event = PackageAdded( self.im, self.tdir / path('dummypackage2/dist/dummypackage-0.1.tar.gz')) out = rebuild_leaf(event) assert out is not None assert rl.call_args == (('dummypackage', ), {}) def test_regenerate_leaf(self): [x for x in self.im.regenerate_all()] leafindex = self.im.path / 'dummypackage/index.html' new_arch = self.tdir / 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() @patch('pyramid.threadlocal.get_current_registry') def test_notify_packages_added(self, getreg): from cheeseprism.index import notify_packages_added pkg = stuf(name='dummypackage', version='0.1', filename=self.dummy.name) pkgs = pkg, index = Mock(name='index') index.path = self.im.path reg = getreg.return_value = Mock(name='registry') out = list(notify_packages_added(index, pkgs)) assert len(out) == 1 assert getreg.called assert reg.notify.called (event, ), _ = reg.notify.call_args assert event.im is index assert event.version == '0.1' assert event.name == 'dummypackage' @raises(StopIteration) def test_notify_packages_added_raises(self): from cheeseprism.index import notify_packages_added next(notify_packages_added(Mock(name='index'), [])) def tearDown(self): logger.debug("teardown: %s", self.count) dirs = self.base.dirs() logger.info(pprint(dirs)) logger.info(pprint([x.rmtree() for x in dirs]))