Download tests/test_scoring_claims.py from sitcod3/modul-x: direct link, hf CLI and curl.
- Browser
- Download file 5.47 kB
-
https://huggingface.co/spaces/sitcod3/modul-x/resolve/main/tests/test_scoring_claims.py
- Command line
-
hf download hf://spaces/sitcod3/modul-x/tests/test_scoring_claims.py
-
curl -L -o test_scoring_claims.py https://huggingface.co/spaces/sitcod3/modul-x/resolve/main/tests/test_scoring_claims.py
5.47 kB
| import unittest | |
| from app.models import ( | |
| CatchAllResult, | |
| DNSResult, | |
| DisposableResult, | |
| SMTPResult, | |
| SyntaxResult, | |
| ) | |
| from app.validator.scoring import calculate_score | |
| class ScoringClaimTests(unittest.TestCase): | |
| def test_transient_dns_has_fixed_medium_risk_score_and_audit_code(self): | |
| result = calculate_score( | |
| SyntaxResult(passed=True), | |
| DNSResult( | |
| domain_exists=False, | |
| has_mx_records=False, | |
| error_code="timeout", | |
| ), | |
| None, | |
| None, | |
| None, | |
| ) | |
| self.assertEqual(result.score, 50) | |
| self.assertEqual(result.risk_level.value, "medium") | |
| self.assertEqual(result.breakdown["DNS_TRANSIENT_FAILURE"], -50) | |
| def test_missing_mail_routes_is_a_zero_score_hard_failure(self): | |
| result = calculate_score( | |
| SyntaxResult(passed=True), | |
| DNSResult( | |
| domain_exists=True, | |
| has_mx_records=False, | |
| error_code="no_mail_records", | |
| ), | |
| None, | |
| None, | |
| None, | |
| ) | |
| self.assertEqual(result.score, 0) | |
| self.assertEqual(result.risk_level.value, "high") | |
| self.assertEqual(result.breakdown["DNS_MX_MISSING"], -100) | |
| def test_explicit_mailbox_unknown_is_a_zero_score_hard_failure(self): | |
| result = calculate_score( | |
| SyntaxResult(passed=True), | |
| DNSResult(domain_exists=True, has_mx_records=True), | |
| None, | |
| None, | |
| SMTPResult( | |
| verified=False, | |
| smtp_code=550, | |
| smtp_message="550 5.1.1 The recipient does not exist", | |
| ), | |
| ) | |
| self.assertEqual(result.score, 0) | |
| self.assertEqual(result.risk_level.value, "high") | |
| self.assertEqual(result.breakdown["SMTP_MAILBOX_NOT_FOUND"], -100) | |
| def test_legacy_user_unknown_rejection_is_detected_without_enhanced_code(self): | |
| result = calculate_score( | |
| SyntaxResult(passed=True), | |
| DNSResult(domain_exists=True, has_mx_records=True), | |
| None, | |
| None, | |
| SMTPResult( | |
| verified=False, | |
| smtp_code=550, | |
| smtp_message="550 User Unknown", | |
| ), | |
| ) | |
| self.assertEqual(result.score, 0) | |
| self.assertIn("SMTP_MAILBOX_NOT_FOUND", result.breakdown) | |
| def test_inconclusive_smtp_is_medium_risk_not_an_implicit_pass(self): | |
| result = calculate_score( | |
| SyntaxResult(passed=True), | |
| DNSResult(domain_exists=True, has_mx_records=True), | |
| None, | |
| None, | |
| SMTPResult(verified=None, error="SMTP connection refused"), | |
| ) | |
| self.assertEqual(result.score, 70) | |
| self.assertEqual(result.risk_level.value, "medium") | |
| self.assertEqual(result.breakdown["SMTP_CHECK_INCONCLUSIVE"], -30) | |
| def test_disposable_domain_is_invalid(self): | |
| result = calculate_score( | |
| SyntaxResult(passed=True), | |
| DNSResult(domain_exists=True, has_mx_records=True), | |
| DisposableResult( | |
| is_disposable=True, | |
| is_free_provider=False, | |
| is_role_based=False, | |
| ), | |
| None, | |
| None, | |
| ) | |
| self.assertEqual(result.score, 0) | |
| self.assertEqual(result.risk_level.value, "high") | |
| self.assertEqual(result.breakdown["DISPOSABLE_DOMAIN"], -100) | |
| def test_catch_all_never_receives_a_low_risk_score(self): | |
| result = calculate_score( | |
| SyntaxResult(passed=True), | |
| DNSResult(domain_exists=True, has_mx_records=True), | |
| None, | |
| CatchAllResult(is_catch_all=True, confidence=0.95), | |
| SMTPResult(verified=True, smtp_code=250), | |
| ) | |
| self.assertEqual(result.score, 74) | |
| self.assertEqual(result.risk_level.value, "medium") | |
| def test_role_based_address_never_receives_a_low_risk_score(self): | |
| result = calculate_score( | |
| SyntaxResult(passed=True), | |
| DNSResult(domain_exists=True, has_mx_records=True), | |
| DisposableResult( | |
| is_disposable=False, | |
| is_free_provider=False, | |
| is_role_based=True, | |
| ), | |
| None, | |
| SMTPResult(verified=True, smtp_code=250), | |
| ) | |
| self.assertEqual(result.score, 74) | |
| self.assertEqual(result.risk_level.value, "medium") | |
| def test_generic_smtp_550_does_not_claim_mailbox_is_nonexistent(self): | |
| result = calculate_score( | |
| SyntaxResult(passed=True), | |
| DNSResult(domain_exists=True, has_mx_records=True), | |
| None, | |
| None, | |
| SMTPResult(verified=False, smtp_code=550), | |
| ) | |
| self.assertTrue( | |
| any( | |
| "provider policy may make the result inconclusive" in warning | |
| for warning in result.warnings | |
| ) | |
| ) | |
| self.assertFalse( | |
| any("Mailbox does not exist" in warning for warning in result.warnings) | |
| ) | |
| self.assertGreater(result.score, 0) | |
| self.assertNotIn("SMTP_MAILBOX_NOT_FOUND", result.breakdown) | |
| if __name__ == "__main__": | |
| unittest.main() | |