Skip to content

Commit 361eacb

Browse files
committed
test: basic testing for BooleanHTMLProperty
plain and field.
1 parent e7c285d commit 361eacb

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

test/test_templating.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,116 @@ def setUp(self):
734734
def inject_fixtures(self, caplog):
735735
self._caplog = caplog
736736

737+
class BooleanHTMLPropertyTestCase(HTMLPropertyTestClass):
738+
739+
def setUp(self):
740+
super(BooleanHTMLPropertyTestCase, self).setUp()
741+
742+
db = self.client.db
743+
db.issue.addprop(boolvalt=hyperdb.Boolean())
744+
db.issue.addprop(boolvalf=hyperdb.Boolean())
745+
db.issue.addprop(boolvalunset=hyperdb.Boolean())
746+
747+
self.client.db.issue.create(title="title",
748+
boolvalt = True,
749+
boolvalf = False)
750+
751+
def tearDown(self):
752+
self.client.db.close()
753+
memorydb.db_nuke('')
754+
755+
testdata = [
756+
("boolvalt", "Yes", True, False),
757+
("boolvalf", "No", False, True),
758+
("boolvalunset", "", False, True),
759+
]
760+
761+
def test_BoolHTMLRadioButtons(self):
762+
#propname = "boolvalt"
763+
764+
#plainval = "Yes"
765+
766+
self.maxDiff = None
767+
for test_inputs in self.testdata:
768+
params = {
769+
"check1": 'checked="checked" ' if test_inputs[2] else "",
770+
"check2": 'checked="checked" ' if test_inputs[3] else "",
771+
"propname": test_inputs[0],
772+
"plainval": test_inputs[1],
773+
774+
}
775+
776+
777+
test_hyperdbBoolean = self.client.db.issue.getprops("1")[
778+
params['propname']]
779+
test_boolean = self.client.db.issue.get("1", params['propname'])
780+
781+
# client, classname, nodeid, prop, name, value,
782+
# anonymous=0, offset=None
783+
d = BooleanHTMLProperty(self.client, 'issue', '1',
784+
test_hyperdbBoolean,
785+
params['propname'], test_boolean)
786+
787+
self.assertIsInstance(d._value, (type(None), bool))
788+
789+
self.assertEqual(d.plain(), params['plainval'])
790+
791+
input_expected = (
792+
'<input %(check1)sid="issue1@%(propname)s_yes" '
793+
'name="issue1@%(propname)s" type="radio" value="yes">'
794+
'<label class="rblabel" for="issue1@%(propname)s_yes">'
795+
'Yes</label>'
796+
'<input %(check2)sid="issue1@%(propname)s_no" name="issue1@%(propname)s" '
797+
'type="radio" value="no"><label class="rblabel" '
798+
'for="issue1@%(propname)s_no">No</label>') % params
799+
800+
self.assertEqual(d.field(), input_expected)
801+
802+
y_label = ( '<label class="rblabel" for="issue1@%(propname)s_yes">'
803+
'True</label>') % params
804+
n_label = ('<label class="rblabel" '
805+
'for="issue1@%(propname)s_no">False</label>') % params
806+
807+
input_expected = (
808+
'<input %(check1)sid="issue1@%(propname)s_yes" '
809+
'name="issue1@%(propname)s" type="radio" value="yes">'
810+
+ y_label +
811+
'<input %(check2)sid="issue1@%(propname)s_no" name="issue1@%(propname)s" '
812+
'type="radio" value="no">' + n_label ) % params
813+
814+
self.assertEqual(d.field(y_label=y_label, n_label=n_label), input_expected)
815+
816+
817+
input_expected = (
818+
'<label class="rblabel" for="issue1@%(propname)s_yes">'
819+
'Yes</label>'
820+
'<input %(check1)sid="issue1@%(propname)s_yes" '
821+
'name="issue1@%(propname)s" type="radio" value="yes">'
822+
'<label class="rblabel" '
823+
'for="issue1@%(propname)s_no">No</label>'
824+
'<input %(check2)sid="issue1@%(propname)s_no" '
825+
'name="issue1@%(propname)s" '
826+
'type="radio" value="no">') % params
827+
828+
print(d.field(labelfirst=True))
829+
self.assertEqual(d.field(labelfirst=True), input_expected)
830+
831+
# one test on the last d is enough.
832+
# check permissions return
833+
is_view_ok_orig = d.is_view_ok
834+
is_edit_ok_orig = d.is_edit_ok
835+
no_access = lambda : False
836+
837+
d.is_view_ok = no_access
838+
self.assertEqual(d.plain(), "[hidden]")
839+
840+
d.is_edit_ok = no_access
841+
self.assertEqual(d.field(), "[hidden]")
842+
843+
d.is_view_ok = is_view_ok_orig
844+
self.assertEqual(d.field(), params['plainval'])
845+
d.is_edit_ok = is_edit_ok_orig
846+
737847
class DateHTMLPropertyTestCase(HTMLPropertyTestClass):
738848

739849
def setUp(self):

0 commit comments

Comments
 (0)