Exemplo n.º 1
0
 def test_required(self):
     c = jformer._Component()
     self.assertRaises(ValueError, c.required, {})
     self.assertEqual(c.required({'value':None}), ['Required.'])
     self.assertEqual(c.required({'value':''}), ['Required.'])
     self.assertEqual(c.required({'value':'0'}), 'success')
     self.assertEqual(c.required({'value':'magic'}), 'success')
Exemplo n.º 2
0
 def test_init(self):
     c = jformer._Component()
     self.assertEqual(c._class, None)
     self.assertEqual(c.value, None)
     self.assertEqual(c.style, None)
     self.assertEqual(c.parentJFormSection, None)
     self.assertEqual(c.anonymous, False)
     self.assertEqual(c.label, None)
     self.assertEqual(c.labelClass, 'jFormComponentLabel')
     self.assertEqual(c.labelRequiredStarClass,
                      'jFormComponentLabelRequiredStar')
     self.assertEqual(c.requiredText, ' *')
     self.assertEqual(c.tip, None)
     self.assertEqual(c.tipClass, 'jFormComponentTip')
     self.assertEqual(c.description, None)
     self.assertEqual(c.descriptionClass,
                      'jFormComponentDescription')
     self.assertEqual(c.instanceOptions, None)
     self.assertEqual(c.triggerFunction, None)
     self.assertEqual(c.enterSubmits, False)
     self.assertEqual(c.dependencyOptions, None)
     self.assertEqual(c.validationOptions, {})
     self.assertEqual(c.errorMessageArray, None)
     self.assertEqual(c.passedValidation, None)
     self.assertEqual(c.showErrorTipOnce, False)
     self.assertEqual(c.persistentTip, False)
Exemplo n.º 3
0
 def test_initialize(self):
     c = jformer._Component()
     c.validationOptions = 'required'
     c.initialize({'attr1': 'value1', 'attr2': 'value2'})
     self.assertEqual(c.validationOptions, ['required'])
     self.assertEqual(c.options, {'attr1': 'value1', 
                      'attr2': 'value2'})
Exemplo n.º 4
0
 def test_has_instance_values(self):
     c = jformer._Component()
     self.assertEqual(c.hasInstanceValues(), False)
     c.value = '1'
     self.assertEqual(c.hasInstanceValues(), False)
     c.value = ['1', '2']
     self.assertEqual(c.hasInstanceValues(), True)
Exemplo n.º 5
0
 def test_get_set_clear_value(self):
     c = jformer._Component()
     c.setValue('House')
     self.assertEqual(c.value, 'House')
     value = c.getValue()
     self.assertEqual(value, 'House')
     c.clearValue()
     self.assertEqual(c.value, None)
Exemplo n.º 6
0
 def test_generate_component_label(self):
     c = jformer._Component()
     setattr(c, 'id', 'magic')
     self.assertEqual(c.generateComponentLabel(), '')
     c.label = 'Name:'
     self.assertEqual(c.generateComponentLabel().__str__(),
         '<label id="magic-label" for="magic" class="jFormComponentLabel">Name:</label>')
     c.validationOptions = ['required', 'password']
     self.assertEqual(c.generateComponentLabel().__str__(),
         '<label id="magic-label" for="magic" class="jFormComponentLabel">Name:<span class="jFormComponentLabelRequiredStar"> *</span></label>')
Exemplo n.º 7
0
 def test_insert_component_tip(self):
     from element import Element
     c = jformer._Component()
     setattr(c, 'id', 'magic')
     div = Element('div', {})
     div = c.insertComponentTip(div)
     self.assertEqual(div.__str__(), '<div></div>')
     c.tip = 'Put on your best smile'
     div = c.insertComponentTip(div)
     self.assertEqual(div.__str__(),
         '<div><div style="display: none" id="magic-tip" class="jFormComponentTip">Put on your best smile</div></div>')
Exemplo n.º 8
0
 def test_insert_component_description(self):
     from element import Element
     c = jformer._Component()
     setattr(c, 'id', 'magic')
     div = Element('div', {})
     div = c.insertComponentDescription(div)
     self.assertEqual(div.__str__(), '<div></div>')
     c.description = 'My description'
     div = c.insertComponentDescription(div)
     self.assertEqual(div.__str__(),
         '<div><div id="magic-description" class="jFormComponentDescription">My description</div></div>')
Exemplo n.º 9
0
 def test_get_options_dependency(self):
     c = jformer._Component()
     c.dependencyOptions = {
         'dependentOn': 'billing_shipping',
         'display': 'hide',
         'jsFunction': '$("#billing_shipping-choice1").is(":checked");'}
     self.assertEqual(c.getOptions(), {'type': None,
         'options': {'dependencyOptions': {
         'dependentOn': ['billing_shipping'],
         'display': 'hide',
         'jsFunction': '$("#billing_shipping-choice1").is(":checked");'}}})
Exemplo n.º 10
0
 def test_get_options_instance(self):
     c = jformer._Component()
     c.instanceOptions = {
         'max': 3,
         'addButtonText': 'Add Team',
         'removeButtonText': 'Remove Team'}
     self.assertEqual(c.getOptions(), {'type': None,
         'options': {'instanceOptions': {
         'max': 3, 
         'removeButtonText': 'Remove Team', 
         'addButtonText': 'Add Team'}}})
Exemplo n.º 11
0
 def test_generate_component_div(self):
     c = jformer._Component()
     setattr(c, 'id', 'magic')
     c._class = 'blue_border'
     self.assertEqual(c.generateComponentDiv().__str__(),
         '<div id="magic-wrapper" class="jFormComponent blue_border"></div>')
     c.style = 'color: blue;'
     self.assertEqual(c.generateComponentDiv().__str__(),
         '<div style="color: blue;" id="magic-wrapper" ' +
         'class="jFormComponent blue_border"></div>')
     c.label = 'Name:'
     self.assertEqual(c.generateComponentDiv().__str__(),
         '<div style="color: blue;" id="magic-wrapper" ' +
         'class="jFormComponent blue_border">' +
         '<label id="magic-label" for="magic" ' +
         'class="jFormComponentLabel">Name:</label></div>')
Exemplo n.º 12
0
 def test_get_options_trigger(self):
     c = jformer._Component()
     c.triggerFunction = 'addValues();'
     self.assertEqual(c.getOptions(), {'type': None,
         'options': {'triggerFunction': 'addValues();'}})
Exemplo n.º 13
0
 def test_update_required_text(self):
     c = jformer._Component()
     self.assertEqual(c.requiredText, ' *')
     c.updateRequiredText('So like required')
     self.assertEqual(c.requiredText, 'So like required')
Exemplo n.º 14
0
 def test_get_options_persistent_tip(self):
     c = jformer._Component()
     c.persistentTip = True
     self.assertEqual(c.getOptions(), {'type': None,
         'options': {'persistentTip': True}})
Exemplo n.º 15
0
 def test_get_options_show_error_tip_once(self):
     c = jformer._Component()
     c.showErrorTipOnce = True
     self.assertEqual(c.getOptions(), {'type': None,
         'options': {'showErrorTipOnce': True}})
Exemplo n.º 16
0
 def test_get_options_validation(self):
     c = jformer._Component()
     c.validationOptions = ['required', 'password']
     self.assertEqual(c.getOptions(), {'type': None,
         'options': {'validationOptions': ['required', 'password']}})
Exemplo n.º 17
0
 def test_get_options_empty(self):
     c = jformer._Component()
     self.assertEqual(c.getOptions(), {'type': None})