示例#1
0
    def test_rename_variable_description_in_config_template(self):
        """
        test change of the description within a Config Template variable
        :return:
        """
        p = Project("project")
        ct = ConfigTemplate(name="Config Template", project=p)
        ct.update_template_variable("var_1", "first description")
        ct.update_template_variable("var_2", "second description")
        ct.update_template_variable("var_3", "third description")
        tvs = TemplateValueSet("Template", config_template=ct)
        tvs.update_variable_value("var_1", "first value")

        db.session.add_all([p, ct, tvs])
        db.session.commit()

        self.assertTrue(len(ct.variables.all()) == 3 + 1)
        self.assertTrue(len(tvs.values.all()) == 4)

        var_obj = ct.get_template_variable_by_name("var_1")
        var_obj.description = "changed description"
        db.session.add(var_obj)
        db.session.commit()

        self.assertEqual(
            ct.get_template_variable_by_name("var_1").description,
            "changed description")
示例#2
0
    def test_config_template_add_variables_and_lookup(self):
        # create test data
        p1 = Project(name="Project 1")
        ct1 = ConfigTemplate(name="first script", project=p1)
        ct2 = ConfigTemplate(name="second script", project=p1)
        ct1.project = p1
        ct2.project = p1
        db.session.add(p1)
        db.session.add(ct1)
        db.session.add(ct2)
        db.session.commit()

        # verify that the variables are not defined
        self.assertFalse(ct1.is_variable_defined("first variable"))
        self.assertFalse(ct1.is_variable_defined("second variable"))
        self.assertFalse(ct2.is_variable_defined("first variable"))

        # add variables to the first configuration template
        ct1var1_desc = "description for first P1 variable"
        ct1var2_desc = "description for second P1 variable"
        ct1.update_template_variable("first variable", ct1var1_desc)
        ct1.update_template_variable("second variable", ct1var2_desc)
        self.assertFalse(ct2.is_variable_defined("first variable"))
        db.session.commit()

        # add variables to the second configuration template
        ct2var1_desc = "description for first P2 variable"
        ct2.update_template_variable("first variable", ct2var1_desc)
        db.session.commit()

        # retrieve variables (hostname is automatically created)
        self.assertTrue(len(ct1.variables.all()) == 2 + 1)
        self.assertTrue(len(ct2.variables.all()) == 1 + 1)
        self.assertTrue(ct1.is_variable_defined("first_variable"))
        self.assertTrue(ct1.is_variable_defined("second_variable"))
        self.assertTrue(ct2.is_variable_defined("first_variable"))

        ct1var1 = ct1.get_template_variable_by_name("first_variable")
        self.assertTrue(type(ct1var1) is TemplateVariable)
        self.assertEqual(ct1var1.config_template, ct1)
        self.assertEqual(ct1var1.description, ct1var1_desc)

        ct1var2 = ct1.get_template_variable_by_name("second_variable")
        self.assertTrue(type(ct1var2) is TemplateVariable)
        self.assertEqual(ct1var2.config_template, ct1)
        self.assertEqual(ct1var2.description, ct1var2_desc)

        ct2var1 = ct2.get_template_variable_by_name("first_variable")
        self.assertTrue(type(ct2var1) is TemplateVariable)
        self.assertEqual(ct2var1.config_template, ct2)
        self.assertEqual(ct2var1.description, ct2var1_desc)

        # invalid template lookup
        with self.assertRaises(TemplateVariableNotFoundException):
            ct1.get_template_variable_by_name("unknown key")
示例#3
0
    def test_config_template_update_variable(self):
        p1 = Project(name="Project 1")
        ct1 = ConfigTemplate(name="first script", project=p1)
        ct2 = ConfigTemplate(name="second script", project=p1)
        ct1.project = p1
        ct2.project = p1
        db.session.add(p1)
        db.session.add(ct1)
        db.session.add(ct2)
        db.session.commit()

        # verify that the variables are not defined
        self.assertFalse(ct1.is_variable_defined("first variable"))
        self.assertFalse(ct1.is_variable_defined("second variable"))
        self.assertFalse(ct2.is_variable_defined("first variable"))

        # add variables to the first configuration template
        ct1var1_desc = "description for first P1 variable"
        ct1.update_template_variable("first variable", ct1var1_desc)
        ct1.update_template_variable("second variable",
                                     "description for second P1 variable")
        ct2.update_template_variable("first variable",
                                     "description for first P2 variable")

        self.assertTrue(len(ct1.variables.all()) == 2 + 1)
        self.assertTrue(len(ct2.variables.all()) == 1 + 1)

        # update value
        ct1var1_desc_mod = "modified description"
        ct1.update_template_variable("first variable", ct1var1_desc_mod)

        ct1var1 = ct1.get_template_variable_by_name("first_variable")
        self.assertNotEqual(ct1var1.description, ct1var1_desc)
        self.assertEqual(ct1var1.description, ct1var1_desc_mod)