You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.9 KiB
Python
45 lines
1.9 KiB
Python
"""Tests for fingerprint hashing."""
|
|
from gimme_job.utils.hashing import compute_fingerprint, normalize_for_fingerprint
|
|
|
|
|
|
def test_fingerprint_consistent():
|
|
"""Same inputs always produce the same fingerprint."""
|
|
fp1 = compute_fingerprint("indeed", "Orthodontist", "ABC Dental", "Phoenix AZ", "https://example.com/job/1")
|
|
fp2 = compute_fingerprint("indeed", "Orthodontist", "ABC Dental", "Phoenix AZ", "https://example.com/job/1")
|
|
assert fp1 == fp2
|
|
|
|
|
|
def test_fingerprint_different_sites():
|
|
"""Different site_id produces different fingerprint."""
|
|
fp1 = compute_fingerprint("indeed", "Orthodontist", "ABC Dental", "Phoenix AZ", "https://example.com/job/1")
|
|
fp2 = compute_fingerprint("linkedin", "Orthodontist", "ABC Dental", "Phoenix AZ", "https://example.com/job/1")
|
|
assert fp1 != fp2
|
|
|
|
|
|
def test_fingerprint_case_insensitive():
|
|
"""Fingerprint is case-insensitive for title/company/location."""
|
|
fp1 = compute_fingerprint("indeed", "Orthodontist", "ABC Dental", "Phoenix, AZ", None)
|
|
fp2 = compute_fingerprint("indeed", "orthodontist", "abc dental", "phoenix, az", None)
|
|
assert fp1 == fp2
|
|
|
|
|
|
def test_fingerprint_url_strips_query():
|
|
"""URL query params are stripped for canonicalization."""
|
|
fp1 = compute_fingerprint("indeed", "Orthodontist", "ABC", "AZ", "https://example.com/job/1?ref=abc")
|
|
fp2 = compute_fingerprint("indeed", "Orthodontist", "ABC", "AZ", "https://example.com/job/1?ref=xyz")
|
|
assert fp1 == fp2
|
|
|
|
|
|
def test_fingerprint_no_url():
|
|
"""Fingerprint works without a URL."""
|
|
fp = compute_fingerprint("indeed", "Orthodontist", "ABC Dental", "Phoenix AZ", None)
|
|
assert len(fp) == 64 # SHA256 hex digest
|
|
|
|
|
|
def test_normalize_for_fingerprint_whitespace():
|
|
assert normalize_for_fingerprint(" hello world ") == "hello world"
|
|
|
|
|
|
def test_normalize_for_fingerprint_none():
|
|
assert normalize_for_fingerprint(None) == ""
|