コード例 #1
0
 def test_integer_resource_parameter_process_value_in_range(self):
     param = IntegerResourceParameter(name="option1",
                                      min_val=-20,
                                      max_val=20)
     self.assertEqual(10, param.process_value("10"))
     self.assertEqual(0, param.process_value("0"))
     self.assertEqual(-10, param.process_value("-10"))
コード例 #2
0
    def test_integer_resource_parameter_html_element(self):
        param = IntegerResourceParameter(name="option1")
        html = param.html_element()
        self.assertIsInstance(html, etree._Element)

        self.assertEqual("fieldset", html.tag)
        self.assertEqual(2, len(html))  # legend and input
        self.assertEqual("legend", html[0].tag)

        self.assertEqual("input", html[1].tag)
        self.assertEqual("option1", html[1].get("name"))
        self.assertEqual("number", html[1].get("type"))
        self.assertEqual(None, html[1].get("min"))
        self.assertEqual(None, html[1].get("max"))
        self.assertEqual(None, html[1].get("value"))
コード例 #3
0
    def get_local_options(cls):
        """Get local options dictionary, including additional subclass local options.

        These options are only included when running locally.

        Returns:
            Dictionary, of form {option name: ResourceParameter object, ...}
        """
        local_options = cls.get_additional_local_options()
        local_options = {
            "header_text":
            TextResourceParameter(name="header_text",
                                  description=_("Header Text"),
                                  placeholder=_("Example School: Room Four"),
                                  required=False),
        }
        if cls.copies:
            local_options.update({
                "copies":
                IntegerResourceParameter(name="copies",
                                         description=_("Number of Copies"),
                                         min_val=1,
                                         max_val=50,
                                         default=1,
                                         required=False),
            })
        return local_options
コード例 #4
0
    def test_integer_resource_parameter_html_element_with_min_max_default(
            self):
        param = IntegerResourceParameter(name="option1",
                                         default=20,
                                         min_val=10,
                                         max_val=30)
        html = param.html_element()
        self.assertIsInstance(html, etree._Element)

        self.assertEqual("fieldset", html.tag)
        self.assertEqual(2, len(html))  # legend and input
        self.assertEqual("legend", html[0].tag)

        self.assertEqual("input", html[1].tag)
        self.assertEqual("option1", html[1].get("name"))
        self.assertEqual("number", html[1].get("type"))
        self.assertEqual("10", html[1].get("min"))
        self.assertEqual("30", html[1].get("max"))
        self.assertEqual("20", html[1].get("value"))
コード例 #5
0
 def test_integer_resource_parameter_process_value_out_of_range(self):
     param = IntegerResourceParameter(name="option1",
                                      min_val=-20,
                                      max_val=20)
     with self.assertRaises(QueryParameterInvalidError):
         param.process_value("-30")
     with self.assertRaises(QueryParameterInvalidError):
         param.process_value("30")
コード例 #6
0
 def test_integer_resource_parameter_process_value_invalid_value_type(self):
     param = IntegerResourceParameter(name="option1")
     with self.assertRaises(QueryParameterInvalidError):
         param.process_value("notaninteger")