示例#1
0
    def test_passing_args(self, Variable):
        class MockModel(object):
            pass
        class MockModelView(ModelView):
            model = MockModel
            def some_view(self, first_arg, second_arg=None):
                return "%s %s" % (first_arg, second_arg)

        class MockObject(object):
            pass

        template_model = Mock()
        template_model.resolve.return_value = MockModel()

        return_vals = [template_model, 'variable value']
        def popit(_):
            return return_vals.pop()
        Variable.side_effect = popit
        node = ModelViewNode('instance',
                             'some_view',
                             args=["'some string'"],
                             kwargs=dict(second_arg='otherthing'))
        context = Mock()
        self.failUnlessEqual(node.render(context),
                             'some string variable value')
示例#2
0
 def test_model_view_rendering_callable(self, Variable):
     class MockModel(object):
         pass
     class MockModelView(ModelView):
         model = MockModel
         def some_view(self):
             return "Output of some view"
     template_model = Mock()
     template_model.resolve.return_value = MockModel()
     Variable.return_value = template_model
     node = ModelViewNode('instance', 'some_view')
     context = Mock()
     self.failUnlessEqual(node.render(context),
                          'Output of some view')
示例#3
0
 def test_arglist_parsing(self):
     rest_args = ['one', 'two', 'three="haha"', "four=hehe"]
     args, kwargs = ModelViewNode.parse_arg_list(rest_args)
     self.failUnlessEqual(args, ['one', 'two'])
     self.failUnlessEqual(kwargs, dict(three='"haha"',
                                       four="hehe"))