Esempio n. 1
0
    def case_add_with_tags(self, refresh_db_before):
        """ Create new Server row with tags many-to-many relation."""
        server_name = "TestServer"
        server_status = "TestStatus"
        server_type = "TestType"
        tags = ["tag one", "tag two", "tag three"]

        ServerStatusOp.add(server_status)
        ServerTypeOp.add(server_type)
        for tag in tags:
            TagOp.add(tag)

        new_server = ServerOp.add(server_name,
                                  server_status,
                                  server_type,
                                  tags=tags)

        get_servers = ServerOp.get()
        self.assertTrue(len(get_servers) is 1)
        self.assertEqual(get_servers[0].description, None)
        self.assertEqual(get_servers[0].id, 1)
        self.assertEqual(get_servers[0].name, server_name)
        self.assertEqual(get_servers[0], new_server)

        for tag, exp_name in zip(get_servers[0].tags, tags):
            self.assertEqual(tag.name, exp_name)
Esempio n. 2
0
    def case_add_with_admins(self, refresh_db_before):
        """ Create new Server row with admins many-to-many relation."""
        server_name = "TestServer"
        server_status = "TestStatus"
        server_type = "TestType"
        admins = ["Admin One", "Admin Two"]

        ServerStatusOp.add(server_status)
        ServerTypeOp.add(server_type)
        for admin in admins:
            AdminOp.add(admin)

        new_server = ServerOp.add(server_name,
                                  server_status,
                                  server_type,
                                  admins=admins)

        get_servers = ServerOp.get()
        self.assertTrue(len(get_servers) is 1)
        self.assertEqual(get_servers[0].description, None)
        self.assertEqual(get_servers[0].id, 1)
        self.assertEqual(get_servers[0].name, server_name)
        self.assertEqual(get_servers[0], new_server)

        for admin, exp_name in zip(get_servers[0].admins, admins):
            self.assertEqual(admin.name, exp_name)
Esempio n. 3
0
    def case_get_by_tags(self, refresh_db_before):
        """ Get server row with tags keyword."""
        server_name = "TestServer"
        server_second_name = "TestServerTwo"
        server_status = "TestStatus"
        server_type = "TestType"
        ServerStatusOp.add(server_status)
        ServerTypeOp.add(server_type)

        tags = ["tag one", "tag two", "tag three"]
        for tag in tags:
            TagOp.add(tag)

        srv_one = ServerOp.add(server_name,
                               server_status,
                               server_type,
                               tags=[tags[0], tags[1]])
        srv_two = ServerOp.add(server_second_name,
                               server_status,
                               server_type,
                               tags=tags)

        get_lonely = ServerOp.get(tags=[tags[2]])
        self.assertTrue(len(get_lonely) is 1)
        self.assertEqual(get_lonely[0], srv_two)
        self.assertEqual(len(get_lonely[0].tags), len(tags))

        get_all = ServerOp.get(tags=[tags[0]])
        self.assertTrue(len(get_all) is 2)
Esempio n. 4
0
    def case_add_with_ips(self, refresh_db_before):
        """ Create new Server row with ips many-to-many relation."""
        server_name = "TestServer"
        server_status = "TestStatus"
        server_type = "TestType"
        ips = ["11.11.11.11", "22.22.22.22", "33.33.33.33"]

        ServerStatusOp.add(server_status)
        ServerTypeOp.add(server_type)
        for ip in ips:
            IpOp.add(ip)

        new_server = ServerOp.add(server_name,
                                  server_status,
                                  server_type,
                                  ips=ips)

        get_servers = ServerOp.get()
        self.assertTrue(len(get_servers) is 1)
        self.assertEqual(get_servers[0].description, None)
        self.assertEqual(get_servers[0].id, 1)
        self.assertEqual(get_servers[0].name, server_name)
        self.assertEqual(get_servers[0], new_server)

        for srv_ip, exp_ip in zip(get_servers[0].ips, ips):
            self.assertEqual(srv_ip.address, exp_ip)
Esempio n. 5
0
    def case_get_by_admins(self, refresh_db_before):
        """ Get server row with admins keyword."""
        server_name = "TestServer"
        server_second_name = "TestServerTwo"
        server_status = "TestStatus"
        server_type = "TestType"
        ServerStatusOp.add(server_status)
        ServerTypeOp.add(server_type)

        admins = ["Admin One", "Admin Two", "Admin Three"]
        for admin in admins:
            AdminOp.add(admin)

        srv_one = ServerOp.add(server_name,
                               server_status,
                               server_type,
                               admins=[admins[0], admins[1]])
        srv_two = ServerOp.add(server_second_name,
                               server_status,
                               server_type,
                               admins=admins)

        get_lonely = ServerOp.get(admins=[admins[2]])
        self.assertTrue(len(get_lonely) is 1)
        self.assertEqual(get_lonely[0], srv_two)
        self.assertEqual(len(get_lonely[0].admins), len(admins))

        get_all = ServerOp.get(admins=[admins[0]])
        self.assertTrue(len(get_all) is 2)
