Beispiel #1
0
 def test_should_remove_target_and_rel_if_href_is_internal(self):
     url = 'http://www.%s/foo/bar/' % settings.DOMAIN_NAME
     self.assertEqual(
         '<a href="%s">Foo</a>' % url,
         get_normalised_links(
             '<a href="%s" rel="noopener noreferrer" target="_blank">Foo</a>'
             % url))
Beispiel #2
0
    def process_model(self, model, links, simulate=False, pk=None):
        """
        Process the given model.
        """
        instances = model.objects.all()
        if pk:
            instances = instances.filter(pk=pk)

        i = 0
        n = 0
        for instance in instances:
            if hasattr(instance, 'get_data'):
                data = instance.get_data()
                changed = False
                if data:
                    for slotname, content in data.items():
                        new_content = get_normalised_links(
                            content, self.get_href_rewrite(links))
                        if content != new_content:
                            print '\t%-20s\t%-60s' % (model._meta.verbose_name,
                                                      instance)
                            i += 1
                            if not simulate:
                                data[slotname] = new_content
                                changed = True

                if changed and not simulate:
                    instance.set_data(data)
                    instance.save()

            n += 1

        return i, n
Beispiel #3
0
 def test_should_remove_target_and_rel_if_href_is_internal_leaving_other_attributes_untouched(
         self):
     url = 'http://www.%s/foo/bar/' % settings.DOMAIN_NAME
     self.assertEqual(
         '<a class="btn btn-primary" disabled="" href="%s">Foo</a>' % url,
         get_normalised_links(
             '<a href="%s" rel="noopener noreferrer" target="_blank" class="btn btn-primary" disabled>Foo</a>'
             % url))
Beispiel #4
0
 def test_should_not_remove_beta_prefix_if_not_internal(self):
     self.assertEqual(
         '<a href="https://beta.google.com" rel="noopener noreferrer" target="_blank">Foo</a>',
         get_normalised_links(
             '<a href="https://beta.google.com" rel="noopener noreferrer" target="_blank">Foo</a>'
         ))
Beispiel #5
0
 def test_should_remove_beta_references_for_internal_url(self):
     self.assertEqual(
         '<a href="http://www.%s/foo/bar/">Foo</a>' % settings.DOMAIN_NAME,
         get_normalised_links(
             '<a href="http://beta.%s/foo/bar/" rel="noopener noreferrer" target="_blank">Foo</a>'
             % settings.DOMAIN_NAME))
Beispiel #6
0
 def test_should_remove_target_and_rel_for_email_href(self):
     self.assertEqual(
         '<a href="mailto:[email protected]">Foo</a>',
         get_normalised_links(
             '<a href="mailto:[email protected]" rel="noopener noreferrer" target="_blank">Foo</a>'
         ))
Beispiel #7
0
 def test_should_add_target_and_rel_if_href_is_external(self):
     self.assertEqual(
         '<a href="https://www.google.co.uk/" rel="noopener noreferrer" target="_blank">Foo</a>',
         get_normalised_links(
             '<a href="https://www.google.co.uk/">Foo</a>'))
Beispiel #8
0
 def test_should_return_empty_for_empty(self):
     self.assertEqual('', get_normalised_links(''))