Skip to content

Commit

Permalink
Merge pull request #29 from mrname/optional_page_title
Browse files Browse the repository at this point in the history
Optional page title
  • Loading branch information
mrname committed Oct 6, 2019
2 parents abc296e + ca52b51 commit 7f49310
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ matrix:
fast_finish: true
allow_failures:
- python: "nightly"
- python: "3.2"
python:
- "2.7"
- "3.4"
Expand Down
2 changes: 1 addition & 1 deletion haralyzer/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def __init__(self, page_id, har_parser=None, har_data=None):
for page in raw_data['pages']:
if page['id'] == self.page_id:
valid = True
self.title = page['title']
self.title = page.get('title', '')
self.startedDateTime = page['startedDateTime']
self.pageTimings = page['pageTimings']

Expand Down
1 change: 1 addition & 0 deletions tests/data/no_title.har
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"log": {"pages": [{"id": "page_3", "startedDateTime": "2015-02-22T19:28:12.136-08:00", "pageTimings": {"onLoad": 567, "onContentLoad": 543}}], "browser": {"version": "25.0.1", "name": "Firefox"}, "entries": [{"serverIPAddress": "216.70.110.121", "cache": {}, "startedDateTime": "2015-02-22T19:28:12.136-08:00", "pageref": "page_3", "request": {"cookies": [], "url": "http://humanssuck.net/", "queryString": [], "headers": [{"name": "Host", "value": "humanssuck.net"}, {"name": "User-Agent", "value": "Mozilla/5.0 (X11; Linux i686 on x86_64; rv:25.0) Gecko/20100101 Firefox/25.0"}, {"name": "Accept", "value": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}, {"name": "Accept-Language", "value": "en-US,en;q=0.5"}, {"name": "Accept-Encoding", "value": "gzip, deflate"}, {"name": "Connection", "value": "keep-alive"}], "headersSize": 292, "bodySize": -1, "method": "GET", "httpVersion": "HTTP/1.1"}, "timings": {"receive": 0, "send": 0, "connect": 0, "dns": 0, "wait": 76, "blocked": 77}, "connection": "80", "time": 153, "response": {"status": 200, "cookies": [], "statusText": "OK", "content": {"mimeType": "text/html", "text": "<!DOCTYPE HTML>\n<html>\r\n<head>humanssuck.net\n<link rel=\"stylesheet\" type=\"text/css\" href=\"test.css\"></head>\r\n<body>\r\n<img src=\"screen_login.gif\">\n<script src=\"jquery-1.7.1.min.js\"></script>\n<video width=\"320\" height=\"240\" controls>\n\t<source src=\"test_video.mp4\" type=\"video/mp4\">\n</video>\n</body>\r\n</html>\r\n\n", "size": 308}, "headers": [{"name": "Server", "value": "nginx"}, {"name": "Date", "value": "Mon, 23 Feb 2015 03:28:12 GMT"}, {"name": "Content-Type", "value": "text/html; charset=UTF-8"}, {"name": "Transfer-Encoding", "value": "chunked"}, {"name": "Connection", "value": "keep-alive"}, {"name": "Vary", "value": "Accept-Encoding"}, {"name": "X-Accel-Version", "value": "0.01"}, {"name": "Last-Modified", "value": "Mon, 23 Feb 2015 03:22:35 GMT"}, {"name": "Etag", "value": "\"3e20f0c-134-50fb8e9e3f6be\""}, {"name": "X-Powered-By", "value": "PleskLin"}, {"name": "Content-Encoding", "value": "gzip"}], "headersSize": 338, "redirectURL": "", "bodySize": 238, "httpVersion": "HTTP/1.1"}}, {"serverIPAddress": "216.70.110.121", "cache": {}, "startedDateTime": "2015-02-22T19:28:12.319-08:00", "pageref": "page_3", "request": {"cookies": [], "url": "http://humanssuck.net/test.css", "queryString": [], "headers": [{"name": "Host", "value": "humanssuck.net"}, {"name": "User-Agent", "value": "Mozilla/5.0 (X11; Linux i686 on x86_64; rv:25.0) Gecko/20100101 Firefox/25.0"}, {"name": "Accept", "value": "text/css,*/*;q=0.1"}, {"name": "Accept-Language", "value": "en-US,en;q=0.5"}, {"name": "Accept-Encoding", "value": "gzip, deflate"}, {"name": "Referer", "value": "http://humanssuck.net/"}, {"name": "Connection", "value": "keep-alive"}], "headersSize": 288, "bodySize": -1, "method": "GET", "httpVersion": "HTTP/1.1"}, "timings": {"receive": 0, "send": 0, "connect": 0, "dns": 0, "wait": 76, "blocked": 0}, "connection": "80", "time": 76, "response": {"status": 200, "cookies": [], "statusText": "OK", "content": {"mimeType": "text/css", "text": "testing\n", "size": 8}, "headers": [{"name": "Server", "value": "nginx"}, {"name": "Date", "value": "Mon, 23 Feb 2015 03:28:12 GMT"}, {"name": "Content-Type", "value": "text/css"}, {"name": "Content-Length", "value": "8"}, {"name": "Connection", "value": "keep-alive"}, {"name": "X-Accel-Version", "value": "0.01"}, {"name": "Last-Modified", "value": "Tue, 22 Jan 2013 08:05:08 GMT"}, {"name": "Etag", "value": "\"3e21423-8-4d3dc093b7500\""}, {"name": "Accept-Ranges", "value": "bytes"}, {"name": "Cache-Control", "value": "max-age=2592000"}, {"name": "Expires", "value": "Wed, 25 Mar 2015 03:28:12 GMT"}, {"name": "X-Powered-By", "value": "PleskLin"}], "headersSize": 358, "redirectURL": "", "bodySize": 8, "httpVersion": "HTTP/1.1"}}, {"serverIPAddress": "216.70.110.121", "cache": {}, "startedDateTime": "2015-02-22T19:28:12.319-08:00", "pageref": "page_3", "request": {"cookies": [], "url": "http://humanssuck.net/screen_login.gif", "queryString": [], "headers": [{"name": "Host", "value": "humanssuck.net"}, {"name": "User-Agent", "value": "Mozilla/5.0 (X11; Linux i686 on x86_64; rv:25.0) Gecko/20100101 Firefox/25.0"}, {"name": "Accept", "value": "image/png,image/*;q=0.8,*/*;q=0.5"}, {"name": "Accept-Language", "value": "en-US,en;q=0.5"}, {"name": "Accept-Encoding", "value": "gzip, deflate"}, {"name": "Referer", "value": "http://humanssuck.net/"}, {"name": "Connection", "value": "keep-alive"}], "headersSize": 311, "bodySize": -1, "method": "GET", "httpVersion": "HTTP/1.1"}, "timings": {"receive": 75, "send": 0, "connect": 76, "dns": 0, "wait": 76, "blocked": 77}, "connection": "80", "time": 304, "response": {"status": 200, "cookies": [], "statusText": "OK", "content": {"mimeType": "image/gif", "size": 23591}, "headers": [{"name": "Server", "value": "nginx"}, {"name": "Date", "value": "Mon, 23 Feb 2015 03:28:12 GMT"}, {"name": "Content-Type", "value": "image/gif"}, {"name": "Content-Length", "value": "23591"}, {"name": "Last-Modified", "value": "Mon, 23 Feb 2015 03:14:47 GMT"}, {"name": "Connection", "value": "keep-alive"}, {"name": "Cache-Control", "value": "max-age=31536000"}, {"name": "Expires", "value": "Tue, 23 Feb 2016 03:28:12 GMT"}, {"name": "X-Powered-By", "value": "PleskLin"}, {"name": "Accept-Ranges", "value": "bytes"}], "headersSize": 308, "redirectURL": "", "bodySize": 23591, "httpVersion": "HTTP/1.1"}}, {"serverIPAddress": "216.70.110.121", "cache": {}, "startedDateTime": "2015-02-22T19:28:12.319-08:00", "pageref": "page_3", "request": {"cookies": [], "url": "http://humanssuck.net/jquery-1.7.1.min.js", "queryString": [], "headers": [{"name": "Host", "value": "humanssuck.net"}, {"name": "User-Agent", "value": "Mozilla/5.0 (X11; Linux i686 on x86_64; rv:25.0) Gecko/20100101 Firefox/25.0"}, {"name": "Accept", "value": "*/*"}, {"name": "Accept-Language", "value": "en-US,en;q=0.5"}, {"name": "Accept-Encoding", "value": "gzip, deflate"}, {"name": "Referer", "value": "http://humanssuck.net/"}, {"name": "Connection", "value": "keep-alive"}], "headersSize": 284, "bodySize": -1, "method": "GET", "httpVersion": "HTTP/1.1"}, "timings": {"receive": 152, "send": 0, "connect": 0, "dns": 0, "wait": 81, "blocked": 77}, "connection": "80", "time": 310, "response": {"status": 200, "cookies": [], "statusText": "OK", "content": {"mimeType": "application/x-javascript", "text": "/*! jQuery v1.7.1 jquery.com | jquery.org/license */\n(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cv(a){if(!ck[a]){var b=c.body,d=f(\"<\"+a+\">\").appendTo(b),e=d.css(\"display\");d.remove();if(e===\"none\"||e===\"\"){cl||(cl=c.createElement(\"iframe\"),cl.frameBorder=cl.width=cl.height=0),b.appendChild(cl);if(!cm||!cl.createElement)cm=(cl.contentWindow||cl.contentDocument).document,cm.write((c.compatMode===\"CSS1Compat\"?\"<!doctype html>\":\"\")+\"<html><body>\"),cm.close();d=cm.createElement(a),cm.body.appendChild(d),e=f.css(d,\"display\"),b.removeChild(cl)}ck[a]=e}return ck[a]}function cu(a,b){var c={};f.each(cq.concat.apply([],cq.slice(0,b)),function(){c[this]=a});return c}function ct(){cr=b}function cs(){setTimeout(ct,0);return cr=f.now()}function cj(){try{return new a.ActiveXObject(\"Microsoft.XMLHTTP\")}catch(b){}}function ci(){try{return new a.XMLHttpRequest}catch(b){}}function cc(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d... [truncated to save space (92843 more bytes)]", "size": 93867}, "headers": [{"name": "Server", "value": "nginx"}, {"name": "Date", "value": "Mon, 23 Feb 2015 03:28:12 GMT"}, {"name": "Content-Type", "value": "application/x-javascript"}, {"name": "Last-Modified", "value": "Mon, 23 Feb 2015 03:16:00 GMT"}, {"name": "Transfer-Encoding", "value": "chunked"}, {"name": "Connection", "value": "keep-alive"}, {"name": "Vary", "value": "Accept-Encoding"}, {"name": "Cache-Control", "value": "max-age=2592000"}, {"name": "Expires", "value": "Wed, 25 Mar 2015 03:28:12 GMT"}, {"name": "X-Powered-By", "value": "PleskLin"}, {"name": "Content-Encoding", "value": "gzip"}], "headersSize": 352, "redirectURL": "", "bodySize": 38367, "httpVersion": "HTTP/1.1"}}], "version": "1.1", "creator": {"version": "1.12", "name": "Firebug"}}}
8 changes: 8 additions & 0 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def test_init(har_data):
page.entries[index + 1]['startedDateTime'])
assert current_date <= next_date

def test_no_title(har_data):
'''
A page with no title should set the title property as an empty string
instead of throwing an exeption.
'''
init_data = har_data('no_title.har')
page = HarPage(PAGE_ID, har_data=init_data)
assert page.title == ''

def test_filter_entries(har_data):
"""
Expand Down

0 comments on commit 7f49310

Please sign in to comment.