• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IIIF / image-validator / 12285728456

11 Dec 2024 10:07PM UTC coverage: 40.498% (+2.5%) from 37.982%
12285728456

Pull #106

github

glenrobson
Moving to updating pypi via github actions
Pull Request #106: Adding github actions

699 of 1726 relevant lines covered (40.5%)

2.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.73
/iiif_validator/tests/baseurl_redirect.py
1
from .test import BaseTest, ValidatorError
5✔
2
try:
5✔
3
    # python3
4
    from urllib.request import Request, urlopen, HTTPError
5✔
5
    print ('Importing 3')
5✔
6
except ImportError:
×
7
    # fall back to python2
8
    from urllib2 import Request, urlopen, HTTPError
×
9
    print ('Importing 2')
×
10

11

12
class Test_Baseurl_Redirect(BaseTest):
5✔
13
    label = 'Base URL Redirects'
5✔
14
    level = 1
5✔
15
    category = 7
5✔
16
    versions = [u'2.0', u'3.0']
5✔
17
    validationInfo = None
5✔
18

19
    def run(self, result):
5✔
20
        url = result.make_info_url()
×
21
        url = url.replace('/info.json', '')
×
22
        newurl = ''
×
23
        try:
×
24
            r = Request(url)
×
25
            wh = urlopen(r)
×
26
            img = wh.read()   
×
27
            wh.close()
×
28
            newurl = wh.geturl()
×
29
        except HTTPError as e:
×
30
            wh = e        
×
31
            if wh.getcode() >= 300 and wh.getcode() < 400:
×
32
                newurl = wh.headers['Location']
×
33
            else:
34
                newurl = wh.geturl()
×
35
        except Exception as error:
×
36
            raise ValidatorError('url-check', str(error), 301, result, 'Failed to redirect from url: {}.'.format(url))
×
37

38
        if newurl == url:
×
39
            print (wh)
×
40
            print (wh.geturl())
×
41
            print (type(wh))
×
42
            # we didn't redirect
43
            raise ValidatorError('redirect', newurl, '{}/info.json'.format(url), result, 'Failed to redirect from {} to {}/info.json. Response code {}'.format(newurl, url, wh.getcode()))
×
44
        else:
45
            # we must have redirected if our url is not what was requested
46
            result.tests.append('redirect')
×
47
            return result
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc