Example #1
0
 def build_pytan_rst_example(self, name, desc, py_code, py_stdout,
                             py_stderr):
     inc_code = self.write_rst_include_file(
         name=name,
         stepname='code',
         out=py_code,
         ext='py',
         out_dir=self.rst_out_dir,
     )
     inc_stdout = self.write_rst_include_file(
         name=name,
         stepname='stdout',
         out=py_stdout,
         ext='txt',
         out_dir=self.rst_outputs_dir,
     )
     inc_stderr = self.write_rst_include_file(
         name=name,
         stepname='stderr',
         out=py_stderr,
         ext='txt',
         out_dir=self.rst_outputs_dir,
     )
     title = buildsupport.get_name_title(name)
     rst_out = script_definitions.EXAMPLE_RST_TEMPLATE.format(
         title=title,
         desc=desc,
         inc_code=inc_code,
         inc_stdout=inc_stdout,
         inc_stderr=inc_stderr,
     )
     return rst_out
Example #2
0
    def build_soap_example(self, name, desc, response_objects):

        for idx, x in enumerate(response_objects):
            req = self.magic_parser(out=x.request.body)
            resp = self.magic_parser(out=x.text)
            req_headers = self.indent_block(pytan.utils.jsonify(dict(x.request.headers)))
            resp_headers = self.indent_block(pytan.utils.jsonify(dict(x.headers)))
            x.platform_version = platform_version
            x.number = idx + 1
            x.stepname = 'step_{}_response'.format(x.number)
            x.request.stepname = 'step_{}_request'.format(x.number)
            x.request.ext, x.request.pretty_out = req
            x.ext, x.pretty_out, = resp
            x.out_dir = self.soap_outputs_dir
            x.pretty_headers = resp_headers
            x.request.pretty_headers = req_headers
            x.inc_file = self.write_rst_include_file(
                name=name,
                stepname=x.stepname,
                out=x.pretty_out,
                ext=x.ext,
                out_dir=x.out_dir,
            )
            x.request.inc_file = self.write_rst_include_file(
                name=name,
                stepname=x.request.stepname,
                out=x.request.pretty_out,
                ext=x.request.ext,
                out_dir=x.out_dir,
            )
        title = buildsupport.get_name_title(name)
        steps = [script_definitions.SOAP_RST_STEP.format(response=x) for x in response_objects]
        steps = '\n'.join(steps)
        soap_out = script_definitions.SOAP_RST_HEAD.format(title=title, desc=desc, steps=steps)
        return soap_out
Example #3
0
 def build_pytan_rst_example(self, name, desc, py_code, py_stdout, py_stderr):
     inc_code = self.write_rst_include_file(
         name=name, stepname='code', out=py_code, ext='py', out_dir=self.rst_out_dir,
     )
     inc_stdout = self.write_rst_include_file(
         name=name, stepname='stdout', out=py_stdout, ext='txt', out_dir=self.rst_outputs_dir,
     )
     inc_stderr = self.write_rst_include_file(
         name=name, stepname='stderr', out=py_stderr, ext='txt', out_dir=self.rst_outputs_dir,
     )
     title = buildsupport.get_name_title(name)
     rst_out = script_definitions.EXAMPLE_RST_TEMPLATE.format(
         title=title, desc=desc,
         inc_code=inc_code, inc_stdout=inc_stdout, inc_stderr=inc_stderr,
     )
     return rst_out
Example #4
0
    def build_soap_example(self, name, desc, response_objects):

        for idx, x in enumerate(response_objects):
            req = self.magic_parser(out=x.request.body)
            resp = self.magic_parser(out=x.text)
            req_headers = self.indent_block(
                pytan.utils.jsonify(dict(x.request.headers)))
            resp_headers = self.indent_block(
                pytan.utils.jsonify(dict(x.headers)))
            x.platform_version = platform_version
            x.number = idx + 1
            x.stepname = 'step_{}_response'.format(x.number)
            x.request.stepname = 'step_{}_request'.format(x.number)
            x.request.ext, x.request.pretty_out = req
            x.ext, x.pretty_out, = resp
            x.out_dir = self.soap_outputs_dir
            x.pretty_headers = resp_headers
            x.request.pretty_headers = req_headers
            x.inc_file = self.write_rst_include_file(
                name=name,
                stepname=x.stepname,
                out=x.pretty_out,
                ext=x.ext,
                out_dir=x.out_dir,
            )
            x.request.inc_file = self.write_rst_include_file(
                name=name,
                stepname=x.request.stepname,
                out=x.request.pretty_out,
                ext=x.request.ext,
                out_dir=x.out_dir,
            )
        title = buildsupport.get_name_title(name)
        steps = [
            script_definitions.SOAP_RST_STEP.format(response=x)
            for x in response_objects
        ]
        steps = '\n'.join(steps)
        soap_out = script_definitions.SOAP_RST_HEAD.format(title=title,
                                                           desc=desc,
                                                           steps=steps)
        return soap_out
