def testNotFound(self): try: testRoot().lookupComponent('noSuchNameShouldBeFound') except exceptions.NameNotFound: pass else: raise AssertionError("Should've raised NameNotFound")
def testDataURL(self): from peak.naming.factories.openable import ConstantStream factory = ConstantStream('abcdefg') assert factory.open('b').read() == "abcdefg" factory = testRoot().lookupComponent('data:,abcdefg') assert factory.open('b').read() == "abcdefg" factory = testRoot().lookupComponent('data:;base64,' + quote('abcdefg'.encode('base64'))) assert factory.open('b').read() == "abcdefg"
def setUp(self, **kw): kw.setdefault('parent', testRoot()) self.xml_parser = config.XMLParser(web.SITEMAP_SCHEMA(testRoot()), sm_globals=globals(), **kw) self.parse = self.xml_parser.parse self.nparser = nparser = self.xml_parser.makeParser() self.startElement = nparser.startElement self.endElement = nparser.endElement nparser._beforeParsing(self.xml_parser.parseFunctions()) self.finish = nparser._afterParsing self.policy = web.TestPolicy(ResourceApp1(testRoot()))
def setUp(self,**kw): self.xml_parser = config.XMLParser( web.TEMPLATE_SCHEMA(testRoot()), pwt_document = web.TemplateDocument(testRoot()), **kw ) self.parse = self.xml_parser.parse self.nparser = nparser = self.xml_parser.makeParser() self.startElement = nparser.startElement self.endElement = nparser.endElement nparser._beforeParsing(self.xml_parser.parseFunctions()) self.finish = nparser._afterParsing self.policy = web.TestPolicy(TestApp(testRoot()))
def testOutput(self): s = StringIO() dm = HTMLDocument(testRoot(), text=sample_input, stream=s) storage.beginTransaction(dm) try: doc = dm.document table, = doc.tables r1, r2, r3 = table.rows r1.cells[0].ignore() r1.cells[0].text = 'TESTED' r2.cells[0].right() r2.cells[0].text = "a one" r2.cells[1].wrong() r2.cells[1].text = "& a two" r3.cells[1].assertEqual('my') r3.cells[2].annotation = "(or sandal)" r1.addCell(dm.newItem(Cell)) r1.cells[-1].text = 'extra' r1.cells[-1].ignore() r4 = dm.newItem(Row) table.addRow(r4) r4.addCell(dm.newItem(Cell)) r4.addCell(dm.newItem(Cell)) r4.cells[0].text = 'extra' r4.cells[1].text = 'stuff' r4.cells[1].exception(dummy_exc) storage.commitTransaction(dm) except: storage.abortTransaction(dm) raise self.assertEqual(s.getvalue(), sample_output)
def testTraverseLocationId(self): ctx = self.policy.newContext(start=self.app) id1 = '++id++spammity' id2 = '++id++foo.bar' key1 = web.LOCATION_ID('spammity') key2 = web.LOCATION_ID('foo.bar') # check default/error behavior self.invokeHandler(ctx,web.traverseLocationId,id1,fail=1) self.assertRaises(web.NotFound, ctx.traverseName, id1) # check direct find, no path item = binding.Configurable(testRoot()) ctx1 = ctx.childContext('test',item) item.registerProvider(key1,config.Value(web.TraversalPath('.'))) ctx2 = ctx1.traverseName(id1) self.failUnless(ctx2 is ctx1) # check indirect find, no path ctx3 = ctx1.childContext('test2',binding.Component()) self.failUnless(ctx3.traverseName(id1) is ctx2) # check direct find, with path item.registerProvider(key2,config.Value(web.TraversalPath('../foo'))) self.failUnless(ctx1.traverseName(id2).current is self.app.foo) # check indirect find, with path self.failUnless(ctx3.traverseName(id2).current is self.app.foo) # check object w/no _getConfigData ctx4 = ctx1.childContext('test2',None) self.failUnless(ctx4.traverseName(id1) is ctx2) self.failUnless(ctx4.traverseName(id2).current is self.app.foo)
def setUp(self): self.m = m = UML_DM(testRoot()) self.pkg = pkg = m.Package() pkg.name = 'SomePackage' self.klass = klass = self.m.Class() klass.name = 'FooClass' pkg.addOwnedElement(klass)
def setUp(self): self.url_base = self.default_url_base + self.script_name self.ob1 = object() self.ob2 = object() self.ob3 = object() self.root = TestApp(testRoot()) self.policy = web.TestPolicy(self.root) self.ctx = self.policy.newContext({'SCRIPT_NAME':self.script_name})
def testExtendedLocation(self): self.setUp(sm_included_from={ 'name': 'foo', 'class': 'TestLocation' }, parent=web.Location(testRoot())) self.startElement('location', []) loc = self.endElement('location') self.assertEqual(loc.getComponentName(), 'foo') self.failUnless(isinstance(loc, TestLocation))
def setUp(self): svcArea = config.ServiceArea(testRoot()) self.data = UtilityData(svcArea, 'data') self.data.aService.registerProvider( ISampleUtility1, lambda foundIn, configKey, forObj: makeAUtility(forObj)) svcArea.registerProvider(config.FactoryFor(ISampleUtility2), config.Value(makeAUtility)) self.data.aService.registerProvider( ISampleUtility2, config.CreateViaFactory(ISampleUtility2))
def testSubObjectRejection(self): # Files and templates shouldn't allow subitems in PATH_INFO paths = 'peak.web/resource_defaults.ini', 'peak.web.tests/template1' policy = web.TestPolicy(ResourceApp1(testRoot())) for path in paths: try: policy.simpleTraverse('/++resources++/%s/subitem' % path, True) except web.NotFound,v: self.assertEqual(v.args[0], "subitem") else: raise AssertionError("Should have raised NotFound:", path)
def checkLoadPkgFile(self): for path in "y", "z.foo", "baz/spam": address = "pkgfile:%s/%s" % (__name__, path) for pkgfile in [ config.packageFile(__name__, path), testRoot().lookupComponent(address) ]: self.assertEqual(pkgfile.address, address) self.assertEqual( pkgfile.open('t').read(), "loaded: " + join(dirname(__file__), *path.split('/')))
def testURLcalculations(self): # Root locations: direct children of a non-IPlace parent r=web.Resource(testRoot()) self.assertEqual(r.place_url,'') r=web.Resource(testRoot(),'foo') self.assertEqual(r.place_url,'') # Skin path is resource prefix policy = web.TestPolicy(ResourceApp1(testRoot())) ctx = policy.simpleTraverse('/++resources++', False) self.assertEqual(ctx.current.place_url, '++resources++') # Skin children should include resource prefix ctx2 = ctx.traverseName('peak.web') self.assertEqual(ctx2.current.place_url, '++resources++/peak.web') # check absolute ("mount point") URL r=web.Resource(testRoot(),'foo',place_url="http://example.com/foo") ctx = policy.newContext() ctx = ctx.childContext('foo',r) self.assertEqual(ctx.absoluteURL, ctx.current.place_url)
def checkEnviron(self): from os import environ # retry multiple times to verify re-get is safe... app = testRoot() ps = config.Namespace('environ', app) for r in range(3): for k, v in environ.items(): self.assertEqual(ps[k], v) ek = environ.keys() ek.sort() pk = ps.keys() pk.sort() self.assertEqual(ek, pk) # verify namespace keys
def testRunner(self): # Test a file runner, action processor, and model processor from peak.ddt.runners import HTMLRunner runner = HTMLRunner( testRoot(), argv=['ddt', 'pkgfile:peak.ddt.tests/Action_Test.html'], stdout=StringIO(), stderr=StringIO(), ) runner.run() self.assertEqual(runner.stderr.getvalue().strip(), "23 right, 1 wrong, 0 ignored, 1 exceptions")
def checkSmartProps(self): app = testRoot() obj = binding.Configurable(app) config.loadConfigFile(obj, config.packageFile(__name__, 'test_links.ini')) for k in '.spew,.blue,.knew'.split(','): prop = PropertyName('foo.bar.rule%s' % k) suff = k.startswith('.') and k[1:] or k self.assertEqual( config.lookup(obj, prop), (obj.__instance_offers__, prop, 'foo.bar.rule.', suff, obj)) assert config.lookup(obj, 'foo.bar.spam') is testRoot assert config.lookup(obj, 'foo.bar.baz') is testRoot
def testParsing(self): dm = HTMLDocument(testRoot(), text=sample_input) storage.beginTransaction(dm) try: self.assertEqual( docTexts(dm.document), [ # doc [ # table 1 ['test parser'], ['one', 'two'], ["buckle", "your", "shoe"] ] ]) finally: storage.abortTransaction(dm)
def setUp(self): from test_templates import TestApp self.app = TestApp(testRoot()) self.policy = web.TestPolicy(self.app) self.foo_skin = web.Skin() foo_dapter = lambda *args: self bar_dapter = lambda *args: "baz" foo_handler = lambda ctx,o,ns,nm,qn,d: ctx.childContext(qn,self) bar_handler = lambda ctx,o,ns,nm,qn,d: ctx.childContext(qn,"baz") self.policy.registerProvider( web.NAMESPACE_NAMES+'.foo', config.Value(foo_dapter) ) self.policy.registerProvider( web.NAMESPACE_NAMES+'.bar', config.Value(bar_dapter) ) self.policy.registerProvider( 'peak.web.skins.foo', config.Value(self.foo_skin) ) self.app.registerView(int,'foo',foo_handler) self.app.registerView(str,'foo',bar_handler)
def testWord(self): dm = HTMLDocument(testRoot(), text=config.packageFile( __name__, 'word_test.html').open('t').read()) storage.beginTransaction(dm) try: self.assertEqual( docTexts(dm.document), [ # doc [ # table 1 ['sample.fixture1'], ["one", "buckle", "shoe", "four"], ["two", "your", "three", "je t'adore"] ] ]) finally: storage.abortTransaction(dm)
def testRecords(self): # Test recordchecker with lots of variants of the same data app = NumbersApp(testRoot()) from peak.ddt.runners import HTMLRunner testURL = 'pkgfile:peak.ddt.tests/RecordChecker_Tests.html' resultURL = 'pkgfile:peak.ddt.tests/RecordChecker_Results.html' output = app.lookupComponent(resultURL).open('t').read() for records in forwards, backwards, sorted, revsorted, _random: app.records = records runner = HTMLRunner( app, argv=['ddt', testURL], stdout=StringIO(), stderr=StringIO(), ) runner.run() self.assertEqual(runner.stdout.getvalue().replace('\r\n', '\n'), output.replace('\r\n', '\n'))
def testParseXML(self): nspre = 'peak.config.xml_namespaces.' c = binding.Configurable(testRoot()) c.registerProvider(nspre + 'foo', config.Value('bar')) config.processXML(c, "pkgfile:peak.web.tests/template1.pwt")
def testParseIni(self): c = binding.Configurable(testRoot()) config.ConfigReader(c).readString(xml_cfg) for args, result in xml_values: self.assertEqual(c.lookupComponent(config.XMLKey(*args)), result)
def testRoot(self): config.registeredProtocol(testRoot(), 'miscellaneous.thing')
def setUp(self): self.S = config.ServiceArea(testRoot()) self.A = binding.Configurable(self.S, 'A') self.B = binding.Configurable(self.S, 'B')
def testRefLookup(self): url = 'ref:peak.naming.tests.TestFactory@xyz' self.assertEqual(testRoot().lookupComponent(url), ['xyz'])
def testRefRestore(self): ref = naming.Reference('peak.naming.tests.TestFactory', ['x', 'y', 'z']) self.assertEqual(ref.restore(testRoot(), ''), ['x', 'y', 'z'])
def parse(url, base=None): return naming.parseURL(testRoot(), url, base)
def checkSetProp(self): app = testRoot() name = PropertyName('peak.config.tests.foo') app.registerProvider(name, config.Value(1)) assert config.lookup(app, name) == 1
def setUp(self): self.data = DescriptorData(testRoot(), 'data')
def checkSchemaLookup(self): from peak.config.load_zconfig import ConfigLoader ob = testRoot().lookupComponent( 'ref:zconfig.schema@pkgfile:peak.running/EventDriven.xml') self.failUnless(isinstance(ob, ConfigLoader))