def test_save_and_update_process(self): # testdb = str(time.time())+".db" testdb = "test.db" current_process = pst.processes.get_current() current_process.title = "TITLE: Unicode HOWTO � Python v2.7.7 documentation - Google Chrome" db = DBConnection(db_filename=testdb) process_start = db.add_process(current_process) time.sleep(0.5) second_current_process = pst.processes.get_current() process_end = db.add_process(current_process) process_end.title = "TITLE: Unicode HOWTO � Python v2.7.7 documentation - Google Chrome" self.assertEquals(process_start.id, process_end.id) self.assertNotEquals(process_end.start_time, process_end.end_time) db.session.close()
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)
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)
def test_save_process(self): # testdb = str(time.time())+".db" testdb = "test.db" current_process = pst.processes.get_current() db = DBConnection(db_filename=testdb) process = db.add_process(current_process) self.assertTrue(type(process) is pst.db.DBProcess) db.session.close()
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)
def test_inactive_then_active_process(self): testdb = str(time.time()) + ".db" db = DBConnection(db_filename=testdb) current_process = pst.processes.get_current() db.add_process(current_process) time.sleep(0.1) db.set_current_process_inactive() time.sleep(0.1) db.add_process(current_process) time.sleep(0.1) db.set_current_process_inactive() processes = [pst.db.row2dict(row) for row in db.get_processes()] self.assertEqual(len(processes), 2) self.assertGreater(processes[0]["end_time"], processes[0]["start_time"]) self.assertGreater(processes[1]["end_time"], processes[1]["start_time"]) self.assertGreater(processes[1]["start_time"], processes[0]["end_time"]) db.session.close() rm(testdb)
def test_delete_process(self): testdb = str(time.time()) + ".db" db = DBConnection(db_filename=testdb) current_process = pst.processes.get_current() process = db.add_process(current_process) db.delete_process(id=process.id) processes = db.get_processes() self.assertEqual(processes.count(), 0) db.session.close() rm(testdb)