Пример #1
0
def test_web_response_etag_updated(etag, status, expected, expected_etag,
                                   expected_msg, caplog):
    response = web.WebResponse("https://foo.com", {}, expires=1.0, etag=etag)
    new_response = web.WebResponse("https://foo.com", {},
                                   expires=2.0,
                                   etag="efgh",
                                   status_code=status)
    assert response.updated(new_response) == expected
    assert response._etag == expected_etag
    assert expected_msg in caplog.text
Пример #2
0
def web_response_mock(web_track_mock):
    return web.WebResponse(
        "https://api.spotify.com/v1/tracks/abc",
        web_track_mock,
        expires=1000,
        status_code=200,
    )
Пример #3
0
def test_web_response_status_unchanged_from_cache():
    response = web.WebResponse("https://foo.com", {})

    assert not response.status_unchanged

    response.still_valid(ignore_expiry=True)

    assert response.status_unchanged

    response.updated(response)

    assert not response.status_unchanged
Пример #4
0
def test_web_response_etag_updated_different(web_response_mock_etag, caplog):
    new_response = web.WebResponse("https://foo.com", {}, status_code=304)
    assert not web_response_mock_etag.updated(new_response)
    assert "ETag mismatch (different URI) for" in caplog.text
Пример #5
0
def test_web_response_etag_headers(etag, expected):
    response = web.WebResponse("https://foo.com", {}, etag=etag)
    assert response.etag_headers == expected
Пример #6
0
def test_web_response_status_unchanged(status_code, expected):
    response = web.WebResponse("https://foo.com", {}, status_code=status_code)
    assert not response._from_cache
    assert response.status_unchanged == expected
Пример #7
0
def test_web_response_status_ok(status_code, expected):
    response = web.WebResponse("https://foo.com", {}, status_code=status_code)
    assert response.status_ok == expected