[web] assert that CubicWebPublisher.handle_request returns bytes
importosfromos.pathimportjoin,dirnamefromshutilimportrmtreeimporterrnoimporttempfilefromunittestimportTestCase,mainfromcubicweb.web.propertysheetimportPropertySheet,lazystrDATADIR=join(dirname(__file__),'data')classPropertySheetTC(TestCase):defsetUp(self):uicache=join(DATADIR,'uicache')try:os.makedirs(uicache)exceptOSErroraserr:iferr.errno!=errno.EEXIST:raiseself.cachedir=tempfile.mkdtemp(dir=uicache)deftearDown(self):rmtree(self.cachedir)defdata(self,filename):returnjoin(DATADIR,filename)deftest(self):ps=PropertySheet(self.cachedir,datadir_url='http://cwtest.com')ps.load(self.data('sheet1.py'))ps.load(self.data('sheet2.py'))# defined by sheet1self.assertEqual(ps['logo'],'http://cwtest.com/logo.png')# defined by sheet1, overriden by sheet2self.assertEqual(ps['bgcolor'],'#FFFFFF')# defined by sheet2self.assertEqual(ps['fontcolor'],'black')# defined by sheet1, extended by sheet2self.assertEqual(ps['stylesheets'],['http://cwtest.com/cubicweb.css','http://cwtest.com/mycube.css'])# lazy string defined by sheet1self.assertIsInstance(ps['lazy'],lazystr)self.assertEqual(str(ps['lazy']),'#FFFFFF')# test compilationself.assertEqual(ps.compile('a {bgcolor: %(bgcolor)s; size: 1%;}'),'a {bgcolor: #FFFFFF; size: 1%;}')self.assertEqual(ps.process_resource(DATADIR,'pouet.css'),self.cachedir)self.assertIn('pouet.css',ps._cache)self.assertFalse(ps.need_reload())os.utime(self.data('sheet1.py'),None)self.assertIn('pouet.css',ps._cache)self.assertTrue(ps.need_reload())self.assertIn('pouet.css',ps._cache)ps.reload()self.assertNotIn('pouet.css',ps._cache)self.assertFalse(ps.need_reload())ps.process_resource(DATADIR,'pouet.css')# put in cacheos.utime(self.data('pouet.css'),None)self.assertFalse(ps.need_reload())self.assertNotIn('pouet.css',ps._cache)if__name__=='__main__':main()