示例#1
0
 def test_editEntrySL(self):
     createTablesBig()
     err, sl = tosl.ScriptLogTable().getByID(2)
     # change some of sl's attributes
     sl.scriptID = 1
     sl.userID = 1
     sl.compID = 1
     sl.startTime = dt.now()
     sl.endTime = dt.now()
     sl.returnVal = -1
     sl.errorCode = 0
     sl.stdoutFile = "stdoutFile new"
     sl.stderrFile = "stderrFile new"
     sl.asAdmin = False
     # write these edits to table
     err, sl2 = tosl.ScriptLogTable().editEntry(sl)
     errExp = pref.getError(pref.ERROR_SUCCESS)
     # checks
     self.assertEqual(err, errExp)
     self.assertEqual(sl.ID, sl2.ID)
     self.assertEqual(sl.scriptID, sl.scriptID)
     self.assertEqual(sl.userID, sl.userID)
     self.assertEqual(sl.compID, sl.compID)
     self.assertEqual(sl.startTime, sl.startTime)
     self.assertEqual(sl.endTime, sl.endTime)
     self.assertEqual(sl.returnVal, sl.returnVal)
     self.assertEqual(sl.errorCode, sl.errorCode)
     self.assertEqual(sl.stdoutFile, sl.stdoutFile)
     self.assertEqual(sl.stderrFile, sl.stderrFile)
     self.assertEqual(sl.asAdmin, sl.asAdmin)
示例#2
0
 def test_addEntrySL(self):
     createEmptyTables()
     # need user entry first for foreign key
     u = tou.UserTable().createEntry("rbroders",
                                     "hella_secure_hashed_password", True)
     err = tou.UserTable().add(u)  # uID will be 1
     # need script entry for foreign key
     s = tos.ScriptTable().createEntry("test_script_name",
                                       "test_script_name.sh", 1,
                                       "emptry script used for testing",
                                       False)
     err = tos.ScriptTable().add(s)
     # need computer entry for foreign key
     c = toc.ComputerTable().createEntry(
         1, "RachelsSurface", "Raquels Computer",
         "Rachel's wonderful awful computer", "rbroders",
         "idk how IPs are formatted ya yeet", False)
     err = toc.ComputerTable().add(c)
     # scriptLog entry
     sl = tosl.ScriptLogTable().createEntry(1, 1, 1, False)
     err = tosl.ScriptLogTable().add(sl)
     errExp = pref.getError(pref.ERROR_SUCCESS)
     # check stdout/stderr file creation
     outPath = pref.getNoCheck(pref.CONFIG_SCRIPT_LOG_PATH) + sl.stdoutFile
     errPath = pref.getNoCheck(pref.CONFIG_SCRIPT_LOG_PATH) + sl.stderrFile
     self.assertEqual(os.path.exists(outPath), True)
     self.assertEqual(os.path.exists(errPath), True)
     # check error and scriptlog ID
     self.assertEqual(err, errExp)
     self.assertEqual(sl.ID, 1)
示例#3
0
def createTables():
    '''
  Create tables (scriptLog, script, computer and user) with one record inserted into each of them
  @param None.
  @return None.
  '''
    createEmptyTables()
    # user entry
    u = tou.UserTable().createEntry("rbroders", "hella_secure_hashed_password",
                                    True)
    err = tou.UserTable().add(u)  # uID will be 1
    # script entry
    s = tos.ScriptTable().createEntry("test_script_name",
                                      "test_script_name.sh", 1,
                                      "empty script used for testing", False)
    err = tos.ScriptTable().add(s)
    # computer entry
    c = toc.ComputerTable().createEntry(1, "RachelsSurface",
                                        "Raquels Computer",
                                        "Rachel's wonderful awful computer",
                                        "rbroders",
                                        "idk how IPs are formatted ya yeet",
                                        False)
    err = toc.ComputerTable().add(c)
    # scriptLog entry
    sl = tosl.ScriptLogTable().createEntry(1, 1, 1, False)
    err = tosl.ScriptLogTable().add(sl)
