1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
# -*- coding: utf-8 -*-
"""
License: BSD
(c) 2005-2012 ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
"""
import unittest
from trac.perm import PermissionSystem
from trac.test import EnvironmentStub, MockRequest
from trac.web.api import RequestDone
from customfieldadmin.admin import CustomFieldAdminPage
from customfieldadmin.api import CustomFields
class CustomFieldAdminPageTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
ps = PermissionSystem(self.env)
ps.grant_permission('admin', 'TICKET_ADMIN')
self.plugin = CustomFieldAdminPage(self.env)
self.api = CustomFields(self.env)
def tearDown(self):
self.env.destroy_db()
def test_create(self):
req = MockRequest(self.env, path_info='/admin/customfields',
method='POST', authname='admin', args={
'add': True,
'name': "test",
'type': "textarea",
'label': "testing",
'format': "wiki",
'row': '9',
}
)
with self.assertRaises(RequestDone):
self.plugin.render_admin_panel(req, 'ticket', 'customfields', None)
self.assertEquals([
(u'test', u'textarea'),
(u'test.format', u'wiki'),
(u'test.label', u'testing'),
(u'test.order', u'1'),
(u'test.rows', u'5'),
(u'test.value', u''),
], sorted(list(self.env.config.options('ticket-custom'))))
def test_add_optional_select(self):
req = MockRequest(self.env, path_info='/admin/customfields',
method='POST', authname='admin', args={
'add': True,
'name': "test",
'type': "select",
'label': "testing",
'options': "\r\none\r\ntwo"
}
)
with self.assertRaises(RequestDone):
self.plugin.render_admin_panel(req, 'ticket', 'customfields', None)
self.assertEquals([
(u'test', u'select'), (u'test.label', u'testing'),
(u'test.options', u'|one|two'), (u'test.order', u'1'),
(u'test.value', u'')
], sorted(list(self.env.config.options('ticket-custom'))))
def test_apply_optional_select(self):
# Reuse the added custom field that test verified to work
self.test_add_optional_select()
self.assertEquals('select',
self.env.config.get('ticket-custom', 'test'))
# Now check that details are maintained across order change
# that reads fields, deletes them, and creates them again
# http://trac-hacks.org/ticket/1834#comment:5
req = MockRequest(self.env, path_info='/admin/customfields',
method='POST', authname='admin', args={
'apply': True,
'order_test': '2'
}
)
with self.assertRaises(RequestDone):
self.plugin.render_admin_panel(req, 'ticket', 'customfields', None)
self.assertEquals([
(u'test', u'select'), (u'test.label', u'testing'),
(u'test.options', u'|one|two'), (u'test.order', u'2'),
(u'test.value', u'')
], sorted(list(self.env.config.options('ticket-custom'))))
def test_edit_optional_select(self):
self.test_add_optional_select()
self.assertEquals('select',
self.env.config.get('ticket-custom', 'test'))
req = MockRequest(self.env, path_info='/admin/customfields',
method='POST', authname='admin', args={
'save': True, 'name': u'test', 'label': u'testing',
'type': u'select', 'value': u'',
'options': u'\r\none\r\ntwo'
}
)
with self.assertRaises(RequestDone):
self.plugin.render_admin_panel(req, 'ticket', 'customfields',
'test')
self.assertEquals([
(u'test', u'select'), (u'test.label', u'testing'),
(u'test.options', u'|one|two'), (u'test.order', u'2'),
(u'test.value', u'')
], sorted(list(self.env.config.options('ticket-custom'))))
def test_order_with_mismatched_keys(self):
# http://trac-hacks.org/ticket/11540
self.api.create_custom_field({
'name': u'one', 'format': 'plain', 'value': '',
'label': u'One', 'type': u'text', 'order': 1
})
req = MockRequest(self.env, path_info='/admin/customfields',
method='POST', authname='admin', args={
'apply': True,
'order_two': '1'
}
)
with self.assertRaises(RequestDone):
self.plugin.render_admin_panel(req, 'ticket', 'customfields', None)
|