Esempio n. 6
0
    def case_get_by_ip(self, refresh_db_before):
        """ Get server row with ip keyword."""
        server_name = "TestServer"
        server_second_name = "TestServerTwo"
        server_status = "TestStatus"
        server_type = "TestType"
        ServerStatusOp.add(server_status)
        ServerTypeOp.add(server_type)

        ips = ["11.11.11.11", "22.22.22.22"]
        for ip in ips:
            IpOp.add(ip)

        srv_one = ServerOp.add(server_name,
                               server_status,
                               server_type,
                               ips=[ips[0]])
        srv_two = ServerOp.add(server_second_name,
                               server_status,
                               server_type,
                               ips=[ips[1]])

        get_first_ip = ServerOp.get(ip=ips[0])
        self.assertTrue(len(get_first_ip) is 1)
        self.assertEqual(get_first_ip[0], srv_one)
        self.assertNotEqual(get_first_ip[0], srv_two)
        self.assertTrue(len(get_first_ip[0].ips) is 1)
        self.assertEqual(get_first_ip[0].ips[0].address, ips[0])
Esempio n. 7
0
    def case_update_all(self, refresh_db_before):
        """ Update all fields."""
        server_name = "TestServer"
        server_name_two = "TestServerTwo"
        ServerStatusOp.add("Status")
        ServerStatusOp.add("StatusTwo")
        ServerTypeOp.add("TypeOne")
        ServerTypeOp.add("TypeTwo")
        desc_one = "Desc one"
        desc_two = "Desc two"
        ips_one = IpOp.add("11.11.11.11")
        ips_two = IpOp.add("22.22.22.22")
        tag_one = TagOp.add("tag one")
        tag_two = TagOp.add("tag two")
        admin_one = AdminOp.add("Admin One")
        admin_two = AdminOp.add("Admin Two")

        srv = ServerOp.add(
            server_name,
            "Status",
            "TypeOne",
            description=desc_one,
            ips=["11.11.11.11"],
            tags=["tag one"],
            admins=["Admin One"],
        )

        get_before_update = ServerOp.get()
        self.assertTrue(len(get_before_update) is 1)
        self.assertEqual(get_before_update[0].id, 1)
        self.assertEqual(get_before_update[0].name, server_name)
        self.assertEqual(get_before_update[0].description, desc_one)
        self.assertEqual(get_before_update[0].status.name, "Status")
        self.assertEqual(get_before_update[0].type.name, "TypeOne")
        self.assertEqual(get_before_update[0].ips, [ips_one])
        self.assertEqual(get_before_update[0].tags, [tag_one])
        self.assertEqual(get_before_update[0].admins, [admin_one])

        ServerOp.update(
            srv,
            name=server_name_two,
            description=desc_two,
            srv_status="StatusTwo",
            srv_type="TypeTwo",
            ips=["22.22.22.22"],
            tags=["tag two"],
            admins=["Admin Two"],
        )

        get_srv = ServerOp.get()
        self.assertTrue(len(get_srv) is 1)
        self.assertEqual(get_srv[0].id, 1)
        self.assertEqual(get_srv[0].name, server_name_two)
        self.assertEqual(get_srv[0].description, desc_two)
        self.assertEqual(get_srv[0].status.name, "StatusTwo")
        self.assertEqual(get_srv[0].type.name, "TypeTwo")
        self.assertEqual(get_srv[0].ips, [ips_two])
        self.assertEqual(get_srv[0].tags, [tag_two])
        self.assertEqual(get_srv[0].admins, [admin_two])
Esempio n. 8
0
    def case_resolve_status_positive(self, refresh_db_before):
        """ Create ServerStatus rows, then resolve their names into ID."""
        statuses = {"Status_one": 1, "Status_two": 2}
        for status in statuses.keys():
            ServerStatusOp.add(status)

        for status_name, status_key in statuses.items():
            resolved_id = ServerOp.resolve_status(status_name)
            self.assertEqual(status_key, resolved_id)
