Example #1
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()
        self.model = Model(self.log, self.dbPath)

        self.fruits = ModelEntry(self.log, "fruits")
        self.fruits.tags.append("apple")
        self.fruits.tags.append("melon")
        self.fruits.text = "This entry is about fruit"
        self.legumes = ModelEntry(self.log, "legumes")
        self.legumes.tags.append("tomato")
        self.cars = ModelEntry(self.log, "cars")
        self.cars.tags.append("mustang")
        self.cars.tags.append("volvo")
        self.cars.text = "This entry is about cars"
        self.legs = ModelEntry(self.log, "legs")
        self.aerocrafts = ModelEntry(self.log, "aerocraft")

        self.model.db.addEntry(self.fruits)
        self.model.db.addEntry(self.legs)
        self.model.db.addEntry(self.legumes)
        self.model.db.addEntry(self.aerocrafts)
        self.model.foundEntries["name"].append(self.cars)
        self.model.foundEntries["description"].append(self.fruits)
        self.model.foundEntries["tag"].append(self.legumes)
        self.model.openedEntries.append(self.fruits)
        self.model.openedEntries.append(self.legumes)
Example #2
0
    def __init__(self, log, config):
        '''Constructor'''
        self.actions = {
            "searchAction": self.searchAction,
            "entryChangeAction": self.entryChangeAction,
            "newAction": self.newEntryAction,
            "showEntryAction": self.entryClickedInVSearch,
            "closedAction": self.closeTabAction,
            "tabChangeAction": self.tabChangeAction,
            "deleteAction": self.deleteEntryAction,
            "pathChangeAction": self.changePathAction,
            "newImageAction": self.newImageAction,
            "imageSelectedAction": self.newFileOrImageSelectedAction,
            "addTagAction": self.newTagAction,
            "deleteTagAction": self.deleteTagAction,
            "deleteImageAction": self.deleteImageAction,
            "deleteFileAction": self.deleteFileAction,
            "newFileAction": self.newFileAction,
            "fileSelectedAction": self.newFileOrImageSelectedAction,
            "openFileAction": self.openFileAction,
            "openEntryOverviewAction": self.openEntryOverviewAction
        }
        if log != None:
            self.log = log
        else:
            self.log = Log("log.txt")

        self.config = ConfigFile(self.log, config)
        self.dbPath = self.config.getValue(self.configDataBase)
        self.tempFilePath = self.config.getValue(self.tempFilePath)
        self.view = View(self.log, self.dbPath, self.actions)
        self.model = Model(self.log, self.dbPath)

        self.log.add(self.log.Info, __file__, "init")
Example #3
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()

        # delete db
        if os.path.exists(self.dbPath):
            os.remove(self.dbPath)

        # create test entries
        self.filehandle = FileHandle(self.log)
        f = open(self.testImagePath, "rb")
        self.testImageStream = f.read()
        f.close()

        f = open(self.testWordPath, "rb")
        self.testWordStream = f.read()
        f.close()

        self.e = []
        self.e.append(ModelEntry(self.log, "buildings"))
        self.e[0].description = "This is a building"
        self.e[0].tags = ["Louvre"]
        self.e[0].images[self.testImageName] = self.testImageStream
        self.e[0].files[self.testWordName] = self.testWordStream
        self.e.append(ModelEntry(self.log, "planes"))
        self.e[1].description = "These are planes"
        self.e[1].tags = ["F16", "F35"]
        self.e.append(ModelEntry(self.log, "test1"))
        self.e[2].description = "blabla"
        self.e[2].tags = ["bla"]
        self.e.append(ModelEntry(self.log, "nametest"))
        self.e[3].description = "blublu"
        self.e[3].tags = ["blu"]
        self.e.append(ModelEntry(self.log, "desc1"))
        self.e[4].description = "df eblublufd"
        self.e[4].tags = ["ble", "bli"]
        self.e.append(ModelEntry(self.log, "key1"))
        self.e[5].description = "aasdf"
        self.e[5].tags = ["blo", "blidff", "lkj"]

        # create test database
        testdb = sqlite3.connect(self.dbPath)
        c = testdb.cursor()
        c.execute(
            "CREATE TABLE entries (name text, description text, tags BLOB, images blob, files blob)"
        )
        for entry in self.e:
            s = buffer(self.filehandle.getStreamFromFiles(entry.tags))

            img = buffer(self.filehandle.getStreamFromDictFiles(entry.images))
            fil = buffer(self.filehandle.getStreamFromDictFiles(entry.files))
            c.execute("INSERT INTO entries VALUES (?, ?, ?, ?, ?)",
                      (entry.name, entry.description, s, img, fil))

        testdb.commit()
        testdb.close()

        # create db object to be tested
        self.db = Database(self.log, self.dbPath)
