當前位置: 首頁>>代碼示例>>Python>>正文


Python ProductEnvironment.enable_component方法代碼示例

本文整理匯總了Python中multiproduct.env.ProductEnvironment.enable_component方法的典型用法代碼示例。如果您正苦於以下問題:Python ProductEnvironment.enable_component方法的具體用法?Python ProductEnvironment.enable_component怎麽用?Python ProductEnvironment.enable_component使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在multiproduct.env.ProductEnvironment的用法示例。


在下文中一共展示了ProductEnvironment.enable_component方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ProductResourceTestCase

# 需要導入模塊: from multiproduct.env import ProductEnvironment [as 別名]
# 或者: from multiproduct.env.ProductEnvironment import enable_component [as 別名]
class ProductResourceTestCase(MultiproductTestCase):
    def setUp(self):
        self._mp_setup()
        self.global_env = self.env
        self._load_product_from_data(self.global_env, u'xü')

        self.env = ProductEnvironment(self.global_env, self.default_product)
        self.env1 = ProductEnvironment(self.global_env, u'xü')

        self._load_default_data(self.global_env)
        self._load_default_data(self.env1)

        # Enable product system component in product context
        self.env.enable_component(MultiProductSystem)

    def tearDown(self):
        self.global_env.reset_db()
        self.global_env = self.env = None
開發者ID:mohsadki,項目名稱:dargest,代碼行數:20,代碼來源:resource.py

示例2: ProductModuleTestCase

# 需要導入模塊: from multiproduct.env import ProductEnvironment [as 別名]
# 或者: from multiproduct.env.ProductEnvironment import enable_component [as 別名]
class ProductModuleTestCase(RequestHandlerTestCase):
    def setUp(self):
        self._mp_setup()
        self.global_env = self.env
        self.env = ProductEnvironment(self.global_env, self.default_product)

        self.global_env.enable_component(TestRequestSpy)
        self.env.enable_component(TestRequestSpy)
        TestRequestSpy(self.global_env).testMatch = self._assert_product_match
        PermissionSystem(self.global_env).grant_permission('testuser', 'PRODUCT_CREATE')
        PermissionSystem(self.global_env).grant_permission('testuser', 'PRODUCT_VIEW')
        PermissionSystem(self.global_env).grant_permission('testuser', 'PRODUCT_MODIFY')

    def tearDown(self):
        self.global_env.reset_db()
        self.env = self.global_env = None

    expectedPrefix = None
    expectedPathInfo = None

    def _assert_product_match(self, req, handler):
        self.assertIs(ProductModule(self.global_env), handler)
        self.assertEqual(self.expectedPrefix, req.args['productid'],
                         "Unexpected product prefix")
        self.assertEqual(self.expectedPathInfo, req.args['pathinfo'],
                         "Unexpected sub path")

    def test_product_list(self):
        spy = self.global_env[TestRequestSpy]
        self.assertIsNot(None, spy)

        req = self._get_request_obj(self.global_env)
        req.authname = 'testuser'
        req.environ['PATH_INFO'] = '/products'

        mps = MultiProductSystem(self.global_env)
        def assert_product_list(req, template, data, content_type):
            self.assertEquals('product_list.html', template)
            self.assertIs(None, content_type)
            self.assertEquals([mps.default_product_prefix,
                               self.default_product],
                              [p.prefix for p in data.get('products')])
            self.assertTrue('context' in data)
            ctx = data['context']
            self.assertEquals('product', ctx.resource.realm)
            self.assertEquals(None, ctx.resource.id)

        spy.testProcessing = assert_product_list
        with self.assertRaises(RequestDone):
            self._dispatch(req, self.global_env)

    def test_product_new(self):
        spy = self.global_env[TestRequestSpy]
        self.assertIsNot(None, spy)

        req = self._get_request_obj(self.global_env)
        req.authname = 'testuser'
        req.environ['PATH_INFO'] = '/products'
        req.environ['QUERY_STRING'] = 'action=new'

        def assert_product_new(req, template, data, content_type):
            self.assertEquals('product_edit.html', template)
            self.assertIs(None, content_type)
            self.assertFalse('products' in data)
            self.assertTrue('context' in data)
            ctx = data['context']
            self.assertEquals('product', ctx.resource.realm)
            self.assertEquals(None, ctx.resource.id)

        spy.testProcessing = assert_product_new
        with self.assertRaises(RequestDone):
            self._dispatch(req, self.global_env)

    def test_product_view(self):
        spy = self.global_env[TestRequestSpy]
        self.assertIsNot(None, spy)

        def assert_product_view(req, template, data, content_type):
            self.assertEquals('product_view.html', template)
            self.assertIs(None, content_type)
            self.assertFalse('products' in data)

            self.assertTrue('context' in data)
            ctx = data['context']
            self.assertEquals('product', ctx.resource.realm)
            self.assertEquals(real_prefix, ctx.resource.id)

            self.assertTrue('product' in data)
            self.assertEquals(real_prefix, data['product'].prefix)

        spy.testProcessing = assert_product_view

        # Existing product
        req = self._get_request_obj(self.global_env)
        req.authname = 'testuser'
        req.environ['PATH_INFO'] = '/products/%s' % (self.default_product,)

        real_prefix = self.default_product
        self.expectedPrefix = self.default_product
        self.expectedPathInfo = ''