Esempio n. 9
0
    def case_get_by_name_one_result(self, refresh_db_before):
        """ Create test records in ServerStatus table and get them by name."""
        statuses_with_id = {"Status_one": 1, "Status_two": 2}

        for status in statuses_with_id.keys():
            ServerStatusOp.add(status)

        for exp_status, exp_id in statuses_with_id.items():
            stat_obj = ServerStatusOp.get(name=exp_status)
            self.assertTrue(len(stat_obj) is 1)
            self.assertEqual(exp_status, stat_obj[0].name)
            self.assertEqual(exp_id, stat_obj[0].id)
Esempio n. 10
0
    def case_delete_records(self, refresh_db_before):
        """ Create new record in ServerStatus table and then delete it."""
        new_status = "NewStatus"

        ServerStatusOp.add(new_status)

        status_obj = ServerStatusOp.get(name=new_status)
        self.assertTrue(len(status_obj) is 1)
        self.assertEqual(status_obj[0].name, new_status)

        ServerStatusOp.delete(status_obj[0])

        status_obj = ServerStatusOp.get(name=new_status)
        self.assertFalse(status_obj)
Esempio n. 11
0
    def case_add_records(self, refresh_db_before):
        """ Add new records to ServerStatus table."""
        new_statuses = ["Status_one", "Status_two"]

        for status in new_statuses:
            ServerStatusOp.add(status)

        check_records = ServerStatusOp.get()

        self.assertEqual(len(check_records), len(new_statuses))

        for record, exp_status in zip(check_records, new_statuses):
            self.assertTrue(isinstance(record, ServerStatus))
            self.assertEqual(record.name, exp_status)
Esempio n. 12
0
    def case_delete(self, refresh_db_before):
        """ Delete record."""
        server_name = "TestServer"
        ServerStatusOp.add("Status")
        ServerTypeOp.add("TypeOne")

        ServerOp.add(server_name, "Status", "TypeOne")

        get_srv = ServerOp.get()
        self.assertTrue(len(get_srv) is 1)
        self.assertEqual(get_srv[0].name, server_name)

        ServerOp.delete(get_srv[0])
        get_empty = ServerOp.get()
        self.assertFalse(get_empty)
Esempio n. 13
0
    def case_get_without_filters(self, refresh_db_before):
        """ Get server rows without any filters."""
        server_name = "TestServer"
        server_second_name = "TestServerTwo"
        ServerStatusOp.add("Status")
        ServerTypeOp.add("TypeOne")
        ServerTypeOp.add("TypeTwo")

        srv_one = ServerOp.add(server_name, "Status", "TypeOne")

        srv_two = ServerOp.add(server_second_name, "Status", "TypeTwo")

        get_all = ServerOp.get()
        self.assertTrue(len(get_all) is 2)
        self.assertEqual(get_all[0], srv_one)
        self.assertEqual(get_all[1], srv_two)
Esempio n. 14
0
    def case_get_by_srv_type(self, refresh_db_before):
        """ Get server row with srv_type keyword."""
        server_name = "TestServer"
        server_second_name = "TestServerTwo"
        ServerStatusOp.add("Status")
        ServerTypeOp.add("TypeOne")
        ServerTypeOp.add("TypeTwo")

        srv_one = ServerOp.add(server_name, "Status", "TypeOne")

        srv_two = ServerOp.add(server_second_name, "Status", "TypeTwo")

        get_first_type = ServerOp.get(srv_type="TypeOne")
        self.assertTrue(len(get_first_type) is 1)
        self.assertEqual(get_first_type[0].id, 1)
        self.assertEqual(get_first_type[0], srv_one)
        self.assertNotEqual(get_first_type[0], srv_two)
Esempio n. 15
0
    def case_update_name(self, refresh_db_before):
        """ Update server name."""
        server_name = "TestServer"
        server_second_name = "TestServerTwo"
        ServerStatusOp.add("Status")
        ServerTypeOp.add("TypeOne")

        srv = ServerOp.add(server_name, "Status", "TypeOne")

        get_before_update = ServerOp.get(name=server_name)
        self.assertTrue(len(get_before_update) is 1)
        self.assertEqual(get_before_update[0].id, 1)

        ServerOp.update(srv, name=server_second_name)

        get_srv = ServerOp.get(name=server_second_name)
        self.assertTrue(len(get_srv) is 1)
        self.assertEqual(get_srv[0].id, 1)
