def test_get_apimethods_multiwrapped(self): class MyResource(ResourceBase): @apimethod(methods=['GET']) @apimethod(methods=['POST']) def fake(cls, *args, **kwargs): args = (cls, ) + args return args, kwargs count = 0 for name, method in _get_apimethods(MyResource): count += 1 self.assertEqual(name, 'fake') self.assertEqual(count, 1)
def test_get_apimethods_multiwrapped(self): class MyResource(ResourceBase): @apimethod(methods=["GET"]) @apimethod(methods=["POST"]) def fake(cls, *args, **kwargs): args = (cls,) + args return args, kwargs count = 0 for name, method in _get_apimethods(MyResource): count += 1 self.assertEqual(name, "fake") self.assertEqual(count, 1)
def test_run_get_apimethods(self): """ Tests whether the methods returned by _get_apimethods can be run raw. """ class MyResource(ResourceBase): @apimethod(methods=['GET']) def fake(cls, request, *args, **kwargs): return cls, request request = object() for name, clsmethod in _get_apimethods(MyResource): klass, response = clsmethod(request) self.assertEqual(MyResource, klass) self.assertEqual(id(request), id(response))
def test_run_get_apimethods(self): """ Tests whether the methods returned by _get_apimethods can be run raw. """ class MyResource(ResourceBase): @apimethod(methods=["GET"]) def fake(cls, request, *args, **kwargs): return cls, request request = object() for name, clsmethod in _get_apimethods(MyResource): klass, response = clsmethod(request) self.assertEqual(MyResource, klass) self.assertEqual(id(request), id(response))
def test_get_apimethods(self): """ Tests that the function _get_apimethods appropriately gets apimethods and that they are class methods not _apiclassmethod instances. """ class MyResource(ResourceBase): @apimethod(methods=['GET']) @apimethod(methods=['POST']) def fake1(cls): pass @apimethod(route='/hey', methods=['GET']) def fake2(self): pass names = [] for name, clsmethod in _get_apimethods(MyResource): names.append(name) self.assertIsInstance(clsmethod, types.FunctionType) self.assertIn('fake1', names) self.assertIn('fake2', names) self.assertEqual(len(names), 2)
def test_get_apimethods(self): """ Tests that the function _get_apimethods appropriately gets apimethods and that they are class methods not _apiclassmethod instances. """ class MyResource(ResourceBase): @apimethod(methods=["GET"]) @apimethod(methods=["POST"]) def fake1(cls): pass @apimethod(route="/hey", methods=["GET"]) def fake2(self): pass names = [] for name, clsmethod in _get_apimethods(MyResource): names.append(name) self.assertIsInstance(clsmethod, types.FunctionType) self.assertIn("fake1", names) self.assertIn("fake2", names) self.assertEqual(len(names), 2)