Пример #1
0
    def test_gluegun__with_no_default(self):
        offer_dictionary_without_default = {
            "offer_thirty": "30%",
            "offer_fourty": "40%",
        }
        test_offer_string_with_unknown_keys = "Get {{offer_alien}} off . Get {{offer_alien2}} if SUPER user. "
        g1 = Gluegun(offer_dictionary_without_default)
        result_string = g1.glue_it(test_offer_string_with_unknown_keys)

        self.assertEqual(result_string, 'Get NA off . Get NA if SUPER user. ')
Пример #2
0
    def test_gluegun_glueit__liststring_dictionary(self):
        in_string = [
            "Hello my name is {{name}} and {{age}}",
            "{{name}} is a good {{gender}}"
        ]
        in_dictionary = {"name": "Foo", "gender": "woman"}
        sut = Gluegun(in_dictionary)
        result_string_list = sut.glue_it(in_string)

        self.assertEqual(len(result_string_list), 2)
        self.assertEqual(result_string_list[0], 'Hello my name is Foo and NA')
        self.assertEqual(result_string_list[1], 'Foo is a good woman')
Пример #3
0
 def test_gluegun_glueit__string_listdictionary(self):
     in_string = "Hello my name is {{name}} and {{age}}"
     in_dictionary = [{
         "name": "Foo"
     }, {
         "name": "Boo",
         "age": 17
     }, {
         "age": 52
     }]
     sut = Gluegun(in_dictionary)
     result_string_list = sut.glue_it(in_string)
     print(result_string_list)
     self.assertEqual(result_string_list[0], 'Hello my name is Foo and NA')
     self.assertEqual(result_string_list[1], 'Hello my name is Boo and 17')
     self.assertEqual(result_string_list[2], 'Hello my name is NA and 52')
    def test_basic(self):
        #     pup_string = "I Love {{pups}} more than {{octopus}}."
        #     animal_dictionary = {
        #         "pups" : "🐶🐶🐶",
        #         "kittens":"🐱🐱🐱",
        #         "fishes":"🐠🐠🐠",
        #         "octopus":"🐙🐙🐙"
        #     }
        #     pet_string = Gluegun(animal_dictionary)
        #     pet_string.glue_it(pup_string)

        #     pet_string = resolve_string(pup_string, animal_dictionary)

        pet_gluegun = Gluegun({
            "pups": "🐶🐶🐶",
            "kittens": "🐱🐱🐱",
            "fishes": "🐠🐠🐠",
            "octopus": "🐙🐙🐙"
        })

        result = pet_gluegun.glue_it("I Love {{pups}} more than {{octopus}}.")
        self.assertEqual(result, 'I Love 🐶🐶🐶 more than 🐙🐙🐙.')
Пример #5
0
    def test_gluegun__with_list_of_dictionary(self):
        dictionary_list = [
            {
                "A": "a",
                "B": "b"
            },
            {
                "AB": "ab",
                "CD": "cd"
            }
        ]
        sut = Gluegun(dictionary_list)

        for mapie in sut.mapping:
            self.assertTrue(
                "default" in mapie)
Пример #6
0
    def test_gluegun__custom_delimiters(self):
        delimiters = {"start": "[[", "end": "]]"}
        g1 = Gluegun(offer_dictionary, delimiters)
        temp_test_offer_string = test_offer_string.replace("{{", "[[").replace(
            "}}", "]]")
        result_string = g1.glue_it(temp_test_offer_string)
        self.assertEqual(result_string,
                         'Get 30% off . Get 40% if SUPER user. ')

        delimiters = {"start": "<<", "end": ">>"}
        g1 = Gluegun(offer_dictionary, delimiters)
        temp_test_offer_string = test_offer_string.replace("{{", "<<").replace(
            "}}", ">>")
        result_string = g1.glue_it(temp_test_offer_string)
        self.assertEqual(result_string,
                         'Get 30% off . Get 40% if SUPER user. ')
Пример #7
0
 def test_gluegun__with_invalid_type(self):
     with self.assertRaises(Exception):
         Gluegun(27)
Пример #8
0
 def test_gluegun__with_no_parameters_should_not_throw_error(self):
     g1 = Gluegun()
     result_string = g1.glue_it(test_offer_string)
     self.assertEqual(
         result_string, 'Get NA off . Get NA if SUPER user. ')
Пример #9
0
 def test_gluegun(self):
     g1 = Gluegun(offer_dictionary)
     result_string = g1.glue_it(test_offer_string)
     self.assertEqual(
         result_string, 'Get 30% off . Get 40% if SUPER user. ')