From 6daca9efac71fe26d29eae618abfe749a75f7758 Mon Sep 17 00:00:00 2001 From: Georgia Kokkinou Date: Mon, 27 Jul 2020 19:16:30 +0300 Subject: [PATCH] Add unit test for chunk_metadata --- tests/test_publish2cloud.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_publish2cloud.py diff --git a/tests/test_publish2cloud.py b/tests/test_publish2cloud.py new file mode 100644 index 0000000..cb82d27 --- /dev/null +++ b/tests/test_publish2cloud.py @@ -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")