def test_remove_from_list_use_stopwords_True(self):
        values = [{
            "type": "remove_from_list",
            "keys": ["_req|test"],
            "new_keys": ["_req|test1"],
            "to_remove": ["Canada", "USa", "germany"],
            "use_stopwords": True,
            "ignore_case": True
        }]

        expected_data = {
            "_req": {
                "test": [
                    "Canada", "Argentina", "Cyprus", "Schweden", "Kacke",
                    "Norway", "USA", "Germany", "United Kingdom", "Z"
                ],
                "test1": [
                    "Argentina", "Cyprus", "Schweden", "Norway",
                    "United Kingdom", "Z"
                ]
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out,
                             "remove_from_list_use_stopwords_True failed")
    def test_sub_lists_numbers(self):
        values = [{
            "type":
            "sub_lists",
            "array_key":
            "_req|numbers",
            "sub_lists": [{
                "new_key": "_req|numbers_1",
                "range_end": 4
            }, {
                "new_key": "_req|numbers_2",
                "range_start": 3,
                "range_end": 7
            }]
        }]

        expected_data = {
            "_req": {
                "words": [
                    "Canada", "Argentina", "Cyprus", "Schweden", "Norway",
                    "USA", "Germany", "United Kingdom", "Z"
                ],
                "numbers": [10, 4, 2, 6, 7, 3, 1, 5, 9, 8, 0],
                "numbers_1": [10, 4, 2, 6],
                "numbers_2": [6, 7, 3, 1]
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "sub_lists_numbers failed")
    def test_transform_calculate_min(self):
        values = [
            {
                "type": "calculate",
                "action": "min",
                "keys": [
                    "_req|testarray1",
                    "_req|testarray2"
                ]
            }
        ]

        expected_data = {
            "_req": {
                "testvalue1": 5,
                "testvalue2": 3.7,
                "testarray1": 1,
                "testarray2": 1.75,
                "icon": ["und", "und", "wie", "viel", "wie", "wie", "wir"],
                "array": [{"left": 4.5, "right": 2.7}, {"left": 2.7, "right": 8.5}, {"left": 1.8, "right": 3},
                          {"left": 3.3, "right": 3}]
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "calculate min Failed")
    def test_transform_calculate_round_one(self):
        values = [
            {
                "type": "calculate",
                "action": "round",
                "keys": [
                    "_req|testvalue2"
                ],
                "count": 0
            }
        ]

        expected_data = {
            "_req": {
                "testvalue1": 5,
                "testvalue2": 4,
                "testarray1": [5, 4, 7, 1, 3, 6],
                "testarray2": [9, 4, 12, 7.6, 1.75, 500],
                "icon": ["und", "und", "wie", "viel", "wie", "wie", "wir"],
                "array": [{"left": 4.5, "right": 2.7}, {"left": 2.7, "right": 8.5}, {"left": 1.8, "right": 3},
                          {"left": 3.3, "right": 3}]
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "calculate min Failed")
Ejemplo n.º 5
0
    def test_transform_convert_to_bool(self):
        values = [
            {
                "type": "convert",
                "keys": [
                    "_req|test3"
                ],
                "to": "bool",
                "new_keys": [
                    "_req|result"
                ]
            }
        ]

        expected_data = {
            "_req": {
                "test1": "1.573",
                "test2": 2,
                "test3": "True",
                "result": True,
                "test4": "-45"
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "convert to bool Failed")
Ejemplo n.º 6
0
    def test_length_string(self):
        values = [{
            "type": "length",
            "keys": ["_req|string"],
            "new_keys": ["_req|len_string"]
        }]

        expected_data = {
            "_req": {
                "list": [
                    "Canada", "Argentina", "Cyprus", "Schweden", "Norway",
                    "USA", "Germany", "United Kingdom", "Z"
                ],
                "string":
                "Das ist ein Testfall",
                "tuple": ("Canada", "Argentina", "Cyprus", "Schweden",
                          "Norway", "USA", "Germany", "United Kingdom", "Z"),
                "dict": {
                    "Canada": 5,
                    "Argentina": 3,
                    "Cyprus": 2,
                    "Schweden": 1,
                    "Norway": 4,
                    "USA": 5,
                    "Germany": 7,
                    "United Kingdom": 8,
                    "Z": 10
                },
                "len_string":
                20
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "length string failed")
Ejemplo n.º 7
0
    def test_range(self):
        values = [
            {
                "type": "loop",
                "range_start": 0,
                "range_stop": 3,
                "transform": [
                    {
                        "type": "calculate",
                        "action": "add",
                        "keys": ["_req|value"],
                        "value_right": "_loop",
                    }
                ]
            }
        ]

        expected_data = {
            "_req": {
                "value": 3,
                "values": []
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "loop_all Failed")
    def test_transform_translate_all(self):
        values = [{
            "type":
            "translate",
            "keys": ["_req|test1", "_req|test2", "_req|test3"],
            "new_keys": ["_req|str_test1", "_req|str_test2", "_req|str_test3"],
            "dict": {
                "250": "Regen",
                "350": "Gewitter",
                "550": "Schneesturm",
            }
        }]

        expected_data = {
            "_req": {
                "test1": "250",
                "test2": "350",
                "test3": "550",
                "str_test1": "Regen",
                "str_test2": "Gewitter",
                "str_test3": "Schneesturm",
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "translate Failed")
Ejemplo n.º 9
0
    def test_transform_calculate_add_value_left(self):
        values = [
            {
                "type": "calculate",
                "keys": [
                    "_req|testvalue1"
                ],
                "action": "add",
                "value_left": 3.6,
                "new_keys": [
                    "_req|result"
                ],
                "decimal": 2
            }
        ]

        expected_data = {
            "_req": {
                "testvalue1": 5,
                "testvalue2": 3.7,
                "result": 8.6,
                "testarray1": [5, 4, 7, 1, 3, 6],
                "testarray2": [9, 4, 12, 7.6, 1.75, 500],
                "icon": ["und", "und", "wie", "viel", "wie", "wie", "wir"],
                "array": [{"left": 4.5, "right": 2.7}, {"left": 2.7, "right": 8.5}, {"left": 1.8, "right": 3},
                          {"left": 3.3, "right": 3}]
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "calculate add value left Failed")
Ejemplo n.º 10
0
    def test_idx_is_set_right(self):
        values = [{
            "type":
            "transform_dict",
            "dict_key":
            "_req",
            "transform": [{
                "type": "add_symbol",
                "keys": ["_loop|hallo"],
                "pattern": "{_idx}"
            }]
        }]

        expected_data = {
            "_req": {
                "test": {
                    "hallo": "test"
                },
                "test1": {
                    "hallo": "test1"
                },
                "test2": {
                    "hallo": "test2"
                },
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "transform_dict _idx is Right Failed")
Ejemplo n.º 11
0
    def test_select_one(self):
        values = [{"type": "select", "relevant_keys": ["_req|hallo"]}]

        expected_data = {"_req": {"hallo": 1}}

        out, exp = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(out, exp, "Invalid Selection")
Ejemplo n.º 12
0
 def test_select_all(self):
     values = [{
         "type": "select",
         "relevant_keys": ["_req|hallo", "_req|test", "_req|test2"]
     }]
     out, exp = prepare_test(values, self.data, {"_req": self.data})
     self.assertDictEqual(out, exp, "Invalid Selection")
Ejemplo n.º 13
0
    def test_looped_all(self):
        values = [
            {
                "type": "transform_array",
                "array_key": "_req",
                "transform": [
                    {
                        "type": "add_symbol",
                        "keys": ["_loop|hallo"],
                        "pattern": "test"
                    }
                ]
            }
        ]

        expected_data = {
            "_req": [
                {"hallo": "test"},
                {"hallo": "test"},
                {"hallo": "test"},
            ]
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "transform_array loop_all Failed")
Ejemplo n.º 14
0
    def test_transform_option_false(self):
        values = [{
            "type":
            "option",
            "check":
            "_req|test2",
            "on_true": [{
                "type": "replace",
                "keys": ["_req|text1", "_req|text2"],
                "old_value": ".",
                "new_value": ",",
                "count": 1
            }],
            "on_false": [{
                "type": "replace",
                "keys": ["_req|text1", "_req|text2"],
                "old_value": ".",
                "new_value": ","
            }]
        }]

        expected_data = {
            "_req": {
                "test1": True,
                "test2": False,
                "text1": "1,2,3,4,5",
                "text2": "6,7,8,9,10"
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "option false Failed")
    def test_select_range_without_start(self):
        values = [{
            "type": "select_range",
            "array_key": "_req|test",
            "range_end": 3,
        }]

        exp, out = prepare_test(values, self.data, {"_req": self.data})
        self.assertDictEqual(exp, out, "Select Range One Failed")
Ejemplo n.º 16
0
    def test_add_data(self):
        values = [{
            "type": "add_data",
            "new_keys": ["_req|test1"],
            "data": "1"
        }]

        expected_data = {"_req": {"test": "test", "test1": "1"}}

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "add_data Failed")
Ejemplo n.º 17
0
    def test_append_single(self):
        values = [{
            "type": "append",
            "keys": ["_req|test|0|test"],
            "new_keys": ["_req|hallo"]
        }]

        expected_data = {"_req": {**self.data, **{"hallo": [2]}}}

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(out, exp, "Append Single Invalid")
    def test_select_one(self):
        values = [{
            "type": "select_range",
            "array_key": "_req|test",
            "range_start": 0,
            "range_end": 1,
        }]

        expected_data = {"_req": {"test": ["hallo"]}}

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "Select Range One Failed")
    def test_wind_direction_test2(self):
        values = [{
            "type": "wind_direction",
            "key": "_req|test2",
            "dict": {
                "west": {
                    "0": "West",
                    "1": "Westen"
                },
                "southwest": {
                    "0": "Südwest",
                    "1": "Südwesten"
                },
                "northwest": {
                    "0": "Nordwest",
                    "1": "Nordwesten"
                },
                "south": {
                    "0": "Süd",
                    "1": "Süden"
                },
                "east": {
                    "0": "Ost",
                    "1": "Osten"
                },
                "southeast": {
                    "0": "Südost",
                    "1": "Südosten"
                },
                "northeast": {
                    "0": "Nordost",
                    "1": "Nordosten"
                },
                "north": {
                    "0": "Nord",
                    "1": "Norden"
                }
            },
            "delimiter": "-"
        }]

        expected_data = {
            "_req": {
                "test1": "south",
                "test2": "Süd-Südwest",
                "test3": "east",
                "test4": "southwest",
                "test5": "east-southeast"
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "Wind direction Failed")
Ejemplo n.º 20
0
 def test_transform_add_symbol_multi(self):
     values = [{
         "type": "add_symbol",
         "keys": ["_req|test", "_req|hallo"],
         "pattern": "{_key} 1"
     }]
     expected_data = {
         "_req": {
             "test": "test 1",
             "hallo": "Hallo 1",
             "test2": "visuanalytics"
         }
     }
     exp, out = prepare_test(values, self.data, expected_data)
     self.assertDictEqual(exp, out, "add_symbol Multi Failed")
Ejemplo n.º 21
0
    def test_alias(self):
        values = [{
            "type": "alias",
            "keys": ["_req|test"],
            "new_keys": ["_req|test2"]
        }]

        expected_data = {
            "_req": {
                "test2": "test",
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "Select Range One Failed")
Ejemplo n.º 22
0
def test_delete_all(self):
    values = [
        {
            "type": "delete",
            "keys": [
                "_req|hallo",
                "_req|test",
                "_req|test2"
            ]
        }
    ]

    expected_data = {}
    out, exp = prepare_test(values, self.data, expected_data)
    self.assertDictEqual(out, exp, "Invalid Deletion")
    def test_normalize_words(self):
        values = [{
            "type": "normalize_words",
            "keys": ["_req|test"],
            "new_keys": ["_req|test1"]
        }]

        expected_data = {
            "_req": {
                "test": ["canada", "CANADA", "CaNaDa", "cAnAdA", "Canada"],
                "test1": ["canada", "canada", "canada", "canada", "canada"]
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "normalize words failed")
    def test_upper_case(self):
        values = [{
            "type": "upper_case",
            "keys": ["_req|test"],
            "new_keys": ["_req|test1"]
        }]

        expected_data = {
            "_req": {
                "test": ["canada", "CANADA", "CaNaDa", "cAnAdA", "Canada"],
                "test1": ["CANADA", "CANADA", "CANADA", "CANADA", "CANADA"]
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "upper case failed")
Ejemplo n.º 25
0
    def test_date_now(self):
        values = [{
            "type": "date_now",
            "new_key": "_req|date",
            "format": "%Y-%m-%d"
        }]

        expected_data = {
            "_req": {
                "timestamp": 1592758688.7606313,
                "date": datetime.now().strftime("%Y-%m-%d")
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "Select Range One Failed")
Ejemplo n.º 26
0
    def test_weekday(self):
        values = [{
            "type": "date_weekday",
            "keys": ["_req|date"],
            "given_format": "%Y-%m-%d"
        }]

        expected_data = {
            "_req": {
                "timestamp": 1592758688.7606313,
                "date": "Sonntag"
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "Select Range One Failed")
    def test_random_value_one(self):
        random.seed(4)
        values = [{
            "type": "random_value",
            "array": ["Text 1", "Text 2", "Text 3", "Text 4"],
            "new_keys": ["_req|test3"]
        }]
        expected_data = {
            "_req": {
                "test1": "2.5",
                "test2": "2.4.6.2.5",
                "test3": "Text 2"
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "Random Value Failed")
Ejemplo n.º 28
0
    def test_transform_copy_replace_old(self):
        values = [{
            "type": "copy",
            "keys": ["_req|test"],
            "new_keys": ["_req|test2"]
        }]

        expected_data = {
            "_req": {
                "test": "test1",
                "hallo": "Hallo",
                "test2": "test1"
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "copy overwrite old Failed")
Ejemplo n.º 29
0
    def test_join(self):
        values = [{
            "type": "join",
            "keys": ["_req|list"],
            "new_keys": ["_req|string"],
            "delimiter": " "
        }]

        expected_data = {
            "_req": {
                "list": ["Das", "ist", "ein", "Testfall"],
                "string": "Das ist ein Testfall"
            }
        }

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(exp, out, "join failed")
Ejemplo n.º 30
0
    def test_append_multi(self):
        values = [{
            "type":
            "transform_array",
            "array_key":
            "_req|test",
            "transform": [{
                "type": "append",
                "keys": ["_loop|test"],
                "new_keys": ["_req|hallo"]
            }]
        }]

        expected_data = {"_req": {**self.data, **{"hallo": [2, 3, 3, 6, 1]}}}

        exp, out = prepare_test(values, self.data, expected_data)
        self.assertDictEqual(out, exp, "Append Multi Invalid")