本文整理汇总了Python中trac.mimeview.api.Mimeview.convert_content方法的典型用法代码示例。如果您正苦于以下问题:Python Mimeview.convert_content方法的具体用法?Python Mimeview.convert_content怎么用?Python Mimeview.convert_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.mimeview.api.Mimeview
的用法示例。
在下文中一共展示了Mimeview.convert_content方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProductTicketConversionTestCase
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [as 别名]
class ProductTicketConversionTestCase(TicketConversionTestCase, \
MultiproductTestCase):
def setUp(self):
self._mp_setup()
self.global_env = self.env
self.env = ProductEnvironment(self.global_env, self.default_product)
# Product name inserted in RSS feed
self.env.product._data['name'] = 'My Project'
self.env.config.set('trac', 'templates_dir',
os.path.join(os.path.dirname(self.env.path),
'templates'))
self.ticket_module = ProductTicketModule(self.env)
self.mimeview = Mimeview(self.env)
self.req = Mock(base_path='/trac.cgi', path_info='',
href=Href('/trac.cgi'), chrome={'logo': {}},
abs_href=Href('http://example.org/trac.cgi'),
environ={}, perm=[], authname='-', args={}, tz=None,
locale='', session=None, form_token=None)
def test_csv_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'csv')
self.assertEqual(('\xef\xbb\xbf'
'id,summary,reporter,owner,description,status,'
'product,keywords,cc\r'
'\n1,Foo,santa,,Bar,,,,\r\n',
'text/csv;charset=utf-8', 'csv'), csv)
def test_tab_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'tab')
self.assertEqual(('\xef\xbb\xbf'
'id\tsummary\treporter\towner\tdescription\tstatus\t'
'product\tkeywords\tcc\r\n'
'1\tFoo\tsanta\t\tBar\t\t\t\t\r\n',
'text/tab-separated-values;charset=utf-8', 'tsv'),
csv)
def tearDown(self):
self.global_env.reset_db()
示例2: _test_convert_content
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [as 别名]
def _test_convert_content(self, expected, content, iterable):
mimeview = Mimeview(self.env)
output = mimeview.convert_content(self._make_req(), self.in_mimetype,
content, 'text', iterable=iterable)
if iterable:
self.assertNotIn(type(output[0]), (str, unicode))
self.assertEqual(expected, ''.join(output[0]))
else:
self.assertEqual(type(expected), type(output[0]))
self.assertEqual(expected, output[0])
self.assertEqual('text/plain', output[1])
self.assertEqual('txt', output[2])
示例3: TicketConversionTestCase
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [as 别名]
class TicketConversionTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
self.env.config.set('trac', 'templates_dir',
os.path.join(os.path.dirname(self.env.path),
'templates'))
self.ticket_module = TicketModule(self.env)
self.mimeview = Mimeview(self.env)
self.req = Mock(base_path='/trac.cgi', path_info='',
href=Href('/trac.cgi'), chrome={'logo': {}},
abs_href=Href('http://example.org/trac.cgi'),
environ={}, perm=PermissionCache(self.env, '-'),
authname='-', args={}, tz=None,
locale='', session=None, form_token=None)
def tearDown(self):
self.env.reset_db()
def _create_a_ticket(self):
# 1. Creating ticket
ticket = Ticket(self.env)
ticket['owner'] = ''
ticket['reporter'] = 'santa'
ticket['summary'] = 'Foo'
ticket['description'] = 'Bar'
ticket['foo'] = 'This is a custom field'
ticket.insert()
return ticket
def _create_a_ticket_with_email(self):
ticket = Ticket(self.env)
ticket['owner'] = '[email protected]'
ticket['reporter'] = '[email protected]'
ticket['cc'] = 'cc1, [email protected]'
ticket['summary'] = 'Foo'
ticket['description'] = 'Bar'
ticket.insert()
return ticket
def test_conversions(self):
conversions = self.mimeview.get_supported_conversions(
'trac.ticket.Ticket')
expected = sorted([('csv', 'Comma-delimited Text', 'csv',
'trac.ticket.Ticket', 'text/csv', 8,
self.ticket_module),
('tab', 'Tab-delimited Text', 'tsv',
'trac.ticket.Ticket', 'text/tab-separated-values', 8,
self.ticket_module),
('rss', 'RSS Feed', 'xml',
'trac.ticket.Ticket', 'application/rss+xml', 8,
self.ticket_module)],
key=lambda i: i[-1], reverse=True)
self.assertEqual(expected, conversions)
def test_csv_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'csv')
self.assertEqual(('\xef\xbb\xbf'
'id,summary,reporter,owner,description,status,'
'keywords,cc\r\n1,Foo,santa,,Bar,,,\r\n',
'text/csv;charset=utf-8', 'csv'), csv)
def test_csv_conversion_with_obfuscation(self):
ticket = self._create_a_ticket_with_email()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'csv')
self.assertEqual(
('\xef\xbb\xbf'
'id,summary,reporter,owner,description,status,keywords,cc\r\n'
'1,Foo,[email protected]…,[email protected]…,Bar,,,cc1 [email protected]…\r\n',
'text/csv;charset=utf-8', 'csv'),
csv)
self.req.perm = MockPerm()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'csv')
self.assertEqual(
('\xef\xbb\xbf'
'id,summary,reporter,owner,description,status,keywords,cc\r\n'
'1,Foo,[email protected],[email protected],Bar,,,'
'cc1 [email protected]\r\n',
'text/csv;charset=utf-8', 'csv'),
csv)
def test_tab_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'tab')
self.assertEqual(('\xef\xbb\xbf'
'id\tsummary\treporter\towner\tdescription\tstatus\t'
'keywords\tcc\r\n1\tFoo\tsanta\t\tBar\t\t\t\r\n',
'text/tab-separated-values;charset=utf-8', 'tsv'),
csv)
def test_tab_conversion_with_obfuscation(self):
ticket = self._create_a_ticket_with_email()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'tab')
self.assertEqual(
#.........这里部分代码省略.........
示例4: TicketConversionTestCase
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [as 别名]
class TicketConversionTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
self.env.config.set("trac", "templates_dir", os.path.join(os.path.dirname(self.env.path), "templates"))
self.ticket_module = TicketModule(self.env)
self.mimeview = Mimeview(self.env)
self.req = Mock(
base_path="/trac.cgi",
path_info="",
href=Href("/trac.cgi"),
chrome={"logo": {}},
abs_href=Href("http://example.org/trac.cgi"),
environ={},
perm=PermissionCache(self.env, "-"),
authname="-",
args={},
tz=None,
locale="",
session=None,
form_token=None,
)
def tearDown(self):
self.env.reset_db()
def _create_a_ticket(self):
# 1. Creating ticket
ticket = Ticket(self.env)
ticket["owner"] = ""
ticket["reporter"] = "santa"
ticket["summary"] = "Foo"
ticket["description"] = "Bar"
ticket["foo"] = "This is a custom field"
ticket.insert()
return ticket
def _create_a_ticket_with_email(self):
ticket = Ticket(self.env)
ticket["owner"] = "[email protected]"
ticket["reporter"] = "[email protected]"
ticket["cc"] = "cc1, [email protected]"
ticket["summary"] = "Foo"
ticket["description"] = "Bar"
ticket.insert()
return ticket
def test_conversions(self):
conversions = self.mimeview.get_supported_conversions("trac.ticket.Ticket")
expected = sorted(
[
("csv", "Comma-delimited Text", "csv", "trac.ticket.Ticket", "text/csv", 8, self.ticket_module),
(
"tab",
"Tab-delimited Text",
"tsv",
"trac.ticket.Ticket",
"text/tab-separated-values",
8,
self.ticket_module,
),
("rss", "RSS Feed", "xml", "trac.ticket.Ticket", "application/rss+xml", 8, self.ticket_module),
],
key=lambda i: i[-1],
reverse=True,
)
self.assertEqual(expected, conversions)
def test_csv_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, "trac.ticket.Ticket", ticket, "csv")
self.assertEqual(
(
"\xef\xbb\xbf" "id,summary,reporter,owner,description,status," "keywords,cc\r\n1,Foo,santa,,Bar,,,\r\n",
"text/csv;charset=utf-8",
"csv",
),
csv,
)
def test_csv_conversion_with_obfuscation(self):
ticket = self._create_a_ticket_with_email()
csv = self.mimeview.convert_content(self.req, "trac.ticket.Ticket", ticket, "csv")
self.assertEqual(
(
"\xef\xbb\xbf"
"id,summary,reporter,owner,description,status,keywords,cc\r\n"
"1,Foo,[email protected]…,[email protected]…,Bar,,,cc1 [email protected]…\r\n",
"text/csv;charset=utf-8",
"csv",
),
csv,
)
self.req.perm = MockPerm()
csv = self.mimeview.convert_content(self.req, "trac.ticket.Ticket", ticket, "csv")
self.assertEqual(
(
"\xef\xbb\xbf"
"id,summary,reporter,owner,description,status,keywords,cc\r\n"
"1,Foo,[email protected],[email protected],Bar,,,"
"cc1 [email protected]\r\n",
#.........这里部分代码省略.........
示例5: TicketConversionTestCase
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [as 别名]
class TicketConversionTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
self.ticket_module = TicketModule(self.env)
self.mimeview = Mimeview(self.env)
self.req = Mock(hdf=HDFWrapper(['./templates']),
base_path='/trac.cgi', path_info='',
href=Href('/trac.cgi'))
def _create_a_ticket(self):
# 1. Creating ticket
ticket = Ticket(self.env)
ticket['reporter'] = 'santa'
ticket['summary'] = 'Foo'
ticket['description'] = 'Bar'
ticket['foo'] = 'This is a custom field'
return ticket
def test_conversions(self):
conversions = self.mimeview.get_supported_conversions(
'trac.ticket.Ticket')
expected = sorted([('csv', 'Comma-delimited Text', 'csv',
'trac.ticket.Ticket', 'text/csv', 8,
self.ticket_module),
('tab', 'Tab-delimited Text', 'tsv',
'trac.ticket.Ticket', 'text/tab-separated-values', 8,
self.ticket_module),
('rss', 'RSS Feed', 'xml',
'trac.ticket.Ticket', 'application/rss+xml', 8,
self.ticket_module)],
key=lambda i: i[-1], reverse=True)
self.assertEqual(expected, conversions)
def test_csv_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'csv')
self.assertEqual((u'id,summary,reporter,owner,description,keywords,cc'
'\r\nNone,Foo,santa,,Bar,,\r\n',
'text/csv;charset=utf-8', 'csv'), csv)
def test_tab_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'tab')
self.assertEqual((u'id\tsummary\treporter\towner\tdescription\tkeywords'
'\tcc\r\nNone\tFoo\tsanta\t\tBar\t\t\r\n',
'text/tab-separated-values;charset=utf-8', 'tsv'),
csv)
def test_rss_conversion(self):
ticket = self._create_a_ticket()
content, mimetype, ext = self.mimeview.convert_content(
self.req, 'trac.ticket.Ticket', ticket, 'rss')
self.assertEqual(('<?xml version="1.0"?>\n<!-- RSS generated by Trac v '
'on -->\n<rss version="2.0">\n <channel>\n '
'<title>Ticket </title>\n <link></link>\n '
'<description><p>\nBar\n</p>\n'
'</description>\n <language>en-us</language>\n '
'<generator>Trac v</generator>\n </channel>\n</rss>\n',
'application/rss+xml', 'xml'),
(content.replace('\r', ''), mimetype, ext))