def test_generate_md5_hash(self):
    with tempfile.NamedTemporaryFile() as tf:
        two_megabytes = ((2 * 1024) * 1024)
        tf.write(os.urandom(two_megabytes))
        tf.flush()
        tf.seek(0)
        checksum_full = hashlib.md5(tf.read()).digest()
        digest_full = base64.encodestring(checksum_full).decode('UTF-8').strip()
        tf.seek(0)
        digest_chunk = generate_md5_hash(tf.name)
        self.assertEqual(digest_chunk, digest_full)
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=128))
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=256))
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=1024))
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=100000000))
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=(- 1)))
        tf.seek(0)
        self.assertNotEqual(digest_full, generate_md5_hash(tf.name, block_size=0))
def test_generate_md5_hash(self):
    with tempfile.NamedTemporaryFile() as tf:
        two_megabytes = ((2 * 1024) * 1024)
        tf.write(os.urandom(two_megabytes))
        tf.flush()
        tf.seek(0)
        checksum_full = hashlib.md5(tf.read()).digest()
        digest_full = base64.encodestring(checksum_full).decode('UTF-8').strip()
        tf.seek(0)
        digest_chunk = generate_md5_hash(tf.name)
        self.assertEqual(digest_chunk, digest_full)
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=128))
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=256))
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=1024))
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=100000000))
        tf.seek(0)
        self.assertEqual(digest_full, generate_md5_hash(tf.name, block_size=(- 1)))
        tf.seek(0)
        self.assertNotEqual(digest_full, generate_md5_hash(tf.name, block_size=0))