Esempio n. 1
0
 def test_parse_data_variables(self):
     variables_mapping = {
         'var_1': 'abc',
         'var_2': 'def',
         'var_3': 123,
         'var_4': {
             'a': 1
         },
         'var_5': True,
         'var_6': None
     }
     assert parser.parse_data('$var_1', variables_mapping) == 'abc'
     assert parser.parse_data('var_1', variables_mapping) == 'var_1'
     assert parser.parse_data('$var_1#XYZ', variables_mapping) == 'abc#XYZ'
     assert parser.parse_data('/$var_1/$var_2/$var_3',
                              variables_mapping) == '/abc/def/123'
     assert parser.parse_string_variables(
         '${func($var_1,$var_2,xyz)}',
         variables_mapping) == '${func(abc,def,xyz)}'
     assert parser.parse_data('$var_3', variables_mapping) == 123
     assert parser.parse_data('$var_4', variables_mapping) == {'a': 1}
     assert parser.parse_data('$var_5', variables_mapping)
     assert parser.parse_data('$var_6', variables_mapping) is None
     assert parser.parse_data(["$var_1", "$var_2"],
                              variables_mapping) == ['abc', 'def']
     assert parser.parse_data({"$var_1": "$var_2"}, variables_mapping) == {
         'abc': 'def'
     }
Esempio n. 2
0
    def test_parse_data_variables(self):
        variables_mapping = {
            "var_1": "abc",
            "var_2": "def",
            "var_3": 123,
            "var_4": {
                "a": 1
            },
            "var_5": True,
            "var_6": None
        }
        self.assertEqual(parser.parse_data("$var_1", variables_mapping), "abc")
        self.assertEqual(parser.parse_data("var_1", variables_mapping),
                         "var_1")
        self.assertEqual(parser.parse_data("$var_1#XYZ", variables_mapping),
                         "abc#XYZ")
        self.assertEqual(
            parser.parse_data("/$var_1/$var_2/var3", variables_mapping),
            "/abc/def/var3")
        self.assertEqual(
            parser.parse_data("/$var_1/$var_2/$var_1", variables_mapping),
            "/abc/def/abc")
        self.assertEqual(
            parser.parse_string_variables("${func($var_1, $var_2, xyz)}",
                                          variables_mapping),
            "${func(abc, def, xyz)}")
        self.assertEqual(parser.parse_data("$var_3", variables_mapping), 123)
        self.assertEqual(parser.parse_data("$var_4", variables_mapping),
                         {"a": 1})
        self.assertEqual(parser.parse_data("$var_5", variables_mapping), True)
        self.assertEqual(parser.parse_data("abc$var_5", variables_mapping),
                         "abcTrue")
        self.assertEqual(parser.parse_data("abc$var_4", variables_mapping),
                         "abc{'a': 1}")
        self.assertEqual(parser.parse_data("$var_6", variables_mapping), None)

        with self.assertRaises(exceptions.VariableNotFound):
            parser.parse_data("/api/$SECRET_KEY", variables_mapping)

        self.assertEqual(
            parser.parse_data(["$var_1", "$var_2"], variables_mapping),
            ["abc", "def"])
        self.assertEqual(
            parser.parse_data({"$var_1": "$var_2"}, variables_mapping),
            {"abc": "def"})