How to unit test Google Cloud Endpoints

后端 未结 6 1409
盖世英雄少女心
盖世英雄少女心 2020-12-23 00:12

I\'m needing some help setting up unittests for Google Cloud Endpoints. Using WebTest all requests answer with AppError: Bad response: 404 Not Found. I\'m not really sure if

6条回答
  •  旧时难觅i
    2020-12-23 00:31

    If you don't want to test the full HTTP stack as described by Ezequiel Muns, you can also just mock out endpoints.method and test your API definition directly:

    def null_decorator(*args, **kwargs):
        def decorator(method):
            def wrapper(*args, **kwargs):
                return method(*args, **kwargs)
            return wrapper
        return decorator
    
    from google.appengine.api.users import User
    import endpoints
    endpoints.method = null_decorator
    # decorator needs to be mocked out before you load you endpoint api definitions
    from mymodule import api
    
    
    class FooTest(unittest.TestCase):
        def setUp(self):
            self.api = api.FooService()
    
        def test_bar(self):
            # pass protorpc messages directly
            self.api.foo_bar(api.MyRequestMessage(some='field'))
    

提交回复
热议问题