Exemple #1
0
 def test_normalize_empty_string_with_default(self):
     expected = 'default'
     field = TextInputField('test_attr',
                            label='Test Attribute',
                            attr_value='default')
     normalized = field.normalize_user_option([''])
     self.assertEqual(normalized, expected)
Exemple #2
0
 def test_render_optional_free_text(self):
     expected = (
         """<label for="test_attr">Test Attribute</label>\n"""
         """<input id="id_test_attr" class="form-control" name="test_attr" type="text">\n"""
     )
     field = TextInputField('test_attr', label='Test Attribute')
     rendered = field.render()
     self.assertEqual(rendered, expected)
Exemple #3
0
 def test_returns_unicode_trait_with_default(self):
     expected = Unicode(default_value='default').tag(config=True)
     field = TextInputField('test_attr',
                            label='Test Attribute',
                            attr_value='default')
     traitlet = field.get_trait()
     self.assertIsInstance(traitlet, Unicode)
     self.assertEqual(traitlet.metadata, expected.metadata)
     self.assertEqual(traitlet.default_value, expected.default_value)
Exemple #4
0
 def test_render_required_email(self):
     expected = (
         """<label for="test_attr">Test Attribute</label>\n"""
         """<input id="id_test_attr" class="form-control" name="test_attr" required type="email">\n"""
     )
     field = TextInputField('test_attr',
                            label='Test Attribute',
                            attr_type='email',
                            attr_required=True)
     rendered = field.render()
     self.assertEqual(rendered, expected)
Exemple #5
0
 def test_render_required_free_text_default_value(self):
     expected = (
         """<label for="test_attr">Test Attribute</label>\n"""
         """<input id="id_test_attr" class="form-control" name="test_attr" required type="text" value="DEFAULT">\n"""
     )
     field = TextInputField('test_attr',
                            label='Test Attribute',
                            attr_required=True,
                            attr_value='DEFAULT')
     rendered = field.render()
     self.assertEqual(rendered, expected)
Exemple #6
0
    def test_get_options_from_empty_form(self):
        expected = {
            'text_attr_1': None,
            'text_attr_2': None,
        }
        field1 = TextInputField('text_attr_1', label="First Input")
        field2 = TextInputField(
            'text_attr_2',
            label="Second Input",
        )
        field_list = [field1, field2]
        form = OptionsForm(form_fields=field_list)

        form_data = {}
        options = form.get_options_from_form(form_data)
        self.assertEqual(options, expected)
Exemple #7
0
    def test_get_normalized_options(self):
        expected = {
            'text_attr': 'test',
        }
        field = TextInputField('text_attr', label="First Input")
        field_list = [field]
        form = OptionsForm(form_fields=field_list)

        user_options = {
            'text_attr': ['test'],
        }
        normalized_options = form.get_normalized_user_options(user_options)
        self.assertEqual(normalized_options, expected)
Exemple #8
0
    def test_apply_traits_to_spawner(self):
        field1 = TextInputField('test_attr_text',
            label='Test Text',
            attr_value='default'
        )
        field2 = NumericalInputField('test_attr_numerical',
            label='Test Numerical',
            attr_value=2,
            attr_step='any'
        )
        form_fields = [field1, field2]
        config = get_config()
        config['OptionsFormSpawner']['form_fields'] = form_fields
        with suppress_output():
            spawner = new_spawner(config=config)

        spawner._apply_traits_from_fields()
        self.assertTrue(spawner.has_trait('test_attr_text'))
        self.assertTrue(spawner.has_trait('test_attr_numerical'))
Exemple #9
0
    def test_render_two_text_fields(self):
        field1 = TextInputField('text_attr_1', label="First Input")
        field2 = TextInputField(
            'text_attr_2',
            label="Second Input",
        )
        field_list = [field1, field2]
        form = OptionsForm(form_fields=field_list)

        expected = '\n'.join([
            form.validation_style,
            field1.render(),
            field2.render(),
        ])
        rendered = form.render()
        self.assertEqual(rendered, expected)
Exemple #10
0
    def test_set_trait_values_on_spawner(self):
        field1 = TextInputField('test_attr_text',
            label='Test Text',
            attr_value='default'
        )
        field2 = NumericalInputField('test_attr_numerical',
            label='Test Numerical',
            attr_value=2,
            attr_step='any'
        )
        form_fields = [field1, field2]
        config = get_config()
        config['OptionsFormSpawner']['form_fields'] = form_fields
        with suppress_output():
            spawner = new_spawner(config=config)

        spawner.user_options = {
            'test_attr_text': ['not_default'],
            'test_attr_numerical': [4.0]
        }
        spawner._set_trait_values_from_options()
        self.assertEqual(spawner.test_attr_text, 'not_default')
        self.assertEqual(spawner.test_attr_numerical, 4.0)
Exemple #11
0
                                   ('blanca-sol', "Blanca - Sol"),
                               ],
                               default='shas')

qos_select = SelectField('req_qos',
                         label='Select a QoS',
                         attr_required=True,
                         choices=[
                             ('jupyterhub', "Summit - All Partitions"),
                             ('blanca-csdms', "Blanca - CSDMS"),
                             ('blanca-sol', "Blanca - Sol"),
                         ],
                         default='jupyterhub')

account_input = TextInputField(
    'req_account',
    label='Specify an account to charge (Required for Blanca users)')

cluster_select = SelectField(
    'req_cluster',
    label='Select a cluster',
    attr_required=True,
    choices=[
        ('summit', "Summit"),
        ('blanca', "Blanca"),
    ],
)

runtime_input = TextInputField(
    'req_runtime',
    label='Specify runtime (HH:MM:SS format, 12hr max)',
Exemple #12
0
 def test_normalize_empty_string_no_default_required(self):
     field = TextInputField('test_attr',
                            label='Test Attribute',
                            attr_required=True)
     self.assertRaises(ValueError, field.normalize_user_option, [''])
Exemple #13
0
 def test_normalize_non_string(self):
     expected = '1234'
     field = TextInputField('test_attr', label='Test Attribute')
     normalized = field.normalize_user_option([1234])
     self.assertEqual(normalized, expected)