Skip to content

Commit

Permalink
In test_etag_last_modified, check caching headers are updated correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon24 committed Jun 29, 2024
1 parent 32186d3 commit f2276b1
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/test_reader_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,23 @@ def test_etag_last_modified(reader, data_dir, server):
Ensures https://rachelbythebay.com/w/2023/01/18/http/ cannot happen.
"""
etag = b'"12345-67890abcdef12"'
etag = b'"00000-67890abcdef12"'
last_modified = b'Thu, 1 Jan 2020 00:00:00 GMT'

server.set_response(data_dir.joinpath('full.atom').read_text(), etag, last_modified)
url = server.url

reader.add_feed(url)

# server response with caching headers
assert reader.update_feed(url).new == 2
request_line, headers, body = server.request
assert request_line == b'GET / HTTP/1.1'
assert body == b''
assert b'If-None-Match' not in headers
assert b'If-Modified-Since' not in headers

# assert caching headers are used
server.set_response(status_line='304 Not Modified')
assert reader.update_feed(url) is None
request_line, headers, body = server.request
Expand All @@ -187,3 +189,21 @@ def test_etag_last_modified(reader, data_dir, server):
assert ua.endswith(b' (+https://github.com/lemon24/reader)')

# TODO: since we're here, assert accept, and a-im too; subtests, ideally

# server responds with new caching headers
server.set_response(
data_dir.joinpath('empty.atom').read_text(),
b'"11111-67890abcdef12"',
b'Thu, 1 Jan 2020 11:11:11 GMT',
)
assert reader.update_feed(url).new == 0
request_line, headers, body = server.request
assert headers[b'If-None-Match'] == etag
assert headers[b'If-Modified-Since'] == last_modified

# assert new caching headers are used
server.set_response(status_line='304 Not Modified')
assert reader.update_feed(url) is None
request_line, headers, body = server.request
assert headers[b'If-None-Match'] == b'"11111-67890abcdef12"'
assert headers[b'If-Modified-Since'] == b'Thu, 1 Jan 2020 11:11:11 GMT'

0 comments on commit f2276b1

Please sign in to comment.