Ejemplo n.º 1
0
 def test_parse_params_invalid_unbalanced_parentheses(self):
     """Test for `parse_params` function - case: invalid params -
     unbalanced parentheses
     """
     with self.assertRaisesMessage(
             ValueError,
             'In chars 5-12 ` TEST="`: Unbalanced parentheses.'):
         utils.parse_params('Test, TEST="')
Ejemplo n.º 2
0
 def test_parse_params_invalid_duplicated_named_arg(self):
     """Test for `parse_params` function - case: invalid params -
     duplicated named argument
     """
     with self.assertRaisesMessage(
             ValueError,
             "In chars 8-15 `param=2`: Duplicated named argument."):
         utils.parse_params("param=1,param=2")
Ejemplo n.º 3
0
 def clean_params(self):
     """Validate `params` field value"""
     params = self.cleaned_data.get("params") or ""
     try:
         parse_params(params)
     except ValueError as e:
         raise forms.ValidationError(text_type(e))
     return params
Ejemplo n.º 4
0
 def test_parse_params_invalid_implicit_empty_value(self):
     """Test for `parse_params` function - case: invalid params -
     implicit empty value
     """
     with self.assertRaisesMessage(
             ValueError,
             "In chars 5-11 ` TEST=`: "
             'Implicit empty value. Use explicit `""` instead.',
     ):
         utils.parse_params("Test, TEST=")
Ejemplo n.º 5
0
 def test_parse_params_invalid_positional_after_named_arg(self):
     """Test for `parse_params` function - case: invalid params -
     positional argument after named one
     """
     with self.assertRaisesMessage(
             ValueError,
             "In chars 13-18 `4.2 ,`: "
             "Positional argument after named arguments.",
     ):
         utils.parse_params("Test, TEST=1,4.2 ,\"A; B; C\", '386'")
Ejemplo n.º 6
0
 def test_parse_params_mixed(self):
     """Test for `parse_params` function - case: mixed arguments"""
     self.assertEqual(
         utils.parse_params("Test, 1,4.2 ,p_1=\"A; B; C\", TEST='386'"),
         (["Test", "1", "4.2"], {
             "p_1": "A; B; C",
             "TEST": "386"
         }),
     )
Ejemplo n.º 7
0
 def test_parse_params_mixed_quoted(self):
     """Test for `parse_params` function - case: mixed arguments with
     quoted values (comma, space)
     """
     self.assertEqual(
         utils.parse_params("\"a b\",'1,2',a='a b',b=\"1,2\""),
         (["a b", "1,2"], {
             "a": "a b",
             "b": "1,2"
         }),
     )
Ejemplo n.º 8
0
 def test_parse_params_named(self):
     """Test for `parse_params` function - case: keyword arguments"""
     self.assertEqual(
         utils.parse_params("a=Test, b=4.2 ,p_1=\"A; B; C\", TEST='386'"),
         ([], {
             "a": "Test",
             "b": "4.2",
             "p_1": "A; B; C",
             "TEST": "386"
         }),
     )
Ejemplo n.º 9
0
 def test_parse_params_positional(self):
     """Test for `parse_params` function - case: positional arguments"""
     self.assertEqual(
         utils.parse_params("Test, 1,4.2 ,\"A; B; C\", '386'"),
         (["Test", "1", "4.2", "A; B; C", "386"], {}),
     )
Ejemplo n.º 10
0
 def test_parse_params_empty(self):
     """Test for `parse_params` function - case: empty string"""
     self.assertEqual(utils.parse_params(""), ([], {}))