1+ import unittest
2+ from .teen_protection import (
3+ analyze_for_cyberbullying ,
4+ analyze_for_inappropriate_content ,
5+ analyze_for_privacy_risks
6+ )
7+
8+ class TestTeenProtection (unittest .TestCase ):
9+
10+ def test_cyberbullying (self ):
11+ """Test the cyberbullying detection."""
12+ # Test case with bullying keywords
13+ text1 = "You are such a loser and an idiot."
14+ result1 = analyze_for_cyberbullying (text1 )
15+ self .assertGreater (result1 ['score' ], 0 )
16+ self .assertIn ("Detected potential cyberbullying keyword: 'loser'" , result1 ['indicators_found' ])
17+ self .assertIn ("Detected potential cyberbullying keyword: 'idiot'" , result1 ['indicators_found' ])
18+
19+ # Test case with no bullying keywords
20+ text2 = "Have a great day!"
21+ result2 = analyze_for_cyberbullying (text2 )
22+ self .assertEqual (result2 ['score' ], 0 )
23+ self .assertEqual (len (result2 ['indicators_found' ]), 0 )
24+
25+ def test_inappropriate_content (self ):
26+ """Test the inappropriate content detection."""
27+ # Test case with inappropriate keywords
28+ text1 = "Don't send nudes or talk about drugs."
29+ result1 = analyze_for_inappropriate_content (text1 )
30+ self .assertGreater (result1 ['score' ], 0 )
31+ self .assertIn ("Detected potential inappropriate content keyword: 'send nudes'" , result1 ['indicators_found' ])
32+ self .assertIn ("Detected potential inappropriate content keyword: 'drugs'" , result1 ['indicators_found' ])
33+
34+ # Test case with no inappropriate keywords
35+ text2 = "This is a perfectly normal conversation."
36+ result2 = analyze_for_inappropriate_content (text2 )
37+ self .assertEqual (result2 ['score' ], 0 )
38+ self .assertEqual (len (result2 ['indicators_found' ]), 0 )
39+
40+ def test_privacy_risks (self ):
41+ """Test the privacy risk detection."""
42+ # Test case with privacy risk keywords
43+ text1 = "My address is 123 Main St and my phone number is 555-1234."
44+ result1 = analyze_for_privacy_risks (text1 )
45+ self .assertGreater (result1 ['score' ], 0 )
46+ self .assertIn ("Detected potential privacy risk keyword: 'my address is'" , result1 ['indicators_found' ])
47+ self .assertIn ("Detected potential privacy risk keyword: 'my phone number is'" , result1 ['indicators_found' ])
48+
49+ # Test case with no privacy risk keywords
50+ text2 = "I like to talk about my hobbies."
51+ result2 = analyze_for_privacy_risks (text2 )
52+ self .assertEqual (result2 ['score' ], 0 )
53+ self .assertEqual (len (result2 ['indicators_found' ]), 0 )
54+
55+ def test_empty_input (self ):
56+ """Test empty input for all analysis types."""
57+ result_cb = analyze_for_cyberbullying ("" )
58+ self .assertEqual (result_cb ['score' ], 0 )
59+ self .assertEqual (len (result_cb ['indicators_found' ]), 0 )
60+
61+ result_ic = analyze_for_inappropriate_content ("" )
62+ self .assertEqual (result_ic ['score' ], 0 )
63+ self .assertEqual (len (result_ic ['indicators_found' ]), 0 )
64+
65+ result_pr = analyze_for_privacy_risks ("" )
66+ self .assertEqual (result_pr ['score' ], 0 )
67+ self .assertEqual (len (result_pr ['indicators_found' ]), 0 )
68+
69+ if __name__ == '__main__' :
70+ unittest .main ()
0 commit comments