Ejemplo n.º 1
0
    def test_context(self):
        ##  Instantiate object with no context
        test_view = TemplateReportView(output_filename='output.pdf',
                                       template_name='template.rml')

        ##  Compare to results using Django's TemplateView
        test_view2 = TemplateView(output_filename='output.pdf',
                                  template_name='template.rml')

        ## Test with no context

        ## get context from each view
        context1 = test_view.get_context_data()
        context2 = test_view2.get_context_data()

        ## remove 'view' key from dictionary, if present
        try:
            del context1['view']
            del context2['view']
        except KeyError:
            pass  ## v1.4 doesn't add this key

        self.assertEqual(context1, context2)

        ## Test with additional context items added

        ## get context from each view
        context1 = test_view.get_context_data(cv='test', cv2='test2')
        context2 = test_view2.get_context_data(cv='test', cv2='test2')

        ## remove 'view' key from dictionary, if present
        try:
            del context1['view']
            del context2['view']
        except KeyError:
            pass  ## Django v1.4 doesn't add this key

        self.assertEqual(context1, context2)
 def test_type_check(self):
     """Assert that TemplateLastModified raises an error if not used with a TemplateView"""
     with pytest.raises(ValueError):
         ObjectLastModified()(TemplateView())
     with pytest.raises(ValueError):
         ObjectLastModified()(ListView())