Example #5
0
            examples_from = '{script_name}'.format(**script_def)

        # copy our examples so we have a unique pointer
        my_examples = copy.deepcopy(my_examples)

        if not my_examples:
            load_msg = (
                "\n\t\t!!WARNING!! No examples for {script_name} - will only have help!\n"
            ).format(**script_def)
        else:
            load_msg = '++ {} loaded {} examples'.format(
                examples_from, len(my_examples))

        buildsupport.spew(load_msg, True)

        script_def['title_name'] = buildsupport.get_name_title(
            script_def['script_name'])

        # create a dictionary containing all of our substitutions
        my_subs = {}
        my_subs.update(script_definitions.general_subs)
        my_subs.update(script_def)

        # insert the help example as the first example
        my_help = buildsupport.template_dict(
            dict(script_examples.help_example), my_subs)
        my_examples.insert(0, my_help)

        parsed_examples = [
            buildsupport.process_example(i, d, my_subs)
            for i, d in enumerate(my_examples)
        ]
Example #6
0
            my_examples = script_examples.examples.get(script_def['script_name'], [])
            examples_from = '{script_name}'.format(**script_def)

        # copy our examples so we have a unique pointer
        my_examples = copy.deepcopy(my_examples)

        if not my_examples:
            load_msg = (
                "\n\t\t!!WARNING!! No examples for {script_name} - will only have help!\n"
            ).format(**script_def)
        else:
            load_msg = '++ {} loaded {} examples'.format(examples_from, len(my_examples))

        buildsupport.spew(load_msg, True)

        script_def['title_name'] = buildsupport.get_name_title(script_def['script_name'])

        # create a dictionary containing all of our substitutions
        my_subs = {}
        my_subs.update(script_definitions.general_subs)
        my_subs.update(script_def)

        # insert the help example as the first example
        my_help = buildsupport.template_dict(dict(script_examples.help_example), my_subs)
        my_examples.insert(0, my_help)

        parsed_examples = [
            buildsupport.process_example(i, d, my_subs)
            for i, d in enumerate(my_examples)
        ]
Example #7
0
    def process_ddt(self, ddt_file):
        ddt_basename = ddt_file.replace('ddt_', '').replace('.json', '')
        ddt = os.path.join(self.ddt_dir, ddt_file)
        ddt_tests = buildsupport.json_read(ddt)
        self.ddt_examples = []

        for name, info in sorted(ddt_tests.items(), key=lambda x: x[1]['priority']):
            only_65 = info.get('6_5_only', False)
            if only_65 and not is6_5:
                print "Skipping {} - not valid for 6.2 platform".format(name)
                continue

            if 'invalid' in name and 'deploy' in name:
                info["report_dir"] = info.get('report_dir', tempfile.gettempdir())

            get_args_block = self.build_args_block(
                'get_kwargs', info, 'get', 'handler.get() method',
            )
            delete_args_block = self.build_args_block(
                'delete_kwargs', info, 'delete', 'handler.delete() method',
            )
            args_block = self.build_args_block(
                'kwargs', info, 'args', 'handler() class',
            )

            method_template = script_definitions.METHOD_TEMPLATES.get(info['method_template'], '')
            method_block = method_template.format(**info)

            response_template = script_definitions.RESPONSE_TEMPLATES.get(
                info['response_template'], ''
            )
            response_block = response_template.format(**info)

            py_code_items = [
                BASIC_PY_CODE,
                get_args_block,
                delete_args_block,
                args_block,
                method_block,
                response_block
            ]

            py_code_items = [x for x in py_code_items if x]
            py_code = '\n'.join(py_code_items)

            ew = buildsupport.ExecWrap()
            ew_ret = ew.main(name=name, code_block=py_code, verbose=self.VERBOSE)
            py_stdout, py_stderr, response_objects = ew_ret

            self.make_rst_example(name, info['desc'], py_code, py_stdout, py_stderr)
            self.make_py_example(name, info['desc'], py_code, py_stdout, py_stderr)
            if info.get('xml_desc', ''):
                self.make_soap_example(name, info['xml_desc'], response_objects)

            ddt_example_file = self.build_rst_filename(name)
            self.ddt_examples.append(ddt_example_file)

        name_title = buildsupport.get_name_title(ddt_basename)

        pytan_title = 'PyTan API {} Examples'.format(name_title)
        pytan_desc = "All of the PyTan API examples for {}".format(name_title)
        pytan_tocitems = '\n   '.join(self.ddt_examples)
        pytan_index_out = script_definitions.RST_INDEX_TEMPLATE.format(
            title=pytan_title, desc=pytan_desc, tocitems=pytan_tocitems,
        )
        self.write_rst_file(ddt_basename, pytan_index_out)
        self.rst_examples.append(ddt_basename)
