Skip to content

Commit

Permalink
Updated doc string and added test for request.cookies and entry heade…
Browse files Browse the repository at this point in the history
…r search
  • Loading branch information
Cyb3r-Jak3 committed Aug 31, 2020
1 parent 2c2d5e4 commit 6af96ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions haralyzer/assets.py
Expand Up @@ -642,6 +642,11 @@ def __init__(self, entry):
self.raw_entry = entry

def get_header_value(self, name):
"""
Returns the header value of the header defined in ``name``
:param name: ``str`` name of the header to get the value of
"""
for x in self.headers:
if x["name"].lower() == name.lower():
return x["value"]
Expand Down
10 changes: 10 additions & 0 deletions haralyzer/sub_classes.py
Expand Up @@ -8,6 +8,11 @@ def __init__(self, entry):
self.raw_entry = entry

def get_header_value(self, name):
"""
Returns the header value of the header defined in ``name``
:param name: ``str`` name of the header to get the value of
"""
for x in self.raw_entry["headers"]:
if x["name"].lower() == name.lower():
return x["value"]
Expand Down Expand Up @@ -79,6 +84,11 @@ def __init__(self, entry):
self.raw_entry = entry

def get_header_value(self, name):
"""
Returns the header value of the header defined in ``name``
:param name: ``str`` name of the header to get the value of
"""
for x in self.raw_entry["headers"]:
if x["name"].lower() == name.lower():
return x["value"]
Expand Down
12 changes: 12 additions & 0 deletions tests/test_entry.py
Expand Up @@ -6,6 +6,9 @@


def test_entry(har_data):
"""
Tests that HarEntry class works
"""
init_data = har_data('humanssuck.net.har')
single_entry = HarPage(PAGE_ID, har_data=init_data).entries[0]
assert isinstance(single_entry, HarEntry)
Expand All @@ -20,11 +23,17 @@ def test_entry(har_data):
assert single_entry.time == 153
assert single_entry.timings == {'receive': 0, 'send': 0, 'connect': 0, 'dns': 0, 'wait': 76, 'blocked': 77}

assert single_entry.get_header_value("X-Accel-Version") == '0.01'


def test_request(har_data):
"""
Tests that HarEntry.request has the correct data
"""
init_data = har_data('humanssuck.net.har')
request = HarPage(PAGE_ID, har_data=init_data).entries[0].request
assert request.accept == "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
assert request.cookies == []
assert request.bodySize == -1
assert request.cacheControl is None
assert request.encoding == "gzip, deflate"
Expand All @@ -42,6 +51,9 @@ def test_request(har_data):


def test_response(har_data):
"""
Tests the HarEntry.response has the correct data
"""
init_data = har_data('humanssuck.net.har')
response = HarPage(PAGE_ID, har_data=init_data).entries[0].response
assert response.bodySize == 238
Expand Down

0 comments on commit 6af96ef

Please sign in to comment.