예제 #1
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)
예제 #2
0
 def test_editEntryC(self):
     createTablesBig()
     err, c = toc.ComputerTable().getByID(2)
     # change some of c's attributes
     c.userID = 2
     c.name = "newName"
     c.nickName = "newNickName"
     c.desc = "newDesc"
     c.username = "******"
     c.IP = "newIP"
     c.dtModified = dt.now()
     c.asAdmin = True
     # write these edits to table
     err, c2 = toc.ComputerTable().editEntry(c)
     errExp = pref.getError(pref.ERROR_SUCCESS)
     # checks
     self.assertEqual(err, errExp)
     self.assertEqual(c.userID, c2.userID)
     self.assertEqual(c.name, c2.name)
     self.assertEqual(c.nickName, c2.nickName)
     self.assertEqual(c.desc, c2.desc)
     self.assertEqual(c.username, c2.username)
     self.assertEqual(c.IP, c2.IP)
     self.assertEqual(c.dtCreated, c2.dtCreated)
     self.assertEqual(c.dtModified, c2.dtModified)
     self.assertEqual(c.asAdmin, c2.asAdmin)
예제 #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_addEntryC(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
     # 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)
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)
     self.assertEqual(c.ID, 1)
예제 #6
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)
예제 #7
0
 def test_deleteC(self):
     createTablesBig()
     err = toc.ComputerTable().delete(1)
     errExp = pref.getError(pref.ERROR_SUCCESS)
     err2, c = toc.ComputerTable.getByID(1)
     errExp2 = pref.getError(pref.ERROR_SQL_RETURN_MISSING_ATTR,
                             args=("getByID", "Computer", 0, 10))
     self.assertEqual(err, errExp)
     self.assertEqual(err2, errExp2)
     self.assertEqual(c, None)
예제 #8
0
 def test_editEntryC_F(self):
     createTablesBig()
     err, c = toc.ComputerTable().getByID(2)
     # change some of c's attributes
     c.ID = None
     # write these edits to table
     err, c2 = toc.ComputerTable().editEntry(c)
     errExp = pref.getError(pref.ERROR_NO_ID_PROVIDED,
                            args=("editEntry", "Computer"))
     # checks
     self.assertEqual(err, errExp)
     self.assertEqual(c.userID, c2.userID)
     self.assertEqual(c.name, c2.name)
     self.assertEqual(c.nickName, c2.nickName)
     self.assertEqual(c.desc, c2.desc)
     self.assertEqual(c.username, c2.username)
     self.assertEqual(c.IP, c2.IP)
     self.assertEqual(c.dtCreated, c2.dtCreated)
     self.assertEqual(c.dtModified, c2.dtModified)
     self.assertEqual(c.asAdmin, c2.asAdmin)
예제 #9
0
 def test_getByIDC(self):
     createTables()
     err, c = toc.ComputerTable().getByID(1)
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)
     self.assertEqual(c.ID, 1)
     self.assertEqual(c.userID, 1)
     self.assertEqual(c.name, "RachelsSurface")
     self.assertEqual(c.nickName, "Raquels Computer")
     self.assertEqual(c.desc, "Rachel's wonderful awful computer")
     self.assertEqual(c.username, "rbroders")
     self.assertEqual(c.IP, "idk how IPs are formatted ya yeet")
     self.assertEqual(c.asAdmin, False)
예제 #10
0
 def test_createEntryC(self):
     createEmptyTables()
     c = toc.ComputerTable().createEntry(
         0, "RachelsSurface", "Raquels Computer",
         "Rachel's wonderful awful computer", "rbroders",
         "idk how IPs are formatted ya yeet", False)
     self.assertEqual(c.userID, 0)
     self.assertEqual(c.name, "RachelsSurface")
     self.assertEqual(c.nickName, "Raquels Computer")
     self.assertEqual(c.desc, "Rachel's wonderful awful computer")
     self.assertEqual(c.username, "rbroders")
     self.assertEqual(c.IP, "idk how IPs are formatted ya yeet")
     self.assertEqual(c.asAdmin, False)
예제 #11
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()
예제 #12
0
    def test_getAttrByIDC(self):
        # c = toc.ComputerTable().createEntry(1, "RachelsSurface", "Raquels Computer", "Rachel's wonderful awful computer", "rbroders", "idk how IPs are formatted ya yeet", False)
        createTables()
        errExp = pref.getError(pref.ERROR_SUCCESS)

        err, cID = toc.ComputerTable().getAttrByID("ID", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(cID, 1)

        err, cUserID = toc.ComputerTable().getAttrByID("userID", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(cUserID, 1)

        err, cName = toc.ComputerTable().getAttrByID("name", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(cName, "RachelsSurface")

        err, sUsername = toc.ComputerTable().getAttrByID("username", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(sUsername, "rbroders")

        err, cAsAdmin = toc.ComputerTable().getAttrByID("asAdmin", 1)
        self.assertEqual(err, errExp)
        self.assertEqual(cAsAdmin, False)
예제 #13
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()
예제 #14
0
 def test_getAllC(self):
     createTablesBig()
     err, c = toc.ComputerTable().getAll()
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)
예제 #15
0
 def test_deleteTableEmptyC(self):
     createEmptyTables()
     err = toc.ComputerTable().deleteTable()
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)
예제 #16
0
 def test_createTableC(self):
     clearTables()
     err = toc.ComputerTable().createTable()
     errExp = pref.getError(pref.ERROR_SUCCESS)
     self.assertEqual(err, errExp)