当前位置: 首页>>代码示例>>Python>>正文


Python SpreadsheetResponseMixin.render_setup方法代码示例

本文整理汇总了Python中spreadsheetresponsemixin.SpreadsheetResponseMixin.render_setup方法的典型用法代码示例。如果您正苦于以下问题:Python SpreadsheetResponseMixin.render_setup方法的具体用法?Python SpreadsheetResponseMixin.render_setup怎么用?Python SpreadsheetResponseMixin.render_setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spreadsheetresponsemixin.SpreadsheetResponseMixin的用法示例。


在下文中一共展示了SpreadsheetResponseMixin.render_setup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RenderSetupTests

# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import render_setup [as 别名]
class RenderSetupTests(TestCase):
    def setUp(self):
        self.mixin = SpreadsheetResponseMixin()
        self.mixin.generate_headers = mock.MagicMock()
        self.mixin.queryset = MockModel.objects.all()
        self.fields = (u'title',)

    def test_if_no_self_queryset_raise_improperlyconfigured(self):
        delattr(self.mixin, 'queryset')
        with pytest.raises(NotImplementedError):
            list(self.mixin.render_setup())

    def test_get_fields_is_called_with_kwargs(self):
        self.mixin.get_fields = mock.MagicMock()
        self.mixin.render_setup(a=1, b=2)
        self.mixin.get_fields.assert_called_once_with(a=1, b=2)

    def test_generate_data_is_called_once_with_fields_and_queryset(self):
        self.mixin.generate_data = mock.MagicMock()
        qs = MockModel.objects.all()
        self.mixin.render_excel_response(queryset=qs, fields=self.fields)
        self.mixin.generate_data.assert_called_once_with(fields=self.fields)

    def test_if_no_headers_passed_generate_headers_called(self):
        self.mixin.render_excel_response(fields=self.fields)
        self.mixin.generate_headers.assert_called_once_with(MockModel,
                                                            fields=self.fields)

    def test_returns_attachment_with_correct_filename(self):
        expected_disposition = 'attachment; filename="export.csv"'
        response = self.mixin.render_csv_response()
        actual_disposition = response._headers['content-disposition'][1]
        assert actual_disposition == expected_disposition

        self.mixin.filename = 'data.dump'

        expected_disposition = 'attachment; filename="data.dump"'
        response = self.mixin.render_csv_response()
        actual_disposition = response._headers['content-disposition'][1]
        assert actual_disposition == expected_disposition

        expected_disposition = 'attachment; filename="data.dump"'
        response = self.mixin.render_excel_response()
        actual_disposition = response._headers['content-disposition'][1]
        assert actual_disposition == expected_disposition

        delattr(self.mixin, 'filename')
        self.mixin.filename_base = 'data.dump'

        expected_disposition = 'attachment; filename="data.dump.csv"'
        response = self.mixin.render_csv_response()
        actual_disposition = response._headers['content-disposition'][1]
        assert actual_disposition == expected_disposition

        expected_disposition = 'attachment; filename="data.dump.xlsx"'
        response = self.mixin.render_excel_response()
        actual_disposition = response._headers['content-disposition'][1]
        assert actual_disposition == expected_disposition
开发者ID:aptivate,项目名称:django-spreadsheetresponsemixin,代码行数:60,代码来源:test_views.py

示例2: RenderSetupTests

# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import render_setup [as 别名]
class RenderSetupTests(TestCase):
    def setUp(self):
        self.mixin = SpreadsheetResponseMixin()
        self.mixin.generate_headers = mock.MagicMock()
        self.mixin.queryset = MockModel.objects.all()
        self.fields = (u'title',)

    def test_get_fields_is_called_with_kwargs(self):
        self.mixin.get_fields = mock.MagicMock()
        self.mixin.render_setup(a=1, b=2)
        self.mixin.get_fields.assert_called_once_with(a=1, b=2)

    def test_generate_data_is_called_once_with_fields_and_queryset(self):
        self.mixin.generate_data = mock.MagicMock()
        self.mixin.render_excel_response(queryset='test', fields=self.fields)
        self.mixin.generate_data.assert_called_once_with(queryset='test',
                                                         fields=self.fields)

    def test_if_no_headers_passed_generate_headers_called(self):
        self.mixin.render_excel_response(fields=self.fields)
        self.mixin.generate_headers.assert_called_once_with(self.mixin.data,
                                                            fields=self.fields)
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:24,代码来源:test_views.py


注:本文中的spreadsheetresponsemixin.SpreadsheetResponseMixin.render_setup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。