示例#4
0
def createTablesBig():
    '''
  Create tables (scriptLog, script, computer and user) with multiple records inserted into each of them
  @param None.
  @return None.
  '''
    createEmptyTables()
    # user entries
    u = tou.UserTable().createEntry("rbroders", "hella_secure_hashed_password",
                                    True)
    err = tou.UserTable().add(u)
    u = tou.UserTable().createEntry("lmilne", "ya_yeet", False)
    err = tou.UserTable().add(u)
    u = tou.UserTable().createEntry("jbusch", "beer-brand", True)
    err = tou.UserTable().add(u)
    # script entries
    s = tos.ScriptTable().createEntry("test_script_name",
                                      "test_script_name.sh", 1,
                                      "empty script used for testing", False)
    err = tos.ScriptTable().add(s)
    s = tos.ScriptTable().createEntry("create_happiness", "reboot.sh", 1,
                                      "doggies and kitties", True)
    err = tos.ScriptTable().add(s)
    s = tos.ScriptTable().createEntry("solve_world_hunger", "shutdown.sh", 1,
                                      "crazy scritpt", False)
    err = tos.ScriptTable().add(s)
    s = tos.ScriptTable().createEntry("leprechan_script",
                                      "sleepScript copy.sh", 1,
                                      "found at end of rainbow", True)
    err = tos.ScriptTable().add(s)
    # computer entries
    c = toc.ComputerTable().createEntry(1, "RachelsSurface",
                                        "Raquels Computer",
                                        "Rachel's wonderful awful computer",
                                        "rbroders",
                                        "idk how IPs are formatted ya yeet",
                                        False)
    err = toc.ComputerTable().add(c)
    c = toc.ComputerTable().createEntry(
        1, "Rachels Air", "Old computer", "dusty computer in closet",
        "rbroders22", "idk how IPs are formatted ya yeet... we can dream",
        True)
    err = toc.ComputerTable().add(c)
    c = toc.ComputerTable().createEntry(
        2, "Larry's Pi", "Raspberry Pie", "yum love pie", "lmilne",
        "idk how IPs are formatted ya yeet ... maybe one day", False)
    err = toc.ComputerTable().add(c)
    c = toc.ComputerTable().createEntry(
        3, "James' Computer", "JB Computer", "its a computer what can I say",
        "jbusch", "idk how IPs are formatted ya yeet...still", False)
    err = toc.ComputerTable().add(c)
    # scriptLog entries
    sl = tosl.ScriptLogTable().createEntry(1, 1, 3, False)
    err = tosl.ScriptLogTable().add(sl)
    sl = tosl.ScriptLogTable().createEntry(2, 2, 4, False)
    err = tosl.ScriptLogTable().add(sl)
    sl = tosl.ScriptLogTable().createEntry(3, 4, 2, False)
    err = tosl.ScriptLogTable().add(sl)
    sl = tosl.ScriptLogTable().createEntry(1, 3, 1, False)
    err = tosl.ScriptLogTable().add(sl)
示例#5
0
 def test_deleteSL(self):
     createTablesBig()
     stdoutFile = pref.getNoCheck(
         pref.CONFIG_SCRIPT_LOG_PATH) + "STDOUT_test_script_name_3.log"
     stderrFile = pref.getNoCheck(
         pref.CONFIG_SCRIPT_LOG_PATH) + "STDERR_test_script_name_3.log"
     open(stdoutFile, "a")  # create files to be deleted
     open(stderrFile, "a")  # create files to be deleted
     existsBefore1 = path.exists(stdoutFile)
     existsBefore2 = path.exists(stderrFile)
     err = tosl.ScriptLogTable().delete(3)
     errExp = pref.getError(pref.ERROR_SUCCESS)
     err2, sl = tosl.ScriptLogTable.getByID(3)
     errExp2 = pref.getError(pref.ERROR_SQL_RETURN_MISSING_ATTR,
                             args=("getByID", "ScriptLog", 0, 11))
     existsAfter1 = path.exists(stdoutFile)
     existsAfter2 = path.exists(stderrFile)
     self.assertEqual(existsBefore1, True)
     self.assertEqual(existsBefore2, True)
     self.assertEqual(err, errExp)
     self.assertEqual(err2, errExp2)
     self.assertEqual(existsAfter1, False)
     self.assertEqual(existsAfter2, False)
     self.assertEqual(sl, None)
     open(stdoutFile, "a")  # recreate deleted files
     open(stderrFile, "a")
示例#6
0
 def test_createEntrySL(self):
     createEmptyTables()
     sl = tosl.ScriptLogTable().createEntry(0, 0, 0, False)
     self.assertEqual(sl.scriptID, 0)
     self.assertEqual(sl.userID, 0)
     self.assertEqual(sl.compID, 0)
     self.assertEqual(sl.asAdmin, False)
示例#7
0
 def test_deleteSL_F(self):
     createTablesBig()
     err = tosl.ScriptLogTable().delete(99)  # delete non-existent computer
     errExp = pref.getError(pref.ERROR_SQL_RETURN_MISSING_ATTR,
                            args=("getAttrByID", "ScriptLog", 0, 11))
     # print(err)
     # print(errExp)
     self.assertEqual(err, errExp)
