1
+ import unittest
2
+ from utils import InputValidator
3
+
4
+ class TestValidator (unittest .TestCase ):
5
+ def setUp (self ):
6
+ self .validator = InputValidator ()
7
+
8
+ def test_ip_validation (self ):
9
+ output = self .validator .validate ("192.168.1.1" )
10
+ self .assertTrue (output [0 ][0 ])
11
+ self .assertEqual (output [0 ][1 ], "input: ipv4 address" )
12
+
13
+ def test_email_validation (self ):
14
+ output = self .validator .validate ("test@test.com" )
15
+ self .assertTrue (output [0 ][0 ])
16
+ self .assertEqual (output [0 ][1 ], "input: email address" )
17
+
18
+ def test_domain_validation (self ):
19
+ output = self .validator .validate ("google.com" )
20
+ self .assertTrue (output [0 ][0 ])
21
+ self .assertEqual (output [0 ][1 ], "input: domain" )
22
+
23
+ def test_url_validation (self ):
24
+ output = self .validator .validate ("https://www.google.com" )
25
+ self .assertTrue (output [0 ][0 ])
26
+ self .assertEqual (output [0 ][1 ], "input: url" )
27
+
28
+ def test_md5_validation (self ):
29
+ output = self .validator .validate ("05f3044a84e6149e80af2c787433c375" )
30
+ self .assertTrue (output [0 ][0 ])
31
+ self .assertEqual (output [0 ][1 ], "input: md5" )
32
+
33
+ def test_sha256_validation (self ):
34
+ output = self .validator .validate ("20296EF7D8F8DE38540AE282A50E1B38CA65ABBF201561741847CEABE4BB7801" )
35
+ self .assertTrue (output [0 ][0 ])
36
+ self .assertEqual (output [0 ][1 ], "input: sha256" )
37
+
38
+ def test_validation_failure (self ):
39
+ output = self .validator .validate ("diwheih}£££" )
40
+ self .assertFalse (output [0 ][0 ])
41
+
42
+ def test_consistency_check (self ):
43
+ test_list = ["ip" ]
44
+ output_1 = self .validator .consistency_check (test_list , "ip" )
45
+ output_2 = self .validator .consistency_check (test_list , "email" )
46
+ self .assertTrue (output_1 )
47
+ self .assertFalse (output_2 )
48
+
49
+ def test_transform_execution (self ):
50
+ output = self .validator .execute_transform ("8.8.8.8" , "dns: reverse lookup" )
51
+ self .assertEqual (output [0 ], "dns.google" )
52
+
53
+ if __name__ == '__main__' :
54
+ unittest .main ()
0 commit comments