Exemple #1
0
  def test_parse_control_options_textbox(self):
    control = {'label': None, 'value': 'test-value', 'type': 'textbox',
               'choices': None, 'min': 0, 'max': 10, 'step': 2}
    defaults = {'test-control': None}

    control_html = _utils.parse_control_options({'test-control': control}, defaults)
    self.assertIn('class="gchart-control"', control_html[0])
    self.assertIn('<input type="text"', control_html[0])
    self.assertIn('value="test-value"', control_html[0])
    self.assertEqual(control_html[1], {'test-control': 'test-value'})

    control['value'] = None
    control_html = _utils.parse_control_options({'test-control': control})
    self.assertIn('value=""', control_html[0])
Exemple #2
0
  def test_parse_control_options_textbox(self):
    control = {'label': None, 'value': 'test-value', 'type': 'textbox',
               'choices': None, 'min': 0, 'max': 10, 'step': 2}
    defaults = {'test-control': None}

    control_html = _utils.parse_control_options({'test-control': control}, defaults)
    self.assertIn('class="gchart-control"', control_html[0])
    self.assertIn('<input type="text"', control_html[0])
    self.assertIn('value="test-value"', control_html[0])
    self.assertEqual(control_html[1], {'test-control': 'test-value'})

    control['value'] = None
    control_html = _utils.parse_control_options({'test-control': control})
    self.assertIn('value=""', control_html[0])
Exemple #3
0
  def test_parse_control_options_set(self):
    control = {'label': None, 'choices': ['v1', 'v2'], 'min': 0, 'max': 10, 'step': 2}
    defaults = {'test-control': ['value1', 'value2']}

    control_html = _utils.parse_control_options({'test-control': control}, defaults)
    self.assertIn('class="gchart-control"', control_html[0])
    self.assertIn('<input type="checkbox"', control_html[0])
    self.assertIn('value="v1"', control_html[0])
    self.assertIn('value="v2"', control_html[0])
    self.assertEqual(control_html[1], {'test-control': ['value1', 'value2']})

    control['choices'] = []
    with self.assertRaisesRegexp(Exception, 'set control must specify a nonempty set'):
      _utils.parse_control_options({'test-control': control}, defaults)

    # make sure value is picked from set of choices if not specified in any way
    control['type'] = 'set'
    control['choices'] = ['v1', 'v2']
    _utils.parse_control_options({'test-control': control})
Exemple #4
0
  def test_parse_control_options_set(self):
    control = {'label': None, 'choices': ['v1', 'v2'], 'min': 0, 'max': 10, 'step': 2}
    defaults = {'test-control': ['value1', 'value2']}

    control_html = _utils.parse_control_options({'test-control': control}, defaults)
    self.assertIn('class="gchart-control"', control_html[0])
    self.assertIn('<input type="checkbox"', control_html[0])
    self.assertIn('value="v1"', control_html[0])
    self.assertIn('value="v2"', control_html[0])
    self.assertEqual(control_html[1], {'test-control': ['value1', 'value2']})

    control['choices'] = []
    with self.assertRaisesRegexp(Exception, 'set control must specify a nonempty set'):
      _utils.parse_control_options({'test-control': control}, defaults)

    # make sure value is picked from set of choices if not specified in any way
    control['type'] = 'set'
    control['choices'] = ['v1', 'v2']
    _utils.parse_control_options({'test-control': control})
Exemple #5
0
  def test_parse_control_options_slider(self):
    control = {'label': None, 'value': 5, 'type': 'slider',
               'choices': None, 'min': 0, 'max': 10, 'step': 2}
    control_html = _utils.parse_control_options({'test-control': control})
    self.assertIn('class="gchart-slider_value"', control_html[0])
    self.assertIn('<input type="range"', control_html[0])
    self.assertIn('value="5"', control_html[0])
    self.assertIn('min="0" max="10" step="2"', control_html[0])
    self.assertEqual(control_html[1], {'test-control': 5})

    control['min'] = None
    with self.assertRaisesRegexp(Exception, 'slider control must specify a min and max'):
      _utils.parse_control_options({'test-control': control})

    control['min'] = 20
    with self.assertRaisesRegexp(Exception,
                                 'slider control must specify a min value less than max value'):
      _utils.parse_control_options({'test-control': control})

    control['min'] = 7
    control['value'] = None
    control_html = _utils.parse_control_options({'test-control': control})
    self.assertIn('value="7"', control_html[0])
Exemple #6
0
  def test_parse_control_options_slider(self):
    control = {'label': None, 'value': 5, 'type': 'slider',
               'choices': None, 'min': 0, 'max': 10, 'step': 2}
    control_html = _utils.parse_control_options({'test-control': control})
    self.assertIn('class="gchart-slider_value"', control_html[0])
    self.assertIn('<input type="range"', control_html[0])
    self.assertIn('value="5"', control_html[0])
    self.assertIn('min="0" max="10" step="2"', control_html[0])
    self.assertEqual(control_html[1], {'test-control': 5})

    control['min'] = None
    with self.assertRaisesRegexp(Exception, 'slider control must specify a min and max'):
      _utils.parse_control_options({'test-control': control})

    control['min'] = 20
    with self.assertRaisesRegexp(Exception,
                                 'slider control must specify a min value less than max value'):
      _utils.parse_control_options({'test-control': control})

    control['min'] = 7
    control['value'] = None
    control_html = _utils.parse_control_options({'test-control': control})
    self.assertIn('value="7"', control_html[0])
Exemple #7
0
 def test_parse_control_options_checkbox(self):
   control_html = _utils.parse_control_options({'test-control': {'type': 'checkbox'}})
   self.assertIn('<input type="checkbox"', control_html[0])
Exemple #8
0
 def test_parse_control_options_badtype(self):
   control = {'label': None, 'type': 'badtype'}
   with self.assertRaisesRegexp(Exception, 'Unknown control type badtype'):
     _utils.parse_control_options({'test-control': control})
Exemple #9
0
 def test_parse_control_options_checkbox(self):
   control_html = _utils.parse_control_options({'test-control': {'type': 'checkbox'}})
   self.assertIn('<input type="checkbox"', control_html[0])
Exemple #10
0
 def test_parse_control_options_badtype(self):
   control = {'label': None, 'type': 'badtype'}
   with self.assertRaisesRegexp(Exception, 'Unknown control type badtype'):
     _utils.parse_control_options({'test-control': control})