Skip to content

Commit

Permalink
Merge pull request #8 from mrname/api-v1-updates
Browse files Browse the repository at this point in the history
Api v1 updates
  • Loading branch information
mrname committed Jul 19, 2015
2 parents aab7fc6 + 8e44a71 commit 060b843
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ page in HarParser.pages is a HarPage object::
print har_parser.browser
# {u'name': u'Firefox', u'version': u'25.0.1'}

print har_parser.hostname
# 'humanssuck.net'

for page in har_parser.pages:
assert isinstance(page, HarPage, None)
# returns True for each
Expand All @@ -69,6 +72,10 @@ file (see example above) with `har_data=har_data`::
with open('har_data.har', 'r') as f:
har_page = HarPage('page_3', har_data=json.loads(f.read()))

### GET BASIC INFO
har_page.hostname
# 'humanssuck.net'

### WORK WITH LOAD TIMES (all load times are in ms) ###

# Get image load time in milliseconds as rendered by the browser
Expand Down
13 changes: 13 additions & 0 deletions haralyzer/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def version(self):
def creator(self):
return self.har_data['creator']

@cached_property
def hostname(self):
return self.pages[0].hostname


class MultiHarParser(object):
"""
Expand Down Expand Up @@ -461,6 +465,15 @@ def get_total_size(self, entries):

# BEGIN PROPERTIES #

@cached_property
def hostname(self):
"""
Hostname of the initial request
"""
for header in self.entries[0]['request']['headers']:
if header['name'] == 'Host':
return header['value']

@cached_property
def entries(self):
page_entries = []
Expand Down
9 changes: 9 additions & 0 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ def test_time_to_first_byte(har_data):
assert page.time_to_first_byte == 153


def test_hostname(har_data):
"""
Makes sure that the correct hostname is returned.
"""
init_data = har_data('humanssuck.net.har')
page = HarPage(PAGE_ID, har_data=init_data)
assert page.hostname == 'humanssuck.net'


def _correct_file_type(entry, file_types):
for header in entry['response']['headers']:
if header['name'] == 'Content-Type':
Expand Down
1 change: 1 addition & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_init(har_data):
assert har_parser.browser == {'name': 'Firefox', 'version': '25.0.1'}
assert har_parser.version == '1.1'
assert har_parser.creator == {'name': 'Firebug', 'version': '1.12'}
assert har_parser.hostname == 'humanssuck.net'


def test_match_headers(har_data):
Expand Down

0 comments on commit 060b843

Please sign in to comment.