mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
Add WarcWriter warc_filename unit test
Use custom ``warc_filename`` option and check that the created WARC filename follows the defined pattern.
This commit is contained in:
parent
ec86f2b3df
commit
d2ce61aec9
@ -163,3 +163,27 @@ def test_special_dont_write_prefix():
|
|||||||
wwt.stop.set()
|
wwt.stop.set()
|
||||||
wwt.join()
|
wwt.join()
|
||||||
|
|
||||||
|
|
||||||
|
def test_warc_writer_filename(tmpdir):
|
||||||
|
"""Test if WarcWriter is writing WARC files with custom filenames.
|
||||||
|
"""
|
||||||
|
recorder = ProxyingRecorder(None, None, 'sha1', url='http://example.com')
|
||||||
|
recorded_url = RecordedUrl(
|
||||||
|
url='http://example.com', content_type='text/plain', status=200,
|
||||||
|
client_ip='127.0.0.2', request_data=b'abc',
|
||||||
|
response_recorder=recorder, remote_ip='127.0.0.3',
|
||||||
|
timestamp=datetime.utcnow())
|
||||||
|
|
||||||
|
dirname = os.path.dirname(str(tmpdir.mkdir('test-warc-writer')))
|
||||||
|
wwriter = WarcWriter(Options(directory=dirname, prefix='foo',
|
||||||
|
warc_filename='{timestamp17}-{prefix}-{timestamp14}-{serialno}'))
|
||||||
|
wwriter.write_records(recorded_url)
|
||||||
|
warcs = [fn for fn in os.listdir(dirname)]
|
||||||
|
assert warcs
|
||||||
|
target_warc = os.path.join(dirname, warcs[0])
|
||||||
|
assert target_warc
|
||||||
|
parts = warcs[0].split('-')
|
||||||
|
assert len(parts[0]) == 17
|
||||||
|
assert parts[1] == 'foo'
|
||||||
|
assert len(parts[2]) == 14
|
||||||
|
assert parts[3] == '00000.warc.open'
|
||||||
|
@ -105,7 +105,7 @@ class WarcWriter:
|
|||||||
Extension ``.warc`` or ``.warc.gz`` is appended automatically.
|
Extension ``.warc`` or ``.warc.gz`` is appended automatically.
|
||||||
"""
|
"""
|
||||||
hostname = socket.getfqdn()
|
hostname = socket.getfqdn()
|
||||||
shorthostname = hostname.split(',')[0]
|
shorthostname = hostname.split('.')[0]
|
||||||
fname = self.warc_filename.format(prefix=self.prefix,
|
fname = self.warc_filename.format(prefix=self.prefix,
|
||||||
timestamp14=self.timestamp14(),
|
timestamp14=self.timestamp14(),
|
||||||
timestamp17=self.timestamp17(),
|
timestamp17=self.timestamp17(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user