Ejemplo n.º 1
0
def test_for_request():
    ld = solution_4.LogDicts(logfilename)
    matching_requests = ld.for_request("/robots.txt")
    assert len(matching_requests) == 16
    assert all([
        '/robots.txt' in one_item['request'] for one_item in matching_requests
    ])
Ejemplo n.º 2
0
def test_sort_by_request():
    ld = solution_4.LogDicts(logfilename)
    sorted_ld = ld.dicts(key=operator.itemgetter('request'))

    assert sorted_ld[0]['request'] <= sorted_ld[1]['request']
    assert sorted_ld[0]['request'] <= sorted_ld[-1]['request']
    assert sorted_ld[-2]['request'] <= sorted_ld[-1]['request']
Ejemplo n.º 3
0
def test_sort_by_ip_address():
    ld = solution_4.LogDicts(logfilename)
    sorted_ld = ld.dicts(key=operator.itemgetter('ip_address'))

    assert sorted_ld[0]['ip_address'] <= sorted_ld[1]['ip_address']
    assert sorted_ld[0]['ip_address'] <= sorted_ld[-1]['ip_address']
    assert sorted_ld[-2]['ip_address'] <= sorted_ld[-1]['ip_address']
Ejemplo n.º 4
0
def test_for_ip():
    ld = solution_4.LogDicts(logfilename)
    matching_requests = ld.for_ip("65.55.106.183")
    assert len(matching_requests) == 2
    assert all([
        one_item['ip_address'] == '65.55.106.183'
        for one_item in matching_requests
    ])
Ejemplo n.º 5
0
def test_iterdicts_returns_iterator_dicts():
    ld = solution_4.LogDicts(logfilename)
    result = ld.iterdicts()
    assert iter(result) == result

    result_list = list(result)
    assert type(result_list) == list

    assert all([type(one_item) == dict for one_item in result])
Ejemplo n.º 6
0
def test_for_ip_partial():
    """Check exact IP is matched"""
    ld = solution_4.LogDicts(logfilename)
    matching_requests = ld.for_ip("65.55.106.1")
    # "65.55.106.183" shall not found
    assert len(matching_requests) == 0
Ejemplo n.º 7
0
def test_dicts_returns_list_of_dicts():
    ld = solution_4.LogDicts(logfilename)
    result = ld.dicts()
    assert type(result) == list
    assert all([type(one_item) == dict for one_item in result])
Ejemplo n.º 8
0
def test_latest():
    ld = solution_4.LogDicts(logfilename)
    latest = ld.latest()

    sorted_ld = ld.dicts(key=operator.itemgetter('timestamp'))
    assert sorted_ld[-1]['timestamp'] == latest['timestamp']
Ejemplo n.º 9
0
def test_earliest():
    ld = solution_4.LogDicts(logfilename)
    earliest = ld.earliest()

    sorted_ld = ld.dicts(key=operator.itemgetter('timestamp'))
    assert sorted_ld[0]['timestamp'] == earliest['timestamp']