Example #8
0
 def build_rst_title(self, name, sep='='):
     title_sep = "{}".format(sep * 90)
     title_name = buildsupport.get_name_title(name)
     ret = "\n{}\n{}\n".format(title_name, title_sep)
     return ret
Example #9
0
    def process_ddt(self, ddt_file):
        ddt_basename = ddt_file.replace('ddt_', '').replace('.json', '')
        ddt = os.path.join(self.ddt_dir, ddt_file)
        ddt_tests = buildsupport.json_read(ddt)
        self.ddt_examples = []

        for name, info in sorted(ddt_tests.items(),
                                 key=lambda x: x[1]['priority']):
            only_65 = info.get('6_5_only', False)
            if only_65 and not is6_5:
                print "Skipping {} - not valid for 6.2 platform".format(name)
                continue

            if 'invalid' in name and 'deploy' in name:
                info["report_dir"] = info.get('report_dir',
                                              tempfile.gettempdir())

            get_args_block = self.build_args_block(
                'get_kwargs',
                info,
                'get',
                'handler.get() method',
            )
            delete_args_block = self.build_args_block(
                'delete_kwargs',
                info,
                'delete',
                'handler.delete() method',
            )
            args_block = self.build_args_block(
                'kwargs',
                info,
                'args',
                'handler() class',
            )

            method_template = script_definitions.METHOD_TEMPLATES.get(
                info['method_template'], '')
            method_block = method_template.format(**info)

            response_template = script_definitions.RESPONSE_TEMPLATES.get(
                info['response_template'], '')
            response_block = response_template.format(**info)

            py_code_items = [
                BASIC_PY_CODE, get_args_block, delete_args_block, args_block,
                method_block, response_block
            ]

            py_code_items = [x for x in py_code_items if x]
            py_code = '\n'.join(py_code_items)

            ew = buildsupport.ExecWrap()
            ew_ret = ew.main(name=name,
                             code_block=py_code,
                             verbose=self.VERBOSE)
            py_stdout, py_stderr, response_objects = ew_ret

            self.make_rst_example(name, info['desc'], py_code, py_stdout,
                                  py_stderr)
            self.make_py_example(name, info['desc'], py_code, py_stdout,
                                 py_stderr)
            if info.get('xml_desc', ''):
                self.make_soap_example(name, info['xml_desc'],
                                       response_objects)

            ddt_example_file = self.build_rst_filename(name)
            self.ddt_examples.append(ddt_example_file)

        name_title = buildsupport.get_name_title(ddt_basename)

        pytan_title = 'PyTan API {} Examples'.format(name_title)
        pytan_desc = "All of the PyTan API examples for {}".format(name_title)
        pytan_tocitems = '\n   '.join(self.ddt_examples)
        pytan_index_out = script_definitions.RST_INDEX_TEMPLATE.format(
            title=pytan_title,
            desc=pytan_desc,
            tocitems=pytan_tocitems,
        )
        self.write_rst_file(ddt_basename, pytan_index_out)
        self.rst_examples.append(ddt_basename)
Example #10
0
 def build_rst_title(self, name, sep='='):
     title_sep = "{}".format(sep * 90)
     title_name = buildsupport.get_name_title(name)
     ret = "\n{}\n{}\n".format(title_name, title_sep)
     return ret