Spaces:
Sleeping
Sleeping
rmm commited on
Commit ·
8a40c2d
1
Parent(s): 8e89085
test: new test for input validation, and fix typo in args
Browse files
src/input/input_validator.py
CHANGED
|
@@ -22,7 +22,7 @@ def generate_random_md5(length:int=16) -> str:
|
|
| 22 |
"""
|
| 23 |
|
| 24 |
# Generate a random string
|
| 25 |
-
random_string = ''.join(random.choices(string.ascii_letters + string.digits,
|
| 26 |
# Encode the string and compute its MD5 hash
|
| 27 |
md5_hash = hashlib.md5(random_string.encode()).hexdigest()
|
| 28 |
return md5_hash
|
|
|
|
| 22 |
"""
|
| 23 |
|
| 24 |
# Generate a random string
|
| 25 |
+
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=length))
|
| 26 |
# Encode the string and compute its MD5 hash
|
| 27 |
md5_hash = hashlib.md5(random_string.encode()).hexdigest()
|
| 28 |
return md5_hash
|
tests/test_input_validator.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
from input.input_validator import generate_random_md5
|
| 3 |
+
|
| 4 |
+
def test_generate_random_md5_length():
|
| 5 |
+
md5_hash = generate_random_md5(16)
|
| 6 |
+
assert len(md5_hash) == 32, "MD5 hash length should be 32 characters"
|
| 7 |
+
|
| 8 |
+
def test_generate_random_md5_uniqueness():
|
| 9 |
+
md5_hash1 = generate_random_md5(16)
|
| 10 |
+
md5_hash2 = generate_random_md5(16)
|
| 11 |
+
assert md5_hash1 != md5_hash2, "MD5 hashes should be unique for different random strings"
|
| 12 |
+
|
| 13 |
+
def test_generate_random_md5_default_length():
|
| 14 |
+
md5_hash = generate_random_md5()
|
| 15 |
+
assert len(md5_hash) == 32, "MD5 hash length should be 32 characters when using default length"
|
| 16 |
+
|
| 17 |
+
def test_generate_random_md5_different_data_lengths():
|
| 18 |
+
md5_hash_8 = generate_random_md5(8)
|
| 19 |
+
md5_hash_32 = generate_random_md5(32)
|
| 20 |
+
assert len(md5_hash_8) == 32, "MD5 hash length should be 32 characters for 8 character input"
|
| 21 |
+
assert len(md5_hash_32) == 32, "MD5 hash length should be 32 characters for 32 character input"
|