本文整理汇总了Python中spreadsheetresponsemixin.SpreadsheetResponseMixin.generate_headers方法的典型用法代码示例。如果您正苦于以下问题:Python SpreadsheetResponseMixin.generate_headers方法的具体用法?Python SpreadsheetResponseMixin.generate_headers怎么用?Python SpreadsheetResponseMixin.generate_headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spreadsheetresponsemixin.SpreadsheetResponseMixin
的用法示例。
在下文中一共展示了SpreadsheetResponseMixin.generate_headers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GenerateHeadersTests
# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import generate_headers [as 别名]
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', )
示例2: GenerateHeadersTests
# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import generate_headers [as 别名]
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', )
示例3: GenerateHeadersTests
# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import generate_headers [as 别名]
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!')