Exemplo n.º 1
0
    def validate(self, url, resources):

        if self.in_ in constants.URL_PARAMS:
            resource = self.config.get(
                constants.RESOURCE, utils.extract_resource_name_from_param(self.name, url, self.in_)
            )
            if resource not in resources:
                self.writer.debug(f"{self.name} parameter resolves to resource {resource}."
                                  f" ATLAS will either generate one or pick up from resource_mapping")
Exemplo n.º 2
0
    def extract_resource_name_from_param(
            self,
            param_name,
            url_path,
            param_type=swagger_constants.PATH_PARAM):
        """
        Extract Resource Name from parameter name
        Names could be either snake case (foo_id) or camelCase (fooId)
        In case of URL Params, further they could be foo/id
        Return None if no such resource could be found
        """

        resource_name = utils.extract_resource_name_from_param(
            param_name, url_path, param_type)

        if not resource_name and param_name in self.resource_keys:
            resource_name = param_name

        return resource_name
Exemplo n.º 3
0
 def test_without_suffix_with_singular(self):
     assert utils.extract_resource_name_from_param("id", "pets/{id}/y/{y_id}/z/{abc}", constants.PATH_PARAM) == "pet"
Exemplo n.º 4
0
 def test_without_suffix_with_first_resource(self):
     assert utils.extract_resource_name_from_param("id", "{id}/y/{y_id}/z/{abc}", constants.PATH_PARAM) is None
Exemplo n.º 5
0
 def test_without_suffix_with_path_params_not_in_settings_identifier(self):
     assert utils.extract_resource_name_from_param("abc", "x/{id}/y/{y_id}/z/{abc}", constants.PATH_PARAM) is None
Exemplo n.º 6
0
 def test_without_suffix_with_query_params(self):
     assert utils.extract_resource_name_from_param("id", "x/{id}/y/{y_id}/z/{abc}", constants.QUERY_PARAM) is None
Exemplo n.º 7
0
 def test_with_suffix(self):
     assert utils.extract_resource_name_from_param("pet_id", "") == "pet"