Beispiel #1
0
 def setUp(self):
     self.plugin = LinkGATagger(medium="email", source="source_test")
Beispiel #2
0
class PluginTest(TestCase):

    def setUp(self):
        self.plugin = LinkGATagger(medium="email", source="source_test")

    def test_render_simple(self):
        """
        render simple link with unique track class
        """
        string = '<a href="picknews.com" class="cnc_track_yop"/>'
        exp_result = '<a href="picknews.com?utm_medium=email&utm_source=source_test&utm_campain=yop" class=""/>'
        result = self.plugin.render(string)

        self.assertEquals(result, exp_result)

    def test_render_multi_class(self):
        """
        render simple link with track class included between multiple classes
        """
        string = '<a href="picknews.com" class="class1 cnc_track_yop class2">'
        exp_result = '<a href="picknews.com?utm_medium=email&utm_source=source_test&utm_campain=yop" class="class1 class2"/>'
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_multi_class_multi_attrs(self):
        """
        render simple link with track class included between multiple classes and with multiple attributes everywhere
        """
        string = '<a another="attribute" href="picknews.com?yop=yop" another_one="attribute" class="class1 cnc_track_yop class2"/>'
        exp_result = '<a another="attribute" href="picknews.com?yop=yop&utm_medium=email&utm_source=source_test&utm_campain=yop" another_one="attribute" class="class1 class2"/>'
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_multi_class_multi_attrs_hash(self):
        """
        render simple link with track class included between multiple classes and with multiple attributes everywhere
        """
        string = '<a another="attribute" href="picknews.com#test" class="class1 cnc_track_yop class2" another_one="attribute"/>'
        exp_result = '<a another="attribute" href="picknews.com?utm_medium=email&utm_source=source_test&utm_campain=yop#test" class="class1 class2" another_one="attribute"/>'
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_multi_class_multi_attrs_get_params_and_hash(self):
        """
        render simple link with track class included between multiple classes and with multiple attributes everywhere
        """
        string = '<a another="attribute" href="picknews.com?yop=yop#test" another="attribute" class="class1 cnc_track_yop class2" another_one="attribute"/>'
        exp_result = '<a another="attribute" href="picknews.com?yop=yop&utm_medium=email&utm_source=source_test&utm_campain=yop#test" class="class1 class2" another_one="attribute"/>'
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_with_mailto(self):
        """
        avoid tagging mailto urls
        """
        string = '<a another="attribute" href="mailto:[email protected]" another_yet="attribute" class="class1 cnc_track_yop class2" another="attribute"/>'
        exp_result = '<a another="attribute" href="mailto:[email protected]" another_yet="attribute" class="class1 cnc_track_yop class2"/>'
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_with_complex_html(self):
        """
        complex html code with simple url
        """
        string = '<div>Some text <a href="mailto:[email protected]" class="cnc_track_yopyopy">Hello world</a>Some text </div>'
        exp_result = '<div>Some text <a href="mailto:[email protected]" class="cnc_track_yopyopy">Hello world</a>Some text </div>'
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_with_complex_html_and_multiple_links(self):
        """
        complex html code with simple url
        """
        string = """<div><div>Some text <a href="mailto:[email protected]" class="cnc_track_yopyopy">Hello world</a>Some text </div><a href="picknews.com" class="cnc_track_yopyopy anotherclass">Hey!!!!!#</a></div>"""
        exp_result = """<div><div>Some text <a href="mailto:[email protected]" class="cnc_track_yopyopy">Hello world</a>Some text </div><a href="picknews.com?utm_medium=email&utm_source=source_test&utm_campain=yopyopy" class="anotherclass">Hey!!!!!#</a></div>"""
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_with_more_complex_html_and_multiple_links(self):
        """
        complex html code with simple url
        """
        string = '<div><div>Some text <a href="mailto:[email protected]" class="cnc_track_yopyopy">Hello world</a></div>\
                  <a href="picknews.com" class="cnc_track_yopyopy anotherclass">Hey!!!!!#</a>\
                  <a another="attribute" href="picknews.com?yop=yop#test" another_one="attribute" class="class1 cnc_track_yop class2" another_two="attribute"/>\
                  and text and text and text</div>'
        exp_result = '<div><div>Some text <a href="mailto:[email protected]" class="cnc_track_yopyopy">Hello world</a></div>\
                  <a href="picknews.com?utm_medium=email&utm_source=source_test&utm_campain=yopyopy" class="anotherclass">Hey!!!!!#</a>\
                  <a another="attribute" href="picknews.com?yop=yop&utm_medium=email&utm_source=source_test&utm_campain=yop#test" another_one="attribute" class="class1 class2" another_two="attribute"/>\
                  and text and text and text</div>'
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_simple_text_with_get_params(self):
        """
        simple text with simple url
        """
        string = "Follow http://www.example.com?yop=yop&cnc_track_some_campaign_id to check out our great web app!!"
        exp_result = "Follow http://www.example.com?yop=yop&utm_medium=email&utm_source=source_test&utm_campain=some_campaign_id to check out our great web app!!"
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_simple_text(self):
        """
        simple text with simple url
        """
        string = "Follow http://www.example.com?cnc_track_some_campaign_id to check out our great web app!!"
        exp_result = "Follow http://www.example.com?utm_medium=email&utm_source=source_test&utm_campain=some_campaign_id to check out our great web app!!"
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_simple_text_with_get_params_and_hash(self):
        """
        simple text with simple url
        """
        string = "Follow http://www.example.com?yop=yop&cnc_track_some_campaign_id#hashtest to check out our great web app!!"
        exp_result = "Follow http://www.example.com?yop=yop&utm_medium=email&utm_source=source_test&utm_campain=some_campaign_id#hashtest to check out our great web app!!"
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_simple_text_with_hash(self):
        """
        simple text with simple url
        """
        string = "Follow http://www.example.com?cnc_track_some_campaign_id#hashtest to check out our great web app!!"
        exp_result = "Follow http://www.example.com?utm_medium=email&utm_source=source_test&utm_campain=some_campaign_id#hashtest to check out our great web app!!"
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_render_simple_text_with_multiple_get_params_and_hash(self):
        """
        simple text with simple url
        """
        string = "Follow http://www.example.com?yop=yop&cnc_track_some_campaign_id&truc=chose#hashtest to check out our great web app!!"
        exp_result = "Follow http://www.example.com?yop=yop&utm_medium=email&utm_source=source_test&utm_campain=some_campaign_id&truc=chose#hashtest to check out our great web app!!"
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)

    def test_simple_raw_text(self):
        """
        simple text without any urls
        """
        string = "Follow THIS URL to check out our great web app!!"
        exp_result = "Follow THIS URL to check out our great web app!!"
        result = self.plugin.render(string)
        self.assertEqual(result, exp_result)