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 27, 2020
1 parent 56d48a8 commit af55d55
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_publish2cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import hashlib
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())
domain = "base-fingerprinting-track-digest256.dummytracker.org/"
domain_hash = hashlib.sha256(domain.encode("utf-8")).digest()
hash_size = hashlib.sha256().digest_size
header = b"a:%d:%d:%d\n" % (chunknum, hash_size, hash_size)
data = header + 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"] == str(hash_size)
assert metadata["len"] == str(hash_size)
assert metadata["checksum"] == hashlib.sha256(domain_hash).hexdigest()

0 comments on commit af55d55

Please sign in to comment.