Exemple #1
0
    def test_from_tag__should_correctly_parse_int_float_from_number(self):
        html = """
        <section name="name">
            <input type="number" step="1"/>
        </section>
        """
        section_tag = load_html(html_str=html)
        form_item = FormItem.from_tag(section_tag)
        self.assertEqual(form_item.type, FormItemType.int)

        html = """
        <section name="name">
            <input type="number"/>
        </section>
        """
        section_tag = load_html(html_str=html)
        form_item = FormItem.from_tag(section_tag)
        self.assertEqual(form_item.type, FormItemType.float)
Exemple #2
0
    def test_from_tag__should_raise_error_if_type_hidden_and_no_value(self):
        html = """
        <section name="name">
            <input type="hidden"/>
        </section>
        """
        section_tag = load_html(html_str=html)

        with self.assertRaises(ONEmSDKException) as context:
            form_item = FormItem.from_tag(section_tag)

        self.assertIn('value attribute is required for input type="hidden"',
                      str(context.exception))
Exemple #3
0
    def test_from_tag__should_raise_error_for_invalid_type(self):
        html = """
        <section name="name">
            <input type="blabla"/>
        </section>
        """

        with self.assertRaises(ValidationError) as context:
            section_tag = load_html(html_str=html)
            form_item = FormItem.from_tag(section_tag)

        self.assertIn(
            "value is not a valid enumeration member; permitted: 'text', 'date', 'number', 'hidden', 'email', 'url', 'datetime', 'location'",
            str(context.exception))
Exemple #4
0
 def test_from_tag__should_correctly_parse_complex_section_tag(self):
     html = """
     <section name="first-step"
              header="The header"
              footer="The footer"
              chunking-footer="Chunking footer"
              confirmation-label="Conf label"
              method="PATCH"
              status-exclude
              url="https://url.url"
              validate-type-error="The validate type err"
              validate-type-error-footer="The val type err footer"
              validate-url="The val url"
              auto-select
              numbered
              required>
         <input type="email"
                pattern="somepattern"
                minlength="3"
                minlength-error="The minlen error"
                maxlength="100"
                maxlength-error="The maxlen error" />
     </section>
     """
     section_tag = load_html(html_str=html)
     form_item = FormItem.from_tag(section_tag)
     expected = {
         "type": "regex",
         "name": "first-step",
         "description": "",
         "header": "The header",
         "footer": "The footer",
         "body": None,
         "value": None,
         "chunking_footer": "Chunking footer",
         "confirmation_label": "Conf label",
         "min_length": 3,
         "min_length_error": "The minlen error",
         "max_length": 100,
         "max_length_error": "The maxlen error",
         "min_value": None,
         "min_value_error": None,
         "max_value": None,
         "max_value_error": None,
         "meta": {
             "auto_select": True,
             "multi_select": False,
             "numbered": True
         },
         "method": "PATCH",
         "required": True,
         "pattern": "somepattern",
         "status_exclude": True,
         "status_prepend": False,
         "url": "https://url.url",
         "validate_type_error": "The validate type err",
         "validate_type_error_footer": "The val type err footer",
         "validate_url": "The val url"
     }
     self.assertEqual(json.dumps(expected, indent=2),
                      form_item.json(indent=2))