Skip to content

Commit

Permalink
Add unit test for chunk_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
boolean5 committed Jul 30, 2020
1 parent 56d48a8 commit 6daca9e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_publish2cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import time

from mock import mock_open, patch

from publish2cloud import chunk_metadata


def test_chunk_metadata():
"""Test getting metadata from the chunk header of a list file."""
chunknum = int(time.time())
# Hash of test-track-digest256.dummytracker.org/
domain_hash = (b"q\xd8Q\xbe\x8b#\xad\xd9\xde\xdf\xa7B\x12\xf0D\xa2"
"\xf2\x1d\xcfx\xeaHi\x7f8%\xb5\x99\x83\xc1\x111")
data = b"a:%d:32:32\n" % chunknum + domain_hash

with patch("test_publish2cloud.open", mock_open(read_data=data)):
with open("base-fingerprinting-track-digest256", "rb") as fp:
metadata = chunk_metadata(fp)

assert metadata["type"] == "a"
assert metadata["num"] == str(chunknum)
assert metadata["hash_size"] == "32"
assert metadata["len"] == "32"
assert metadata["checksum"] == ("043493ecb63c5f143a372a5118d04a44df"
"188f238d2b18e6cd848ae413a01090")

0 comments on commit 6daca9e

Please sign in to comment.