示例#1
0
    def test_add_method(self):
            views = ViewMapper()
    
            #At first there should not be method 'plus' in views
            self.assertRaises(KeyError, lambda: views['plus'])
            self.assertNotIn('plus', views.keys())
            
            #Plus method added:
            views.add_method('plus', lambda x: 2)
            
            #Checked for the existance of the plus method
            self.assertIsNotNone(views['plus']['method'])
            self.assertIsNotNone(views['plus']['kwargs'])
            self.assertIn('plus', views.keys())
    
            #Check to see wether a method is overridden properly
            views.add_method('plus', 'me')
            
            #The method should have changed from lambda x:2 to me
            self.assertEqual(views['plus']['method'], 'me')
            
#             Check to see wether a method is overridden properly
            views.add_method('minus', 'x', {'key': 'value'})
            self.assertEqual(views['minus']['method'], 'x')
示例#2
0
    def test_add_method(self):
        views = ViewMapper()

        #At first there should not be method 'plus' in views
        self.assertRaises(KeyError, lambda: views['plus'])
        self.assertNotIn('plus', views.keys())

        #Plus method added:
        views.add_method('plus', lambda x: 2)

        #Checked for the existance of the plus method
        self.assertIsNotNone(views['plus']['method'])
        self.assertIsNotNone(views['plus']['kwargs'])
        self.assertIn('plus', views.keys())

        #Check to see wether a method is overridden properly
        views.add_method('plus', 'me')

        #The method should have changed from lambda x:2 to me
        self.assertEqual(views['plus']['method'], 'me')

        #             Check to see wether a method is overridden properly
        views.add_method('minus', 'x', {'key': 'value'})
        self.assertEqual(views['minus']['method'], 'x')