Esempio n. 16
0
    def case_add_without_description(self, refresh_db_before):
        """ Create new Server row without description field."""
        server_name = "TestServer"

        ServerStatusOp.add("TestStatus")
        ServerTypeOp.add("TestType")

        new_server = ServerOp.add(server_name, "TestStatus", "TestType")

        get_servers = ServerOp.get()
        self.assertTrue(len(get_servers) is 1)
        self.assertEqual(get_servers[0].description, None)
        self.assertEqual(get_servers[0].id, 1)
        self.assertEqual(get_servers[0].type_id, 1)
        self.assertEqual(get_servers[0].status_id, 1)
        self.assertEqual(get_servers[0].name, server_name)

        self.assertEqual(get_servers[0], new_server)
Esempio n. 17
0
    def case_get_by_name(self, refresh_db_before):
        """ Get server row with name keyword."""
        server_name = "TestServer"
        server_second_name = "TestServerTwo"
        ServerStatusOp.add("TestStatus")
        ServerTypeOp.add("TestType")

        new_server = ServerOp.add(server_name, "TestStatus", "TestType")

        new_second_server = ServerOp.add(server_second_name, "TestStatus",
                                         "TestType")

        get_second_server = ServerOp.get(name=server_second_name)

        self.assertTrue(len(get_second_server) is 1)

        self.assertEqual(get_second_server[0], new_second_server)
        self.assertEqual(get_second_server[0].id, 2)
        self.assertNotEqual(get_second_server[0], new_server)
Esempio n. 18
0
    def case_update_srv_type(self, refresh_db_before):
        """ Update server type."""
        server_name = "TestServer"
        ServerStatusOp.add("Status")
        ServerTypeOp.add("TypeOne")
        ServerTypeOp.add("TypeTwo")

        srv = ServerOp.add(server_name, "Status", "TypeOne")

        get_before_update = ServerOp.get()
        self.assertTrue(len(get_before_update) is 1)
        self.assertEqual(get_before_update[0].id, 1)
        self.assertEqual(get_before_update[0].type.name, "TypeOne")

        ServerOp.update(srv, srv_type="TypeTwo")

        get_srv = ServerOp.get()
        self.assertTrue(len(get_srv) is 1)
        self.assertEqual(get_srv[0].id, 1)
        self.assertEqual(get_srv[0].type.name, "TypeTwo")
Esempio n. 19
0
    def case_update_ips(self, refresh_db_before):
        """ Update ip addresses. """
        server_name = "TestServer"
        ServerStatusOp.add("Status")
        ServerTypeOp.add("Type")
        ips_one = IpOp.add("11.11.11.11")
        ips_two = IpOp.add("22.22.22.22")

        srv = ServerOp.add(server_name, "Status", "Type", ips=["11.11.11.11"])

        get_before_update = ServerOp.get()
        self.assertTrue(len(get_before_update) is 1)
        self.assertEqual(get_before_update[0].id, 1)
        self.assertEqual(get_before_update[0].ips, [ips_one])

        ServerOp.update(srv, ips=["22.22.22.22"])

        get_srv = ServerOp.get()
        self.assertTrue(len(get_srv) is 1)
        self.assertEqual(get_srv[0].id, 1)
        self.assertEqual(get_srv[0].ips, [ips_two])
Esempio n. 20
0
    def case_update_description(self, refresh_db_before):
        """ Update server description."""
        server_name = "TestServer"
        ServerStatusOp.add("Status")
        ServerTypeOp.add("TypeOne")
        desc_one = "Desc one"
        desc_two = "Desc two"

        srv = ServerOp.add(server_name, "Status", "TypeOne", desc_one)

        get_before_update = ServerOp.get()
        self.assertTrue(len(get_before_update) is 1)
        self.assertEqual(get_before_update[0].id, 1)
        self.assertEqual(get_before_update[0].description, desc_one)

        ServerOp.update(srv, description=desc_two)

        get_srv = ServerOp.get()
        self.assertTrue(len(get_srv) is 1)
        self.assertEqual(get_srv[0].id, 1)
        self.assertEqual(get_srv[0].description, desc_two)
Esempio n. 21
0
    def case_update_admins(self, refresh_db_before):
        """ Update admins."""
        server_name = "TestServer"
        ServerStatusOp.add("Status")
        ServerTypeOp.add("Type")

        admin_one = AdminOp.add("Admin One")
        admin_two = AdminOp.add("Admin Two")

        srv = ServerOp.add(server_name, "Status", "Type", admins=["Admin One"])

        get_before_update = ServerOp.get()
        self.assertTrue(len(get_before_update) is 1)
        self.assertEqual(get_before_update[0].id, 1)
        self.assertEqual(get_before_update[0].admins, [admin_one])

        ServerOp.update(srv, admins=["Admin Two"])

        get_srv = ServerOp.get()
        self.assertTrue(len(get_srv) is 1)
        self.assertEqual(get_srv[0].id, 1)
        self.assertEqual(get_srv[0].admins, [admin_two])
