Debian Codegraph @

tests.py

raw symbols SCIP
1 from functools import wraps
2 import unittest
3 import robot_detection
4
5 class RobotDetectTestCase(unittest.TestCase):
6
7 def _known_robot(user_agent):
8 def testFunc(self):
9 self.assertTrue(robot_detection.is_robot(user_agent))
10 testFunc.__doc__ = "Should detect {0} as a robot".format(user_agent)
11 return testFunc
12
13 def _known_human(user_agent):
14 def testFunc(self):
15 self.assertFalse(robot_detection.is_robot(user_agent))
16 testFunc.__doc__ = "Should not detect {0} as a robot".format(user_agent)
17 return testFunc
18
19 testGoogle1 = _known_robot("googlebot")
20 testGoogle2 = _known_robot("Foo bargooglebot")
21 testGoogle3 = _known_robot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
22 testGoogle4 = _known_robot('\xef\xbb\xbfMozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')
23 testYeti = _known_robot('Yeti/1.0 (NHN Corp.; http://help.naver.com/robots/)')
24 testHuman1 = _known_human("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.83 Safari/535.11")
25
26
27
28 if __name__ == '__main__':
29 unittest.main()