Esempio n. 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')
Esempio n. 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')