Esempio n. 22
0
    def case_update_tags(self, refresh_db_before):
        """ Update tags."""
        server_name = "TestServer"
        ServerStatusOp.add("Status")
        ServerTypeOp.add("Type")

        tag_one = TagOp.add("tag one")
        tag_two = TagOp.add("tag two")

        srv = ServerOp.add(server_name, "Status", "Type", tags=["tag one"])

        get_before_update = ServerOp.get()
        self.assertTrue(len(get_before_update) is 1)
        self.assertEqual(get_before_update[0].id, 1)
        self.assertEqual(get_before_update[0].tags, [tag_one])

        ServerOp.update(srv, tags=["tag two"])

        get_srv = ServerOp.get()
        self.assertTrue(len(get_srv) is 1)
        self.assertEqual(get_srv[0].id, 1)
        self.assertEqual(get_srv[0].tags, [tag_two])
Esempio n. 23
0
    def case_update_record(self, refresh_db_before):
        """ Create test record in ServerStatus table and then update it."""
        original_status = "StatusOrig"
        update_status = "StatusUpdate"

        original_stat_obj = ServerStatusOp.add(original_status)

        updated_stat_local = ServerStatusOp.update(original_stat_obj, update_status)

        self.assertEqual(updated_stat_local.name, update_status)

        updated_stat_get = ServerStatusOp.get(name=update_status)

        self.assertTrue(len(updated_stat_get) is 1)
        self.assertEqual(updated_stat_get[0].name, update_status)
        self.assertEqual(updated_stat_get[0].id, original_stat_obj.id)
Esempio n. 24
0
    def test_add(self, mock_servstatus, mock_val_name, mock_db):
        """ Assumptions:
                - add method run
        """
        new_name = "TestName"
        new_ip = ServerStatusOp.add(new_name)

        exp_calls = [mock.call(new_name)]
        mock_servstatus.assert_has_calls(exp_calls)

        self.assertEqual(new_ip, mock_servstatus())
        self.assertTrue(mock_val_name.called)

        db_exp_calls = [
            mock.call.session.add(new_ip),
            mock.call.session.commit()
        ]

        mock_db.assert_has_calls(db_exp_calls)
Esempio n. 25
0
    def case_get_by_all(self, refresh_db_before):
        """ Get server row with both srv_status
            srv_type keywords.
        """
        server_name = "TestServer"
        server_second_name = "TestServerTwo"
        server_third_name = "TestServerThree"
        server_fourth_name = "TestServerFour"
        ServerStatusOp.add("StatusOne")
        ServerStatusOp.add("StatusTwo")
        ServerTypeOp.add("TypeOne")
        ServerTypeOp.add("TypeTwo")

        IpOp.add("11.11.11.11")
        IpOp.add("22.22.22.22")

        TagOp.add("Tag one")
        TagOp.add("Tag two")

        AdminOp.add("Admin One")
        AdminOp.add("Admin Two")

        srv_one = ServerOp.add(
            server_name,
            "StatusOne",
            "TypeOne",
            ips=["11.11.11.11"],
            tags=["Tag one"],
            admins=["Admin One"],
        )

        ServerOp.add(
            server_second_name,
            "StatusTwo",
            "TypeTwo",
            ips=["22.22.22.22"],
            tags=["Tag two"],
            admins=["Admin Two"],
        )

        ServerOp.add(
            server_third_name,
            "StatusOne",
            "TypeTwo",
            ips=["22.22.22.22"],
            tags=["Tag two"],
            admins=["Admin Two"],
        )

        srv_four = ServerOp.add(
            server_fourth_name,
            "StatusOne",
            "TypeOne",
            ips=["11.11.11.11"],
            tags=["Tag one"],
            admins=["Admin One"],
        )

        get_by_all = ServerOp.get(
            srv_status="StatusOne",
            srv_type="TypeOne",
            ip="11.11.11.11",
            tags=["Tag one"],
            admins=["Admin One"],
        )

        self.assertTrue(len(get_by_all) is 2)
        self.assertEqual(get_by_all[0].id, 1)
        self.assertEqual(get_by_all[1].id, 4)
        self.assertEqual(get_by_all[0], srv_one)
        self.assertEqual(get_by_all[1], srv_four)