Example #4
0
 def setUp(self):
     self.log = Log("testlog.txt")
     self.log.add = MagicMock()
     
     self.cfgfile = ConfigFile( self.log, self.path)
     
     self.content = "a = sdf\nb = 123\n"
     self.file = open(self.path, "w+")
     self.file.write(self.content)
     self.file.close()
Example #5
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()

        self.root = Tk()
        self.root.title("kbase test")
        self.root.geometry("400x500")

        self.dummy = MagicMock()

        self.actionlist = {"pathChangeAction": self.dummy}

        self.vdbpath = VDbPath(self.root, self.log, self.actionlist)
Example #6
0
 def setUp(self):
     self.log = Log("testlog.txt")
     self.log.add = MagicMock()
     
     f = open(self.testImagePath, "rb")
     self.testImageStream = f.read()
     f.close()
     
     f = open(self.configPath, "w+")
     f.write("databasepath = " + self.dbPath + "\n")
     f.close()
     
     f = open(self.testWordPath, "rb")
     self.testWordStream = f.read()
     f.close()
     
     self.ctr = Controller( self.log, self.configPath )
     self.ctr.model.currentEntry = ModelEntry(self.log, "furniture")
     self.ctr.model.currentEntry.description = "This is the description of furniture"
     self.ctr.model.currentEntry.tags.append("chair")
     self.ctr.model.currentEntry.tags.append("table")
     self.ctr.model.currentEntry.images[self.testImageName] = self.testImageStream
     self.ctr.model.currentEntry.files[self.testWordName] = self.testWordStream
     self.ctr.view.drawEntry = MagicMock()
     self.ctr.view.drawSearch = MagicMock()
     self.ctr.view.removeEntry = MagicMock()
     self.ctr.view.removeSearch = MagicMock()
     self.ctr.view.setDeleteButton = MagicMock()
     self.ctr.view.removeEntry = MagicMock()
     self.ctr.view.changeDbPath = MagicMock()
     self.ctr.view.showNewImageSelectDialog = MagicMock()
     self.ctr.view.showNewFileSelectDialog = MagicMock()
     self.ctr.model.updateNameOfEntry = MagicMock()
     self.ctr.model.updateContentOfEntry= MagicMock()
     self.ctr.model.addEntry = MagicMock()
     self.ctr.model.hasEntry= MagicMock()
     self.ctr.model.getEntries = MagicMock()
     self.ctr.model.removeEntry = MagicMock()
     self.ctr.config.setValue = MagicMock()
     os.startfile = MagicMock()
     self.ctr.model.getEntryByName = MagicMock()
     self.ctr.view.drawOverview = MagicMock()
     self.ctr.view.getActiveTab = MagicMock()
Example #7
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()

        self.root = Tk()
        self.root.title("kbase test")
        self.root.geometry("400x500")

        self.dummy1 = MagicMock()
        self.dummy4 = MagicMock()
        self.dummy5 = MagicMock()
        self.dummy6 = MagicMock()
        self.dummy7 = MagicMock()
        self.dummy8 = MagicMock()
        self.dummy9 = MagicMock()

        self.actionlist = {
            "entryChangeAction": self.dummy1,
            "newImageAction": self.dummy4,
            "addTagAction": self.dummy5,
            "deleteImageAction": self.dummy6,
            "deleteTagAction": self.dummy7,
            "deleteFileAction": self.dummy8,
            "openFileAction": self.dummy9
        }

        self.ventry = VEntry(self.root, self.log, self.actionlist)

        f = open(self.testImagePath, "rb")
        self.testImageStream = f.read()
        f.close()

        f = open(self.testWordPath, "rb")
        self.testWordStream = f.read()
        f.close()
        self.entry = ModelEntry(self.log, "animals")
        self.entry.description = "these are animals"
        self.entry.tags.append("deer")
        self.entry.tags.append("bear")
        self.entry.images[self.testImageName] = self.testImageStream
        self.entry.files[self.testWordName] = self.testWordStream
