Esempio n. 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."))
Esempio n. 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)
Esempio n. 3
0
 def send(self, request, **kwargs):
     match = self.match_url(request)
     if match:
         return self.response_from_fixture(request=request,
                                           fixture_path=match)
     else:
         return StaticResponseFactory.BadResponse(status_code=404,
                                                  request=request,
                                                  body=b("'Not found.'"))
Esempio n. 4
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)
Esempio n. 5
0
 def _v1_delete_bad(self, request, method):
     if method == "DELETE":
         return StaticResponseFactory.BadResponse(request=request,
                                                  body=b("bad request"),
                                                  status_code=500)
Esempio n. 6
0
 def _v1_post_bad(self, request, method):
     if method == "POST":
         return StaticResponseFactory.BadResponse(request=request,
                                                  body=b("bad request"),
                                                  status_code=500)
Esempio n. 7
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.BadResponse(
         request=request,
         body=b("it's not over"),
         headers={'now': 'never'},
     )
 def _test_json(self, request):
     return StaticResponseFactory.GoodResponse(request=request,
                                               body=b("it's my life"),
                                               headers={'now': 'never'},
                                               status_code=201)
Esempio n. 10
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)
Esempio n. 11
0
 def _plans_api_reports_v1_users_test_plan(self, request, method):
     return StaticResponseFactory.BadResponse(request=request,
                                              body=b('bad request'),
                                              status_code=500)
Esempio n. 12
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)
 def _plans_api_license_v1_plana_delete_bad(self, request, method):
     if method == 'DELETE':
         return StaticResponseFactory.BadResponse(
             request=request,
             body=b('bad request'),
             status_code=500)
Esempio n. 14
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)