~nskaggs/help-app/functional-test-template

« back to all changes in this revision

Viewing changes to internals/tests/test_links.py

  • Committer: Daniel Holbach
  • Date: 2015-04-08 12:34:32 UTC
  • mto: This revision was merged to the branch mainline in revision 135.
  • Revision ID: daniel.holbach@canonical.com-20150408123432-a5ctzpsv95pcponz
split out link checking functionality into utils.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import subprocess
6
6
import tempfile
7
7
from unittest import TestCase
8
 
import urllib.parse
9
8
 
10
 
from translations.utils import use_top_level_dir
 
9
from translations.utils import (
 
10
    link_is_anchor,
 
11
    link_is_local,
 
12
    use_top_level_dir,
 
13
)
11
14
 
12
15
 
13
16
def require_build(build):
34
37
    def handle_starttag(self, tag, attrs):
35
38
        if tag == "a":
36
39
            for name, value in attrs:
37
 
                if name == "href":
38
 
                    url = urllib.parse.urlparse(value)
39
 
                    if not value.startswith('#') and \
40
 
                       url.netloc in [None, '', 'localhost']:
41
 
                        self.links += [value]
 
40
                if name == "href" and not link_is_anchor(value) and \
 
41
                   link_is_local(value):
 
42
                    self.links += [value]
42
43
 
43
44
    def reload(self):
44
45
        links = self.links