本文整理汇总了Python中spreadsheetresponsemixin.SpreadsheetResponseMixin类的典型用法代码示例。如果您正苦于以下问题:Python SpreadsheetResponseMixin类的具体用法?Python SpreadsheetResponseMixin怎么用?Python SpreadsheetResponseMixin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpreadsheetResponseMixin类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: GenerateXlsxTests
class GenerateXlsxTests(TestCase):
def setUp(self):
self.data = (('row1col1', 'row1col2'), ('row2col1', 'row2col2'))
self.mixin = SpreadsheetResponseMixin()
def _get_sheet(self, wb):
return wb.get_active_sheet()
def test_returns_workbook_if_no_file_passed(self):
assert type(self.mixin.generate_xlsx(self.data)) == Workbook
def test_if_file_is_passed_it_is_returned_with_content_added(self):
given_content = StringIO()
assert given_content.getvalue() == ''
self.mixin.generate_xlsx(self.data, file=given_content)
assert given_content.getvalue() > ''
def test_adds_row_of_data(self):
wb = self.mixin.generate_xlsx(self.data)
ws = self._get_sheet(wb)
assert ws.cell('A1').value == 'row1col1'
assert ws.cell('B2').value == 'row2col2'
def test_inserts_headers_if_provided(self):
headers = ('ColA', 'ColB')
wb = self.mixin.generate_xlsx(self.data, headers)
ws = self._get_sheet(wb)
assert ws.cell('A1').value == 'ColA'
assert ws.cell('B2').value == 'row1col2'
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:29,代码来源:test_views.py
示例2: GetRenderMethodTest
class GetRenderMethodTest(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
def test_raise_notimplemented_for_unknown_format(self):
with pytest.raises(NotImplementedError):
self.mixin.get_render_method('doc')
def test_returns_excel_response_method_for_excel_format(self):
expected_render_method = self.mixin.render_excel_response
assert self.mixin.get_render_method('excel') == expected_render_method
def test_csv_response_method_for_csv_format(self):
expected_render_method = self.mixin.render_csv_response
assert self.mixin.get_render_method('csv') == expected_render_method
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:15,代码来源:test_views.py
示例3: GetFormatTest
class GetFormatTest(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
def test_get_format_from_export_format_kwarg(self):
format = 'excel'
assert self.mixin.get_format(format=format) == format
def test_get_format_from_export_format_attribute(self):
format = 'csv'
self.mixin.format = format
assert self.mixin.get_format() == format
def test_raise_notimplemented_if_export_format_not_supplied(self):
with pytest.raises(NotImplementedError):
self.mixin.get_format()
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:16,代码来源:test_views.py
示例4: RenderExcelResponseTests
class RenderExcelResponseTests(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
MockModelFactory()
self.queryset = MockModel.objects.all()
self.mixin.queryset = self.queryset
def test_returns_httpresponse(self):
assert type(self.mixin.render_excel_response()) == HttpResponse
def test_returns_xlsx_content_type(self):
expected_content_type = \
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
response = self.mixin.render_excel_response()
actual_content_type = response._headers['content-type'][1]
assert actual_content_type == expected_content_type
def test_returns_attachment_content_disposition(self):
expected_disposition = 'attachment; filename="export.xlsx"'
response = self.mixin.render_excel_response()
actual_disposition = response._headers['content-disposition'][1]
assert actual_disposition == expected_disposition
def test_generate_xslx_is_called_with_data(self):
self.mixin.generate_xlsx = mock.MagicMock()
self.mixin.render_excel_response()
data = self.mixin.generate_data(self.queryset)
mut = self.mixin.generate_xlsx
assert mut.call_count == 1
assert list(mut.call_args.__getnewargs__()[0][1]['data']) == list(data)
def test_generate_xslx_is_called_with_headers(self):
self.mixin.generate_xlsx = mock.MagicMock()
headers = ('ColA', 'ColB')
self.mixin.render_excel_response(headers=headers)
mut = self.mixin.generate_xlsx
assert mut.call_count == 1
assert mut.call_args.__getnewargs__()[0][1]['headers'] == headers
def test_generate_xslx_is_called_with_response(self):
self.mixin.generate_xlsx = mock.MagicMock()
self.mixin.render_excel_response()
mut = self.mixin.generate_xlsx
assert mut.call_count == 1
assert type(mut.call_args.__getnewargs__()[0][1]['file']) \
== HttpResponse
开发者ID:tommorris,项目名称:django-spreadsheetresponsemixin,代码行数:46,代码来源:test_views.py
示例5: GenerateHeadersTests
class GenerateHeadersTests(TestCase):
def setUp(self):
MockModelFactory()
self.mixin = SpreadsheetResponseMixin()
self.data = self.mixin.generate_data(MockModel.objects.all())
def test_get_fields_defined_on_view(self):
fields = ('title', 'summary')
self.mixin.fields = fields
assert fields == self.mixin.get_fields()
def test_get_fields_from_kwargs(self):
fields = ('title', 'summary')
assert fields == self.mixin.get_fields(fields=fields)
def test_get_fields_from_model(self):
model = MockModelFactory()
self.mixin.model = model
assert ['id', 'title'] == self.mixin.get_fields()
def test_get_fields_from_queryset(self):
self.mixin.queryset = MockModel.objects.all()
assert ['id', 'title'] == self.mixin.get_fields()
def test_generate_headers_gets_headers_from_model_name(self):
assert self.mixin.generate_headers(self.data) == (u'Id', u'Title')
def test_generate_headers_only_returns_fields_if_fields_is_passed(self):
fields = ('title',)
assert self.mixin.generate_headers(self.data,
fields=fields) == (u'Title', )
开发者ID:tommorris,项目名称:django-spreadsheetresponsemixin,代码行数:32,代码来源:test_views.py
示例6: RenderCsvResponseTests
class RenderCsvResponseTests(TestCase):
def setUp(self):
MockModelFactory()
self.queryset = MockModel.objects.all()
self.mixin = SpreadsheetResponseMixin()
self.mixin.queryset = self.queryset
def test_returns_httpresponse(self):
assert type(self.mixin.render_csv_response()) == HttpResponse
def test_returns_csv_content_type(self):
expected_content_type = 'text/csv'
response = self.mixin.render_csv_response()
actual_content_type = response._headers['content-type'][1]
assert actual_content_type == expected_content_type
def test_returns_attachment_content_disposition(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
def test_generate_csv_is_called_with_data(self):
self.mixin.generate_csv = mock.MagicMock()
self.mixin.render_csv_response()
data = self.mixin.generate_data(self.queryset)
mut = self.mixin.generate_csv
assert mut.call_count == 1
assert list(mut.call_args.__getnewargs__()[0][1]['data']) == list(data)
def test_generate_csv_is_called_with_headers(self):
self.mixin.generate_csv = mock.MagicMock()
headers = ('ColA', 'ColB')
self.mixin.render_csv_response(headers=headers)
mut = self.mixin.generate_csv
assert mut.call_count == 1
assert mut.call_args.__getnewargs__()[0][1]['headers'] == headers
def test_generate_csv_is_called_with_response(self):
self.mixin.generate_csv = mock.MagicMock()
self.mixin.render_csv_response()
mut = self.mixin.generate_csv
assert mut.call_count == 1
assert type(mut.call_args.__getnewargs__()[0][1]['file']) \
== HttpResponse
开发者ID:tommorris,项目名称:django-spreadsheetresponsemixin,代码行数:45,代码来源:test_views.py
示例7: GetFilenameTest
class GetFilenameTest(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
def test_from_filename_kwarg(self):
filename = 'filename.kwarg'
assert self.mixin.get_filename(filename=filename) == filename
def test_from_filename_attribute(self):
filename = 'filename.attr'
self.mixin.filename = filename
assert self.mixin.get_filename() == filename
def test_default_return_with_no_extension_provided(self):
assert self.mixin.get_filename() == 'export.out'
def test_default_return_with_extension_provided(self):
assert self.mixin.get_filename(extension='blob') == 'export.blob'
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:18,代码来源:test_views.py
示例8: GenerateHeadersTests
class GenerateHeadersTests(TestCase):
def setUp(self):
MockModelFactory()
self.mixin = SpreadsheetResponseMixin()
self.data = self.mixin.generate_data(MockModel.objects.all())
def test_generate_headers_gets_headers_from_model_name(self):
assert self.mixin.generate_headers(self.data) == (u'Id', u'Title')
def test_generate_headers_keeps_fields_order(self):
fields = ('title', 'id')
headers = self.mixin.generate_headers(self.data, fields=fields)
assert headers == (u'Title', u'Id')
def test_generate_headers_only_returns_fields_if_fields_is_passed(self):
fields = ('title',)
assert self.mixin.generate_headers(self.data,
fields=fields) == (u'Title', )
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:18,代码来源:test_views.py
示例9: RenderSetupTests
class RenderSetupTests(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
MockModelFactory()
self.queryset = MockModel.objects.all()
self.mixin.queryset = self.queryset
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='testfields')
self.mixin.generate_data.assert_called_once_with(queryset='test',
fields='testfields')
def test_if_no_headers_passed_generate_headers_called(self):
self.mixin.generate_headers = mock.MagicMock()
fields = (u'title',)
self.mixin.render_excel_response(fields=fields)
self.mixin.generate_headers.assert_called_once_with(self.mixin.data,
fields=fields)
开发者ID:tommorris,项目名称:django-spreadsheetresponsemixin,代码行数:19,代码来源:test_views.py
示例10: GetFieldsTests
class GetFieldsTests(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
def test_if_fields_defined_on_view(self):
fields = ('title', 'summary')
self.mixin.fields = fields
assert self.mixin.get_fields() == fields
def test_get_fields_from_kwargs(self):
fields = ('title', 'summary')
assert self.mixin.get_fields(fields=fields) == fields
def test_get_fields_from_model(self):
self.mixin.model = MockModel
assert self.mixin.get_fields() == ['id', 'title']
def test_get_fields_from_queryset(self):
self.mixin.queryset = MockModel.objects.all()
assert self.mixin.get_fields() == ['id', 'title']
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:20,代码来源:test_views.py
示例11: GetFieldsTests
class GetFieldsTests(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
def test_if_fields_defined_on_view(self):
fields = ('title', 'summary')
self.mixin.fields = fields
assert self.mixin.get_fields() == fields
def test_get_fields_from_kwargs(self):
fields = ('title', 'summary')
assert self.mixin.get_fields(fields=fields) == fields
def test_get_fields_from_queryset(self):
self.mixin.queryset = MockModel.objects.all()
assert self.mixin.get_fields() == ['id', 'title', 'author']
def test_get_fields_from_values_list_queryset(self):
self.mixin.queryset = MockModel.objects.all().values_list()
assert self.mixin.get_fields() == ['id', 'title', 'author_id']
def test_get_fields_from_values_list_queryset_with_specific_fields(self):
self.mixin.queryset = MockModel.objects.all().values_list('author', 'title')
assert self.mixin.get_fields() == ['author', 'title']
开发者ID:jangeador,项目名称:django-spreadsheetresponsemixin,代码行数:24,代码来源:test_views.py
示例12: GenerateCsvTests
class GenerateCsvTests(TestCase):
def setUp(self):
self.data = (('row1col1', 'row1col2'), ('row2col1', 'row2col2'))
self.mixin = SpreadsheetResponseMixin()
def test_if_no_file_passed_in_stringio_is_returned(self):
generated_csv = self.mixin.generate_csv(self.data)
assert type(generated_csv) == type(StringIO())
def test_if_file_is_passed_it_is_returned_with_content_added(self):
given_content = mock.MagicMock()
returned_file = self.mixin.generate_csv(self.data, file=given_content)
assert returned_file == given_content
def test_adds_row_of_data(self):
expected_string = \
'row1col1,row1col2\r\nrow2col1,row2col2\r\n'
generated_csv = self.mixin.generate_csv(self.data)
assert generated_csv.getvalue() == expected_string
def test_inserts_headers_if_provided(self):
headers = ('ColA', 'ColB')
expected_string = \
'ColA,ColB\r\nrow1col1,row1col2\r\nrow2col1,row2col2\r\n'
generated_csv = self.mixin.generate_csv(self.data, headers)
assert generated_csv.getvalue() == expected_string
def test_handles_data_with_commas_correctly_by_putting_quotes(self):
data = (('Title is, boo', '2'), )
expected_string = \
'"Title is, boo",2\r\n'
generated_csv = self.mixin.generate_csv(data)
assert generated_csv.getvalue() == expected_string
def test_handles_data_with_quotes_correctly(self):
data = (('Title is, "boo"', '2'), )
expected_string = \
'"Title is, ""boo""",2\r\n'
generated_csv = self.mixin.generate_csv(data)
assert generated_csv.getvalue() == expected_string
def test_handles_data_in_unicode_correctly(self):
data = ((u'Bumblebee is čmrlj', '2'), )
expected_string = u'Bumblebee is čmrlj,2\r\n'.encode('utf-8')
generated_csv = self.mixin.generate_csv(data)
assert generated_csv.getvalue() == expected_string
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:46,代码来源:test_views.py
示例13: GenerateHeadersTests
class GenerateHeadersTests(TestCase):
def setUp(self):
MockModelFactory()
self.mixin = SpreadsheetResponseMixin()
self.mixin.queryset = MockModel.objects.all()
self.data = self.mixin.generate_data()
def test_generate_headers_gets_headers_from_model_name(self):
fields = self.mixin.get_fields(model=MockModel)
assert self.mixin.generate_headers(MockModel, fields) == (u'Id', u'Title', u'Author')
def test_generate_headers_keeps_fields_order(self):
fields = ('title', 'id')
headers = self.mixin.generate_headers(MockModel, fields=fields)
assert headers == (u'Title', u'Id')
def test_generate_headers_only_returns_fields_if_fields_is_passed(self):
fields = ('title',)
assert self.mixin.generate_headers(MockModel,
fields=fields) == (u'Title', )
def test_generate_headers_follows_foreign_keys(self):
fields = ('title', 'author__name')
headers = self.mixin.generate_headers(MockModel, fields)
assert headers == (u'Title', u'Author Name')
def test_generate_headers_with_calculated_fields(self):
fields = ('title', 'author__name', 'calculate_this')
self.mixin.calculate_this = lambda values: 'whee %d' % values[0]
headers = self.mixin.generate_headers(MockModel, fields)
assert headers == (u'Title', u'Author Name', u'Calculate This')
def test_generate_headers_with_calculated_fields_with_verbose_names(self):
fields = ('title', 'author__name', 'calculate_this')
self.mixin.calculate_this = lambda values: 'whee %d' % values[0]
self.mixin.calculate_this.verbose_name = 'Whee!'
headers = self.mixin.generate_headers(MockModel, fields)
assert headers == (u'Title', u'Author Name', u'Whee!')
开发者ID:aptivate,项目名称:django-spreadsheetresponsemixin,代码行数:38,代码来源:test_views.py
示例14: setUp
def setUp(self):
self.data = (('row1col1', 'row1col2'), ('row2col1', 'row2col2'))
self.mixin = SpreadsheetResponseMixin()
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:3,代码来源:test_views.py
示例15: RenderSetupTests
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,代码行数:58,代码来源:test_views.py
示例16: GenerateDataTests
class GenerateDataTests(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
self.author = MockAuthorFactory()
self.mock = MockModelFactory(author=self.author)
self.mock2 = MockModelFactory(author=self.author)
self.queryset = MockModel.objects.all()
def test_assertion_error_raised_if_not_a_queryset_is_sent(self):
with pytest.raises(AssertionError):
self.mixin.queryset = [1]
list(self.mixin.generate_data())
def test_if_queryset_is_none_gets_self_queryset(self):
self.mixin.queryset = MockModel.objects.all()
self.assertSequenceEqual(MockModel.objects.values_list(),
list(self.mixin.generate_data()))
def test_returns_values_list_qs_if_queryset(self):
self.mixin.queryset = self.queryset
expected_list = self.queryset.values_list()
actual_list = self.mixin.generate_data()
assert list(actual_list) == list(expected_list)
def test_returns_values_list_if_qs_is_values_queryset(self):
self.mixin.queryset = self.queryset.values()
expected_list = MockModel.objects.all().values_list()
actual_list = self.mixin.generate_data()
assert list(actual_list) == list(expected_list)
def test_returns_self_if_qs_is_values_list_queryset(self):
values_list_queryset = MockModel.objects.all().values_list()
self.mixin.queryset = values_list_queryset
actual_list = self.mixin.generate_data()
assert list(actual_list) == list(values_list_queryset)
def test_uses_specified_fields(self):
fields = ('title',)
values_list_queryset = MockModel.objects.all().values_list()
self.mixin.queryset = values_list_queryset
# We expect it to be filtered by title,
# even though full value_list is passed
expected_list = MockModel.objects.all().values_list(*fields)
actual_list = self.mixin.generate_data(fields)
assert list(actual_list) == list(expected_list)
def test_follows_foreign_key_with_model_queryset(self):
fields = ('title', 'author__name')
queryset = MockModel.objects.all()
self.mixin.queryset = queryset
expected_list = [
(self.mock.title, self.author.name),
(self.mock2.title, self.author.name),
]
actual_list = self.mixin.generate_data(fields)
assert list(actual_list) == list(expected_list)
def test_allows_calculated_field_values(self):
fields = ('title', 'author__name', 'calculated')
queryset = MockModel.objects.all()
self.mixin.queryset = queryset
expected_list = [
(self.mock.title, self.author.name, u'whee %d' % self.mock.id),
(self.mock2.title, self.author.name, u'whee %d' % self.mock2.id),
]
self.mixin.calculated = lambda values: 'whee %d' % values[0]
self.mixin.calculated.fields = ['id']
actual_list = self.mixin.generate_data(fields)
self.assertEqual(list(actual_list), expected_list)
def test_follows_foreign_key_with_values_list_queryset(self):
fields = ('title', 'author__name')
values_list_queryset = MockModel.objects.all().values_list()
self.mixin.queryset = values_list_queryset
expected_list = [
(self.mock.title, self.author.name),
(self.mock2.title, self.author.name),
]
actual_list = self.mixin.generate_data(fields)
assert list(actual_list) == list(expected_list)
def test_reverse_ordering_when_fields_specified(self):
fields = ('title', 'id')
self.mixin.queryset = self.queryset
actual_list = self.mixin.generate_data(fields)
assert list(actual_list)[0] == (self.mock.title, self.mock.id)
def test_allows_evaluation_using_models(self):
fields = ('title', 'author__name', 'calculated')
self.mixin.queryset = self.queryset
expected_list = [
(self.mock.title, self.author.name, u'whee %d' % self.mock.id),
(self.mock2.title, self.author.name, u'whee %d' % self.mock2.id),
]
self.mixin.use_models = True
self.mixin.calculated = lambda model: 'whee %d' % model.id
#.........这里部分代码省略.........
开发者ID:aptivate,项目名称:django-spreadsheetresponsemixin,代码行数:101,代码来源:test_views.py
示例17: setUp
def setUp(self):
self.author = MockAuthorFactory()
MockModelFactory(author=self.author)
self.queryset = MockModel.objects.all()
self.mixin = SpreadsheetResponseMixin()
self.mixin.queryset = self.queryset
开发者ID:aptivate,项目名称:django-spreadsheetresponsemixin,代码行数:6,代码来源:test_views.py
示例18: GenerateDataTests
class GenerateDataTests(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
self.mock = MockModelFactory()
self.mock2 = MockModelFactory()
self.queryset = MockModel.objects.all()
def test_assertion_error_raised_if_not_a_queryset_is_sent(self):
with pytest.raises(AssertionError):
self.mixin.generate_data([1])
def test_if_queryset_is_none_gets_self_queryset(self):
self.mixin.queryset = mock.Mock(spec=QuerySet)
self.mixin.generate_data()
self.mixin.queryset.values_list.assert_called_once_with()
def test_if_no_self_queryset_raise_improperlyconfigured(self):
with pytest.raises(NotImplementedError):
self.mixin.generate_data()
def test_returns_values_list_qs_if_queryset(self):
expected_list = self.queryset.values_list()
actual_list = self.mixin.generate_data(self.queryset)
assert list(actual_list) == list(expected_list)
def test_returns_values_list_if_qs_is_values_queryset(self):
expected_list = MockModel.objects.all().values_list()
actual_list = self.mixin.generate_data(self.queryset.values())
assert list(actual_list) == list(expected_list)
def test_returns_self_if_qs_is_values_list_queryset(self):
values_list_queryset = MockModel.objects.all().values_list()
actual_list = self.mixin.generate_data(values_list_queryset)
assert list(actual_list) == list(values_list_queryset)
def test_uses_specified_fields(self):
fields = ('title',)
values_list_queryset = MockModel.objects.all().values_list()
# We expect it to be filtered by title,
# even though full value_list is passed
expected_list = MockModel.objects.all().values_list(*fields)
actual_list = self.mixin.generate_data(values_list_queryset, fields)
assert list(actual_list) == list(expected_list)
def test_reverse_ordering_when_fields_specified(self):
fields = ('title', 'id')
actual_list = self.mixin.generate_data(self.queryset, fields)
assert actual_list[0] == (self.mock.title, self.mock.id)
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:48,代码来源:test_views.py
注:本文中的spreadsheetresponsemixin.SpreadsheetResponseMixin类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论