Beispiel #1
0
def test_get_status_code_summary(db_interface):
    request = Request(db_interface)
    timestamp = []
    now = datetime.now(tz=timezone.utc)

    urls = URLs(db_interface)
    url_id = urls.save_url(None, None, "www.internet.de")

    for i in range(-10, 10):
        ts = now + timedelta(seconds=i)
        timestamp.append(ts)
        request.mark_as_requested(
            url_id=url_id,
            status_code=200,
            redirected_url="www.internet1.de",
            requested_at=ts,
        )

    result = request.get_status_code_summary(timestamp[0], timestamp[-1])
    assert result[200] == 20
    result = request.get_status_code_summary(timestamp[1], timestamp[-2])
    assert result[200] == 18
    result = request.get_status_code_summary(
        timestamp[-1], timestamp[-1] + timedelta(seconds=60)
    )
    assert result[200] == 1
    result = request.get_status_code_summary(
        timestamp[0] - timedelta(seconds=60), timestamp[0]
    )
    assert result[200] == 1
Beispiel #2
0
def test_save_url_completly_unique(db_interface, sessionDays, rulesFix):
    u = URLs(db_interface)
    result = []
    for day_id, rule_id in zip(sessionDays, rulesFix):
        result.append(
            u.save_url(date_id=day_id,
                       rule_id=rule_id,
                       url="www.internet.de" + str(day_id)))
    entries = list(zip(sessionDays, rulesFix))
    assert len(entries) == len(result)
Beispiel #3
0
def url_ids(db_interface):
    u = URLs(db_interface)

    url_ids = []
    amount = 10
    for i in range(amount):
        url_ids.append(u.save_url(None, None, str(i)))

    assert count_urls(db_interface) == amount
    return url_ids
Beispiel #4
0
def test_save_url_rule_unique(db_interface, sessionDays, rulesFix):
    """
    Only the combination of url and responsible rule should be unique. This allows for the same url being generated by the session_day_checker and by the date_url_generator, given that the session_day-rule wraps the
    """
    u = URLs(db_interface)
    result = []
    for day_id, rule_id in zip(sessionDays, rulesFix):
        result.append(
            u.save_url(date_id=day_id, rule_id=rule_id, url="www.internet.de"))
    entries = list(zip(sessionDays, rulesFix))
    assert len(entries) == len(result)
Beispiel #5
0
def test_Request_mark_as_requested_get_request_log(
    db_interface,
    url,
    status_code,
    redirected_url,
    document_id,
    requested_at,
):
    request = Request(db_interface)
    urls = URLs(db_interface)

    url_id = None
    if url:
        url_id = urls.save_url(None, None, url)

    # TODO: Test document_id

    id = request.mark_as_requested(
        url_id=url_id,
        status_code=status_code,
        redirected_url=redirected_url,
        requested_at=requested_at,
        document_id=document_id,
    )

    assert type(id) == int

    if url:
        assert type(url_id) == int
    else:
        assert url_id is None

    row = request.get_request_log(id)
    assert row[0] == id
    assert row[1] == url_id
    assert row[2] == document_id
    assert row[3] == requested_at
    assert row[4] == status_code
    assert row[5] == redirected_url
Beispiel #6
0
def todo_setup(db_interface):
    u = URLs(db_interface)
    r = Request(db_interface)
    ru = Rules(db_interface)
    s = SessionDay(db_interface)

    day_id = s.insert_date(date.today())
    rule_ids = ru.register_rules(rule_registry.all)
    session_day_id, name, active = ru.get_rule(rulename="session_day")
    session_url_id = u.save_url(date_id=day_id,
                                rule_id=session_day_id,
                                url="www.internet.de")
    rule_ids.remove(session_url_id)

    r.mark_as_requested(url_id=session_url_id,
                        status_code=200,
                        redirected_url="www.internet1.de")

    return {
        "day_id": day_id,
        "rule_ids": rule_ids,
        "session_url_id": session_url_id
    }