Exemple #1
0
    def test_generate(self):
        """
        Check the success case, if it raises the proper exception when
        the type is not found and if it saves the output in a file instead
        printing it on stdout.
        """
        template_params = {
            'DESCRIPTION': 'Foo',
            'KURL': 'bar',
            'ARCH': 'baz',
        }
        dbdir = os.path.join(os.path.dirname(__file__), 'assets')
        template = utils.get_jinja_template('rhel7', dbdir)
        with mock.patch('sys.stdout') as mock_stdout:
            run.generate(template, template_params, [], dbdir, None)
        with open(os.path.join(dbdir, 'rhel7_rendered.xml')) as file_handler:
            content_expected = file_handler.read()
        self.assertEqual(
            mock.call(content_expected),
            mock_stdout.write.call_args_list[0],
        )

        tmpfile = tempfile.mktemp()
        run.generate(template, template_params, [], dbdir, tmpfile)
        with open(tmpfile) as tmp_handler:
            content = tmp_handler.read()
        self.assertEqual(
            content_expected,
            content,
        )
        os.remove(tmpfile)
Exemple #2
0
 def test_get_jinja_template(self):
     """
     Check the success case and if it raises the proper exception when
     the template is not found
     """
     template = utils.get_jinja_template('rhel7', self.root_dir)
     self.assertEqual(
         'rhel7.xml',
         template.name,
     )
     self.assertRaises(jinja2.exceptions.TemplateNotFound,
                       utils.get_jinja_template, 'not-found', self.root_dir)
Exemple #3
0
def main(args):
    """Main function for the `run` command"""
    if args.action == 'generate':
        template = utils.get_jinja_template(args.tree, args.db)
        template_params = {
            'DESCRIPTION': args.description,
            'ARCH': args.arch,
            'KURL': args.kernel,
        }
        generate(template, template_params, args.mboxes, args.db, args.output)
    elif args.action == 'print-test-cases':
        print_test_cases(args.patches, args.db)
    else:
        utils.raise_action_not_found(args.action, args.command)
Exemple #4
0
def main(args):
    """Main function for the `run` command"""
    if not data.Base.is_dir_valid(args.db):
        raise Exception("\"{}\" is not a database directory".format(args.db))
    database = data.Base(args.db)
    if args.action == 'generate':
        template = utils.get_jinja_template(args.tree, args.db)
        template_params = {
            'DESCRIPTION': args.description,
            'ARCH': args.arch,
            'KURL': args.kernel,
            'TREE': args.tree,
            'getenv': os.getenv,
        }
        generate(template, template_params, args.mboxes, database, args.output,
                 args.pw_cookie)
    elif args.action == 'print-test-cases':
        print_test_cases(args.patches, database, args.pw_cookie)
    else:
        utils.raise_action_not_found(args.action, args.command)