示例#1
0
def test_create_asset_timeline(har_data):
    """
    Tests the asset timeline function by making sure that it inserts one object
    correctly.
    """
    init_data = har_data('humanssuck.net.har')
    har_parser = HarParser(init_data)

    entry = har_data('single_entry.har')

    # Get the datetime object of the start time and total load time
    time_key = dateutil.parser.parse(entry['startedDateTime'])
    load_time = int(entry['time'])

    asset_timeline = har_parser.create_asset_timeline([entry])

    # The number of entries in the timeline should match the load time
    assert len(asset_timeline) == load_time

    for t in range(1, load_time):
        assert time_key in asset_timeline
        assert len(asset_timeline[time_key]) == 1
        # Compare the dicts
        for key, value in iteritems(entry):
            assert asset_timeline[time_key][0][key] == entry[key]
        time_key = time_key + datetime.timedelta(milliseconds=1)
示例#2
0
def test_create_asset_timeline(har_data):
    """
    Tests the asset timeline function by making sure that it inserts one object
    correctly.
    """
    init_data = har_data('humanssuck.net.har')
    har_parser = HarParser(init_data)

    entry = har_data('single_entry.har')

    # Get the datetime object of the start time and total load time
    time_key = dateutil.parser.parse(entry['startedDateTime'])
    load_time = int(entry['time'])

    asset_timeline = har_parser.create_asset_timeline([entry])

    # The number of entries in the timeline should match the load time
    assert len(asset_timeline) == load_time

    for t in range(1, load_time):
        assert time_key in asset_timeline
        assert len(asset_timeline[time_key]) == 1
        # Compare the dicts
        for key, value in iteritems(entry):
            assert asset_timeline[time_key][0][key] == entry[key]
        time_key = time_key + datetime.timedelta(milliseconds=1)
示例#3
0
 def time_to_first_byte(self):
     """
     Time to first byte of the page request in ms
     """
     initial_entry = self.entries[0]
     ttfb = 0
     for k, v in iteritems(initial_entry['timings']):
         if k != 'receive':
             ttfb += v
     return ttfb
示例#4
0
def _headers_test(parser, entry, test_data, expects, regex):
    """
    Little helper function to test headers matches

    :param parser: Instance of HarParser object
    :param entry: entry object
    :param test_data: ``dict`` of test data
    :param expects: ``bool`` indicating whether the assertion
    should be True/False
    :param regex: ``bool`` indicating whether we should be using regex
    search
    """
    for req_type, data in iteritems(test_data):
        for header, value in iteritems(data):
            is_match = parser.match_headers(entry, req_type,
                                                header, value, regex=regex)
            if expects:
                assert is_match
            else:
                assert not is_match
示例#5
0
def _headers_test(parser, entry, test_data, expects, regex):
    """
    Little helper function to test headers matches

    :param parser: Instance of HarParser object
    :param entry: entry object
    :param test_data: ``dict`` of test data
    :param expects: ``bool`` indicating whether the assertion
    should be True/False
    :param regex: ``bool`` indicating whether we should be using regex
    search
    """
    for req_type, data in iteritems(test_data):
        for header, value in iteritems(data):
            is_match = parser.match_headers(entry,
                                            req_type,
                                            header,
                                            value,
                                            regex=regex)
            if expects:
                assert is_match
            else:
                assert not is_match
示例#6
0
def test_file_types(har_data):
    """
    Test file type properties
    """
    init_data = har_data('cnn.har')
    page = HarPage(PAGE_ID, har_data=init_data)

    file_types = {'image_files': ['image'], 'css_files': ['css'],
                  'js_files': ['javascript'], 'audio_files': ['audio'],
                  'video_files': ['video', 'flash'], 'text_files': ['text'],
                  'html_files': ['html']}

    for k, v in iteritems(file_types):
        for asset in getattr(page, k, None):
            assert _correct_file_type(asset, v)
示例#7
0
def test_file_types(har_data):
    """
    Test file type properties
    """
    init_data = har_data('cnn.har')
    page = HarPage(PAGE_ID, har_data=init_data)

    file_types = {'image_files': ['image'], 'css_files': ['css'],
                  'js_files': ['javascript'], 'audio_files': ['audio'],
                  'video_files': ['video', 'flash'], 'text_files': ['text'],
                  'html_files': ['html']}

    for k, v in iteritems(file_types):
        for asset in getattr(page, k, None):
            assert _correct_file_type(asset, v)