Example #8
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()

        self.root = Tk()
        self.root.title("kbase test")
        self.root.geometry("400x500")

        self.dummy = MagicMock()
        self.dummy2 = MagicMock()
        self.dummy3 = MagicMock()
        self.dummy4 = MagicMock()

        self.actionlist = {
            "searchAction": self.dummy,
            "newAction": self.dummy2,
            "deleteAction": self.dummy4,
            "closedAction": self.dummy3
        }

        self.vmenubar = VMenubar(self.root, self.log, self.actionlist)
Example #9
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()

        self.dummy1 = MagicMock()
        self.actions = {"fileSelectedAction": self.dummy1}
        self.dbPath = "arxads"

        self.view = View(log=self.log,
                         dbPath=self.dbPath,
                         actions=self.actions)
        self.view.menubar.enableButtonClose = MagicMock()
        self.view.menubar.enableButtonDelete = MagicMock()
        self.view.tabs.addEntry = MagicMock()
        self.view.tabs.grid = MagicMock()
        self.view.tabs.setSearch = MagicMock()
        self.view.tabs.removeEntry = MagicMock()
        self.view.tabs.hasTabs = MagicMock()
        self.view.menubar.disableButtonClose = MagicMock()
        self.view.menubar.disableButtonDelete = MagicMock()
        self.view.tabs.removeSearch = MagicMock()
        self.view.dbPath.changePath = MagicMock()
Example #10
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()

        self.root = Tk()
        self.root.title("kbase test")
        self.root.geometry("400x500")

        self.dummy = MagicMock()

        self.actionlist = {"openEntryOverviewAction": self.dummy}

        self.voverview = VOverview(self.root, self.log, self.actionlist)

        self.e1 = ModelEntry(self.log, "e1")
        self.e2 = ModelEntry(self.log, "e2")
        self.e3 = ModelEntry(self.log, "k")
        self.e4 = ModelEntry(self.log, "z")

        self.entries = OrderedDict()
        self.entries["e"] = [self.e1, self.e2]
        self.entries["k"] = [self.e3]
        self.entries["z"] = [self.e4]
Example #11
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()

        self.root = Tk()
        self.root.title("kbase test")
        self.root.geometry("400x500")

        self.dummy = MagicMock()

        self.actionlist = {"showEntryAction": self.dummy}

        self.vsearch = VSearch(self.root, self.log, self.actionlist)

        self.e1 = ModelEntry(self.log, "e1")
        self.e2 = ModelEntry(self.log, "e2")
        self.e3 = ModelEntry(self.log, "e3")
        self.e4 = ModelEntry(self.log, "e4")

        self.results = {
            "name": [self.e1],
            "tag": [self.e2],
            "description": [self.e3, self.e4]
        }
Example #12
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()

        self.root = Tk()
        self.root.title("kbase test")
        self.root.geometry("400x500")

        self.dummy = MagicMock()

        self.actionlist = {"tabChangeAction": self.dummy}

        self.vtab = VTab(parent=self.root,
                         log=self.log,
                         actions=self.actionlist)

        self.results = None

        self.vsearchdrawtemp = VSearch.drawSearchResults
        VSearch.drawSearchResults = MagicMock()
        self.vsearchremovetemp = VSearch.removeOldResults
        VSearch.removeOldResults = MagicMock()

        self.entryDrawTemp = VEntry.drawEntry
Example #13
0
 def setUp(self):
     self.capturedOutput = StringIO.StringIO()
     sys.stdout = self.capturedOutput
     self.log = Log(self.logfile)
Example #14
0
    def setUp(self):
        self.log = Log("testlog.txt")
        self.log.add = MagicMock()

        self.entry = ModelEntry(self.log, "testentry")