示例#1
0
    def send(self, request, **kwargs):
        parsed_url = urlparse(request.path_url)
        method_name = parsed_url.path.replace('/', '_').replace('.',
                                                                '_').replace(
                                                                    '-', '_')

        if hasattr(self.cls, method_name):
            match = getattr(self.cls, method_name)
            spec = inspect.getargspec(match)
            kwargs = {}
            if 'request' in spec.args:
                kwargs['request'] = request
            if 'method' in spec.args:
                kwargs['method'] = request.method
            if 'params' in spec.args:
                kwargs['params'] = dict(parse_qsl(parsed_url.query))
            if 'headers' in spec.args:
                kwargs['headers'] = request.headers
            if 'url' in spec.args:
                kwargs['url'] = request.url
            if 'body' in spec.args:
                kwargs['body'] = request.body
            response = match(**kwargs)
            if isinstance(response, six.string_types):
                return StaticResponseFactory.GoodResponse(body=b(response),
                                                          request=request)
            else:
                return response
        else:
            return StaticResponseFactory.BadResponse(status_code=404,
                                                     request=request,
                                                     body=b("Not found."))
示例#2
0
 def _v1_skills(self, request, method):
     if method in ["POST", "PUT"]:
         return self.adapter.response_from_fixture(
             request, "tests/fixtures/v1/skills_single")
     elif method == "DELETE":
         return StaticResponseFactory.GoodResponse(request=request,
                                                   body=b(""),
                                                   status_code=200)
示例#3
0
 def _v1_users(self, request, method):
     if method in ["POST", "PUT"]:
         return self.adapter.response_from_fixture(
             request,
             "tests/fixtures/v1/users_4cea0449-666a-433f-8396-857e269449a9")
     elif method == "DELETE":
         return StaticResponseFactory.GoodResponse(request=request,
                                                   body=b(""),
                                                   status_code=200)
示例#4
0
 def _response(self, request, path):
     with open(os.path.join(self.base_path, path), "rb") as fo:
         body = fo.read()
     return StaticResponseFactory.GoodResponse(body, request)
 def _test_json(self, request):
     return StaticResponseFactory.GoodResponse(request=request,
                                               body=b("it's my life"),
                                               headers={'now': 'never'},
                                               status_code=201)
示例#6
0
 def _v1_gatherings_3578d16a_381a_4041_a6bb_1b3957fc8e94_paths_9dbd1b62_2d6e_414a_9e4c_253d17693f09(
         self, request, method):
     assert method == "DELETE"
     return StaticResponseFactory.GoodResponse(b"", request)
示例#7
0
 def response_from_fixture(self, request, fixture_path):
     with open(fixture_path, 'rb') as fo:
         body = fo.read()
     return StaticResponseFactory.GoodResponse(body=body, request=request)
示例#8
0
 def _v1_users_4cea0449_666a_433f_8396_857e269449a9_user_skills_f5bf30a8_412c_4cea_9a64_1d4aae5a40f9(
         self, request, method):
     if method == "DELETE":
         return StaticResponseFactory.GoodResponse(request=request,
                                                   body=b(""),
                                                   status_code=200)