Ejemplo n.º 1
0
 def setUp(self):
     super().setUp()
     self.fixture = ConfigItem()
     self.fixture.set_name("Test")
     self.fixture.set_description("Test")
     self.fixture.set_value("Test")
     self.db.add(self.fixture)
     self.db.commit()
Ejemplo n.º 2
0
 def test_create_from_json(self):
     exp = {
         "id": 1,
         "name": "Test2",
         "description": "Test2",
         "value": "Test2"
     }
     self.fixture = ConfigItem(exp)
     self.assertEqual(exp['name'], self.fixture.get_name(), "name not same")
     self.assertEqual(exp['description'], self.fixture.get_description(),
                      "desc not same")
     self.assertEqual(exp['value'], self.fixture.get_value(),
                      "value not same")
Ejemplo n.º 3
0
 def test_items(self):
     iss1 = ConfigItem(name="Issue 01",
                       description="Desc 01",
                       value="Value 1")
     iss2 = ConfigItem(name="Issue 02",
                       description="Desc 02",
                       value="Value 2")
     self.db.add(iss1)
     self.db.add(iss2)
     self.fixture.add_item(iss1)
     self.fixture.add_item(iss2)
     self.db.commit()
     self.assertIn(iss1, self.fixture.items)
     self.assertIn(iss2, self.fixture.items)
Ejemplo n.º 4
0
 def test_existing_item(self):
     iss1 = ConfigItem(name="Issue 01",
                       description="Desc 01",
                       value="Value 1")
     self.db.add(iss1)
     self.fixture.add_item(iss1)
     count = self.fixture.items.count()
     self.fixture.add_item(iss1)
     self.assertEqual(count, self.fixture.items.count(), "counts not same")
Ejemplo n.º 5
0
class ConfigItemTest(BaseTest):
    def setUp(self):
        super().setUp()
        self.fixture = ConfigItem()
        self.fixture.set_name("Test")
        self.fixture.set_description("Test")
        self.fixture.set_value("Test")
        self.db.add(self.fixture)
        self.db.commit()

    def test_id(self):
        self.assertEqual(self.fixture.get_id(), 1, "id's do not match")

    def test_name(self):
        self.assertEqual(self.fixture.get_name(), "Test", "names do not match")

    def test_null_name(self):
        with self.assertRaises(Exception):
            self.fixture.set_name(None)

    def test_empty_name(self):
        with self.assertRaises(Exception):
            self.fixture.set_name("")

    def test_description(self):
        self.fixture.set_name("Test")
        self.assertEqual(self.fixture.get_name(), "Test",
                         "descriptions do not match")

    def test_null_description(self):
        with self.assertRaises(Exception):
            self.fixture.set_description(None)

    def test_empty_description(self):
        with self.assertRaises(Exception):
            self.fixture.set_description("")

    def test_value(self):
        self.assertEqual(self.fixture.get_value(), "Test",
                         "values do not match")

    def test_empty_value(self):
        with self.assertRaises(Exception):
            self.fixture.set_value("")

    def test_null_value(self):
        with self.assertRaises(Exception):
            self.fixture.set_description(None)

    def test_parent_security_config(self):
        sc = SecurityConfig(name="SC_Test")
        self.db.add(sc)
        sc.add_item(self.fixture)
        self.assertIn(self.fixture, sc.items, "not contained")
        self.assertEqual(sc.get_id(), self.fixture.sec_conf_id, "id mismatch")

    def test_parent_server_config(self):
        sc = ServerConfig(name="SC_Test")
        self.db.add(sc)
        sc.add_item(self.fixture)
        self.assertIn(self.fixture, sc.items, "not contained")
        self.assertEqual(sc.get_id(), self.fixture.serv_conf_id, "id mismatch")

    def test_to_dict(self):
        exp = {"id": 1, "name": "Test", "description": "Test", "value": "Test"}
        self.assertDictEqual(exp, self.fixture.to_dict(), "dicts not the same")

    def test_update(self):
        exp = {
            "id": 1,
            "name": "Test2",
            "description": "Test2",
            "value": "Test2"
        }
        self.fixture.update(exp)
        self.assertEqual(exp['name'], self.fixture.get_name(), "name not same")
        self.assertEqual(exp['description'], self.fixture.get_description(),
                         "desc not same")
        self.assertEqual(exp['value'], self.fixture.get_value(),
                         "value not same")

    def test_create_from_json(self):
        exp = {
            "id": 1,
            "name": "Test2",
            "description": "Test2",
            "value": "Test2"
        }
        self.fixture = ConfigItem(exp)
        self.assertEqual(exp['name'], self.fixture.get_name(), "name not same")
        self.assertEqual(exp['description'], self.fixture.get_description(),
                         "desc not same")
        self.assertEqual(exp['value'], self.fixture.get_value(),
                         "value not same")

    def test_repr(self):
        self.assertEqual("Config Item: Test=Test", self.fixture.__repr__(),
                         "repr not same")

    def test_str(self):
        self.assertEqual("Config Item: Test=Test", str(self.fixture),
                         "string representation not same")