Skip to content

Commit

Permalink
Added more methods to mimic a dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyb3r-Jak3 committed Sep 5, 2020
1 parent 858579f commit 3529e6e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
22 changes: 20 additions & 2 deletions haralyzer/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Mixin Objects"""
"""Mixin Objects that allow for shared methods"""


class GetHeaders(object):
Expand All @@ -21,4 +21,22 @@ def __getitem__(self, item):
return self.raw_entry[item]

def __len__(self):
return len(self.raw_entry)
return len(self.raw_entry)

def get(self, item, default=None):
"""
Mimics dict.get()
"""
return self.raw_entry.get(item, default)

def keys(self):
"""
Mimics dict.keys()
"""
return self.raw_entry.keys()

def items(self):
"""
Mimics dict.items()
"""
return self.raw_entry.items()
8 changes: 8 additions & 0 deletions tests/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,13 @@ def test_backwards(har_data):
assert single_entry["timings"] == {'receive': 0, 'send': 0, 'connect': 0, 'dns': 0, 'wait': 76, 'blocked': 77}
assert len(single_entry) == 9

assert list(single_entry.keys()) == ['serverIPAddress', 'cache', 'startedDateTime', 'pageref', 'request', 'timings', 'connection', 'time', 'response']
assert len(single_entry.items()) == 9
assert single_entry.get("time") == 153
assert single_entry.get("NothingHere", "Default") == "Default"

assert single_entry.request["method"] == "GET"
assert single_entry.request.get("method") == "GET"

assert single_entry.response["status"] == 200
assert single_entry.response.get("status") == 200

0 comments on commit 3529e6e

Please sign in to comment.