-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntest
More file actions
executable file
·49 lines (40 loc) · 1.44 KB
/
runtest
File metadata and controls
executable file
·49 lines (40 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
# -*- coding: utf-8 -*-
# http://google.github.io/styleguide/pyguide.html
import json
import urllib2
import sys
API_URL = 'https://api.pageportrait.com/v1/'
MAPPING = {
'social': ('facebook', 'gplusone', 'linkedin'),
'whois': ('status', 'updated', 'created', 'ip', 'registrar', 'expired'),
# 'mozdata': ('domain-authority', 'links', 'page-authority'),
'webfiles': ('favicon.ico', 'sitemap.xml', 'robots.txt'),
'audience': ('demographics', 'engagement'),
'google': ('safebrowsing', 'mobile', 'pagespeed'),
'alexa': ('country', 'global'),
'content': ('content', 'status', 'headers'),
'pagerank': ('value', ),
'microdata': ('errors', 'tripleGroups', 'totalNumErrors', 'totalNumWarnings')
}
def run():
"""Runs tests."""
for action in MAPPING:
print 'Running action: %s' % action
url = API_URL + action + '?url=https://www.pageportrait.com&key=APITEST'
obj = _get_json(url)
handler = MAPPING[action]
keys = obj.keys()
if type(handler) in (tuple, list):
for key in handler:
if key not in keys:
print 'Action "%s": Key "%s" not in list ["%s"]' % (
action, key, '", "'.join(keys))
sys.exit(1)
def _get_json(url):
"""Gets JSON object by API URL."""
response = urllib2.urlopen(url)
content = response.read()
return json.loads(content)
if __name__ == '__main__':
run()