#.........這裏部分代碼省略.........
開發者ID:mohsadki,項目名稱:dargest,代碼行數:103,代碼來源:web_ui.py

示例3: ProductModuleTestCase

# 需要導入模塊: from multiproduct.env import ProductEnvironment [as 別名]
# 或者: from multiproduct.env.ProductEnvironment import enable_component [as 別名]
class ProductModuleTestCase(RequestHandlerTestCase):
    def setUp(self):
        self._mp_setup()
        self.global_env = self.env
        self.env = ProductEnvironment(self.global_env, self.default_product)

        self.global_env.enable_component(TestRequestSpy)
        self.env.enable_component(TestRequestSpy)
        TestRequestSpy(self.global_env).testMatch = self._assert_product_match
        PermissionSystem(self.global_env).grant_permission("testuser", "PRODUCT_CREATE")
        PermissionSystem(self.global_env).grant_permission("testuser", "PRODUCT_VIEW")
        PermissionSystem(self.global_env).grant_permission("testuser", "PRODUCT_MODIFY")

    def tearDown(self):
        self.global_env.reset_db()
        self.env = self.global_env = None

    expectedPrefix = None
    expectedPathInfo = None

    def _assert_product_match(self, req, handler):
        self.assertIs(ProductModule(self.global_env), handler)
        self.assertEqual(self.expectedPrefix, req.args["productid"], "Unexpected product prefix")
        self.assertEqual(self.expectedPathInfo, req.args["pathinfo"], "Unexpected sub path")

    def test_product_list(self):
        spy = self.global_env[TestRequestSpy]
        self.assertIsNot(None, spy)

        req = self._get_request_obj(self.global_env)
        req.authname = "testuser"
        req.environ["PATH_INFO"] = "/products"

        mps = MultiProductSystem(self.global_env)

        def assert_product_list(req, template, data, content_type):
            self.assertEquals("product_list.html", template)
            self.assertIs(None, content_type)
            self.assertEquals(
                [mps.default_product_prefix, self.default_product], [p.prefix for p in data.get("products")]
            )
            self.assertTrue("context" in data)
            ctx = data["context"]
            self.assertEquals("product", ctx.resource.realm)
            self.assertEquals(None, ctx.resource.id)

        spy.testProcessing = assert_product_list
        with self.assertRaises(RequestDone):
            self._dispatch(req, self.global_env)

    def test_product_new(self):
        spy = self.global_env[TestRequestSpy]
        self.assertIsNot(None, spy)

        req = self._get_request_obj(self.global_env)
        req.authname = "testuser"
        req.environ["PATH_INFO"] = "/products"
        req.environ["QUERY_STRING"] = "action=new"

        def assert_product_new(req, template, data, content_type):
            self.assertEquals("product_edit.html", template)
            self.assertIs(None, content_type)
            self.assertFalse("products" in data)
            self.assertTrue("context" in data)
            ctx = data["context"]
            self.assertEquals("product", ctx.resource.realm)
            self.assertEquals(None, ctx.resource.id)

        spy.testProcessing = assert_product_new
        with self.assertRaises(RequestDone):
            self._dispatch(req, self.global_env)

    def test_product_view(self):
        spy = self.global_env[TestRequestSpy]
        self.assertIsNot(None, spy)

        def assert_product_view(req, template, data, content_type):
            self.assertEquals("product_view.html", template)
            self.assertIs(None, content_type)
            self.assertFalse("products" in data)

            self.assertTrue("context" in data)
            ctx = data["context"]
            self.assertEquals("product", ctx.resource.realm)
            self.assertEquals(real_prefix, ctx.resource.id)

            self.assertTrue("product" in data)
            self.assertEquals(real_prefix, data["product"].prefix)

        spy.testProcessing = assert_product_view

        # Existing product
        req = self._get_request_obj(self.global_env)
        req.authname = "testuser"
        req.environ["PATH_INFO"] = "/products/%s" % (self.default_product,)

        real_prefix = self.default_product
        self.expectedPrefix = self.default_product
        self.expectedPathInfo = ""
        with self.assertRaises(RequestDone):
#.........這裏部分代碼省略.........
開發者ID:rvelezc,項目名稱:rafaelvelez.us-backup,代碼行數:103,代碼來源:web_ui.py


注:本文中的multiproduct.env.ProductEnvironment.enable_component方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。