示例#1
0
 def test_missing_resource(self):
     """ Raise KeyError if route doesn't match named paths """
     resource = IStaticResource()
     factory = MagicMock()
     resource.subobjects = {'myroute': factory}
     with self.assertRaises(KeyError):
         resource['foobar']
示例#2
0
 def test_static_resource(self):
     """ Generate next resource if path in map """
     resource = IStaticResource()
     factory = MagicMock()
     resource.subobjects = {'myroute': factory}
     result = resource['myroute']
     self.assertEqual(result, factory())
     # Set __parent__ and __name__
     self.assertEqual(result.__name__, 'myroute')
     self.assertEqual(result.__parent__, resource)
示例#3
0
 def test_nested_request_attr(self):
     """ ISmartLookupResource can fetch a request from a nested path """
     grandparent = IStaticResource()
     parent = IStaticResource()
     parent.__parent__ = grandparent
     resource = IStaticResource()
     resource.__parent__ = parent
     grandparent.request = object()
     self.assertEqual(resource.request, grandparent.request)