Exemple #1
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)
Exemple #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)
Exemple #3
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])
Exemple #4
0
    def case_get_by_name_one_result(self, refresh_db_before):
        """ Create test records in Admin table and get them by name."""
        names_with_id = {"admin1": 1, "admin2": 2, "admin3": 3}

        for name in names_with_id.keys():
            AdminOp.add(name)

        for exp_name, exp_id in names_with_id.items():
            admin_obj = AdminOp.get(name=exp_name)
            self.assertTrue(len(admin_obj) is 1)
            self.assertEqual(exp_name, admin_obj[0].name)
            self.assertEqual(exp_id, admin_obj[0].id)
Exemple #5
0
    def case_delete_records(self, refresh_db_before):
        """ Create new record in Admin table and then delete it."""
        new_name = "admin1"

        AdminOp.add(new_name)

        adm_obj = AdminOp.get(name=new_name)
        self.assertTrue(len(adm_obj) is 1)
        self.assertEqual(adm_obj[0].name, new_name)

        AdminOp.delete(adm_obj[0])

        adm_obj = AdminOp.get(name=new_name)
        self.assertFalse(adm_obj)
Exemple #6
0
    def case_add_records(self, refresh_db_before):
        """ Add new records to Admin table."""
        new_names = ["admin1", "admin2", "admin3"]

        for name in new_names:
            AdminOp.add(name)

        check_records = AdminOp.get()

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

        for record, exp_name in zip(check_records, new_names):
            self.assertTrue(isinstance(record, Admin))
            self.assertEqual(record.name, exp_name)
Exemple #7
0
    def case_resolve_admin_positive(self, refresh_db_before):
        """ Try to resolve existing Admin name."""
        adm_name = "New Admin"
        adm_obj = AdminOp.add(adm_name)

        adm_res_obj = ServerOp.resolve_admin(adm_name)
        self.assertEqual(adm_obj, adm_res_obj)
        self.assertEqual(adm_res_obj.name, adm_name)
Exemple #8
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])
Exemple #9
0
    def case_update_record(self, refresh_db_before):
        """ Create test record in Admin table and then update it."""
        original_name = "admin3"
        update_name = "admin33"

        original_admin = AdminOp.add(original_name)

        updated_admin_local = AdminOp.update(original_admin, update_name)

        self.assertEqual(updated_admin_local.name, update_name)

        updated_admin_get = AdminOp.get(name=update_name)

        self.assertTrue(len(updated_admin_get) is 1)
        self.assertEqual(updated_admin_get[0].name, update_name)
        self.assertEqual(updated_admin_get[0].id, original_admin.id)
Exemple #10
0
    def test_add(self, mock_admin, mock_val_name, mock_db):
        """ Assumptions:
                - add method run
        """
        new_name = "Test Name"
        new_admin = AdminOp.add(new_name)

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

        self.assertEqual(new_admin, mock_admin())

        self.assertTrue(mock_val_name.called)

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

        mock_db.assert_has_calls(db_exp_calls)
Exemple #11
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)