示例#8
0
 def test_deleteTableU_S(self):
     createTables()
     err = tosl.ScriptLogTable().deleteTable()
     err = tos.ScriptTable().deleteTable()
     err = toc.ComputerTable().deleteTable()
     err = tou.UserTable().deleteTable()
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)
示例#9
0
 def test_editEntrySL_F(self):
     createTablesBig()
     err, sl = tosl.ScriptLogTable().getByID(2)
     # change some of sl's attributes
     sl.ID = None
     # write these edits to table
     err, sl2 = tosl.ScriptLogTable().editEntry(sl)
     errExp = pref.getError(pref.ERROR_NO_ID_PROVIDED,
                            args=("editEntry", "ScriptLog"))
     self.assertEqual(err, errExp)
     self.assertEqual(sl.ID, sl2.ID)
     self.assertEqual(sl.scriptID, sl.scriptID)
     self.assertEqual(sl.userID, sl.userID)
     self.assertEqual(sl.compID, sl.compID)
     self.assertEqual(sl.startTime, sl.startTime)
     self.assertEqual(sl.endTime, sl.endTime)
     self.assertEqual(sl.returnVal, sl.returnVal)
     self.assertEqual(sl.errorCode, sl.errorCode)
     self.assertEqual(sl.stdoutFile, sl.stdoutFile)
     self.assertEqual(sl.stderrFile, sl.stderrFile)
     self.assertEqual(sl.asAdmin, sl.asAdmin)
示例#10
0
def clearTables():
    '''
    Drops all SQL tables in database (scriptLog, script, computer and user)
    @param None.
    @return None.
    @Notes 
        All rows of a given table are deleted upon a drop table operation. 
        If any of these deletions trigger errors due to foreign key constraints or other issues, an error will be raised. 
        No error will be raised for dropping empty tables regardless of foreign key constraints on them.
    '''
    e = tosl.ScriptLogTable().deleteTable()
    e = tos.ScriptTable().deleteTable()
    e = toc.ComputerTable().deleteTable()
    e = tou.UserTable().deleteTable()
示例#11
0
    def test_getAttrByIDSL(self):
        # sl = tosl.ScriptLogTable().createEntry(1, 1, 1, False)
        createTables()
        errExp = pref.getError(pref.ERROR_SUCCESS)

        err, slID = tosl.ScriptLogTable().getAttrByID("ID", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(slID, 1)

        err, slCompID = tosl.ScriptLogTable().getAttrByID("compID", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(slCompID, 1)

        err, slRetVal = tosl.ScriptLogTable().getAttrByID("returnVal", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(slRetVal, None)

        err, slStdout = tosl.ScriptLogTable().getAttrByID("stdoutFile", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(slStdout, "STDOUT_test_script_name_1.log")

        err, slAsAdmin = tosl.ScriptLogTable().getAttrByID("asAdmin", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(slAsAdmin, False)
示例#12
0
def createEmptyTables():
    '''
    Creates empty SQL tables for scriptLog, script, computer and user
    @param None.
    @return None.
    @Notes 
        Foreign key constraints are not checked when a table is created. 
        There is nothing stopping the user from creating a foreign key definition that refers 
            to a parent table that does not exist therefore creation order does not matter.
    '''
    clearTables()
    e = tosl.ScriptLogTable().createTable()
    e = tos.ScriptTable().createTable()
    e = toc.ComputerTable().createTable()
    e = tou.UserTable().createTable()
示例#13
0
 def test_getByIDSL(self):
     createTables()
     err, sl = tosl.ScriptLogTable().getByID(1)
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)
     self.assertEqual(sl.ID, 1)
     self.assertEqual(sl.scriptID, 1)
     self.assertEqual(sl.userID, 1)
     self.assertEqual(sl.compID, 1)
     self.assertEqual(sl.endTime, None)
     self.assertEqual(sl.returnVal, None)
     self.assertEqual(sl.errorCode, None)
     self.assertEqual(
         sl.stdoutFile, "STDOUT_test_script_name_1.log"
     )  # FIXME when getAttrByID implemented - "STDOUT_test_script_name_1.log"
     self.assertEqual(
         sl.stderrFile, "STDERR_test_script_name_1.log"
     )  # FIXME when getAttrByID implemented - "STDERR_test_script_name_1.log"
     self.assertEqual(sl.asAdmin, False)
示例#14
0
 def test_getAllSL(self):
     createTablesBig()
     err, sl = tosl.ScriptLogTable().getAll()
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)
示例#15
0
 def test_deleteTableEmptySL(self):
     createEmptyTables()
     err = tosl.ScriptLogTable().deleteTable()
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)
示例#16
0
 def test_createTableSL(self):
     clearTables()
     err = tosl.ScriptLogTable().createTable()
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)