def testAddHandler(self): '''Tests if addHandler works as expected, Tests methods: [addHandler, pathFor, handlerFor]''' class Handler(Resource): pass #Sample request handler print "\nTesting the normal execution paths" Registry.addHandler(None, "/", Handler) self.assertEqual(Registry.handlerFor(None, "/"), Handler) self.assertEqual("/", Registry.pathFor(Handler)[1]) print "Normal execution path ok, proceeding with other tests" print "\nTesting defensive safe guards" print "Checking if ``Registry`` accepts slashless paths" self.assertRaises(ValueError, lambda: Registry.addHandler(None, "hello", Handler)) print "Checking if ``Registry`` accepts non Resource objects" self.assertRaises(ValueError, lambda: Registry.addHandler(None, "/hello", object)) print "Checking if ``Registry`` accepts duplicate paths" self.assertRaises(DuplicatePathError, lambda: Registry.addHandler(None, "/", Handler)) print "Defensive assertions ok"
def testSanity(self): '''Checks the common execution paths''' @Path("/base", "institutions") class Handler(Resource): '''A Mock Handler''' pass print "Testing normal behavior" self.assertTrue(Registry.handlerFor("institutions", "/base") == Handler) self.assertTrue(Registry.pathFor(Handler)[1] == "/base") print "Testing that @Path only allows Resource objects" with self.assertRaises(ValueError): @Path("/") class Handler(object): pass print "Show that @Path only accepts routes preceded with a slash" with self.assertRaises(ValueError): @Path("hello") class Handler(Resource): pass