Exemplo n.º 1
0
    def test_add_process_and_process_category_and_assign_and_delete(self):
        testdb = str(time.time()) + ".db"
        db = DBConnection(db_filename=testdb)
        tests_to_run = 5
        for x in xrange(0, tests_to_run):
            # x = 0
            current_process = pst.processes.get_current()
            random_title = random_string(10)
            random_filename = random_string(10)
            current_process.title = "TEST TITLE " + random_title
            current_process.filename = "TEST FILENAME " + random_filename
            process = db.add_process(current_process)
            new_category = db.add_category(title="TITLE")
            new_filter = db.add_filter(
                category_id=new_category.id, title_search=random_title, filename_search=random_filename
            )
            db.assign_categories()
            # processes = db.get_processes()
            processes = [pst.db.row2dict(row) for row in db.get_processes()]
            self.assertEqual(new_category.id, int(processes[x]["process_categories"][0]["id"]))
            self.assertEqual(
                new_filter.title_search, processes[x]["process_categories"][0]["filters"][0]["title_search"]
            )
            self.assertEqual(
                new_filter.filename_search, processes[x]["process_categories"][0]["filters"][0]["filename_search"]
            )

        processes = db.get_processes()
        for process in processes:
            db.delete_category(process[1].id)
            db.assign_categories()

        association_table_data = db.session.query("* FROM association")

        self.assertEqual(tests_to_run, association_table_data.count())

        processes = db.get_processes()
        for process in processes:
            self.assertEqual(process[1].process_categories[0].title, "unassigned")
            self.assertEqual(len(process[1].process_categories), 1)

        for process in processes:
            random_title = random_string(10)
            random_filename = random_string(10)
            new_category = db.add_category(title="TITLE")
            new_filter = db.add_filter(
                category_id=new_category.id, title_search=random_title, filename_search=random_filename
            )

        db.assign_categories()
        processes = db.get_processes()
        for process in processes:
            self.assertEqual(process[1].process_categories[0].title, "unassigned")
            self.assertEqual(len(process[1].process_categories), 1)

        db.session.close()
        rm(testdb)
Exemplo n.º 2
0
 def test_incorrect_process_filter(self):
     testdb = str(time.time()) + ".db"
     db = DBConnection(db_filename=testdb)
     for x in xrange(0, 10):
         # x = 0
         current_process = pst.processes.get_current()
         random_title = random_string(10)
         random_filename = random_string(10)
         current_process.title = "Developer Tools - http://127.0.0.1:8081/" + random_title
         current_process.filename = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
         process = db.add_process(current_process)
         new_category = db.add_category(title="TITLE")
         random_title2 = "TimeTracker"
         random_filename2 = ""
         new_filter = db.add_filter(
             category_id=new_category.id, title_search=random_title2, filename_search=random_filename2
         )
         db.assign_categories()
         # processes = db.get_processes()
         processes = [pst.db.row2dict(row) for row in db.get_processes()]
         self.assertEqual(0, int(processes[x]["process_categories"][0]["id"]))
         self.assertEqual("", processes[x]["process_categories"][0]["filters"][0]["title_search"])
         self.assertEqual("", processes[x]["process_categories"][0]["filters"][0]["filename_search"])
     db.session.close()
     rm(testdb)
Exemplo n.º 3
0
 def test_add_process_and_process_category_and_assign(self):
     testdb = str(time.time()) + ".db"
     db = DBConnection(db_filename=testdb)
     for x in xrange(0, 10):
         # x = 0
         current_process = pst.processes.get_current()
         random_title = random_string(10)
         random_filename = random_string(10)
         current_process.title = "TEST TITLE " + random_title
         current_process.filename = "TEST FILENAME " + random_filename
         process = db.add_process(current_process)
         new_category = db.add_category(title="TITLE")
         new_filter = db.add_filter(
             category_id=new_category.id, title_search=random_title, filename_search=random_filename
         )
         db.assign_categories()
         # processes = db.get_processes()
         processes = [pst.db.row2dict(row) for row in db.get_processes()]
         self.assertEqual(new_category.id, int(processes[x]["process_categories"][0]["id"]))
         self.assertEqual(
             new_filter.title_search, processes[x]["process_categories"][0]["filters"][0]["title_search"]
         )
         self.assertEqual(
             new_filter.filename_search, processes[x]["process_categories"][0]["filters"][0]["filename_search"]
         )
     db.session.close()
     rm(testdb)
Exemplo n.º 4
0
    def test_add_process_category_filter(self):
        testdb = str(time.time()) + ".db"
        db = DBConnection(db_filename=testdb)

        random_title = random_string(10)
        random_filename = random_string(10)
        new_category = db.add_category(title="TITLE")
        new_filter = db.add_filter(
            category_id=new_category.id, title_search=random_title, filename_search=random_filename
        )

        pc = db.session.query(pst.db.ProcessCategory).filter(pst.db.ProcessCategory.title == "TITLE").one()
        self.assertEquals(pc.id, 1)
        self.assertEqual(pc.process_filter[0].title_search, random_title)
        self.assertEqual(pc.process_filter[0].filename_search, random_filename)
        db.session.close()
        rm(testdb)