File: test_fingerprint.py

package info (click to toggle)
python-tuspy 1.0.3-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212 kB
  • sloc: python: 884; makefile: 3
file content (48 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import io
import unittest

from parametrize import parametrize

from tusclient.fingerprint import fingerprint

FILEPATH_TEXT = "tests/sample_files/text.txt"
FILEPATH_BINARY = "tests/sample_files/binary.png"


class FileStorageTest(unittest.TestCase):
    def setUp(self):
        self.fingerprinter = fingerprint.Fingerprint()

    @parametrize(
        "filename",
        [FILEPATH_TEXT, FILEPATH_BINARY],
    )
    def test_get_fingerpint(self, filename: str):
        with open(filename, "rb") as f:
            content = f.read()
        buff = io.BytesIO()
        buff.write(content)
        buff.seek(0)  # reset buffer postion before reading

        with open(filename, "rb") as f:
            self.assertEqual(
                self.fingerprinter.get_fingerprint(buff),
                self.fingerprinter.get_fingerprint(f)
            )

    @parametrize(
        "filename",
        [FILEPATH_TEXT, FILEPATH_BINARY],
    )
    def test_unique_fingerprint(self, filename: str):
        with open(filename, "rb") as f:
            content = f.read()
        buff = io.BytesIO()
        buff.write(content + b's')  # add some salt to change value
        buff.seek(0)  # reset buffer postion before reading

        with open(filename, "rb") as f:
            self.assertNotEqual(
                self.fingerprinter.get_fingerprint(buff),
                self.fingerprinter.get_fingerprint(f)
            )