Пример #1
0
 def boot():
     db_operations.create_database()
     Spider.queued_links = db_operations.retrieve_links_from_db(
         Spider.queue_table)
     Spider.crawled_links = db_operations.retrieve_links_from_db(
         Spider.crawled_table)
     Spider.error_links = db_operations.retrieve_links_from_db(
         Spider.error_table)
     Spider.foreign_links = db_operations.retrieve_links_from_db(
         Spider.foreign_table)
Пример #2
0
 def update_clients_list(self):
     # Update combo box without adding duplicates
     if db_operations.database_exists():
         try:
             self.combo_client.remove_all()
             rows = db_operations.retrieve_all_clients()
             for client in rows:
                 self.combo_client.append_text(client[0])
         except TypeError:
             logging.error(sys.exc_info()[1])
     else:
         logging.warning("Database not found, creating new database.")
         db_operations.create_database()
Пример #3
0
    def save_button_pressed(self, widget):
        # New client window
        name = self.client_name.get_text()
        website = self.client_website.get_text()
        project = self.client_project.get_text()
        logging.debug('Name: ' + name)
        logging.debug('Website: ' + website)
        logging.debug('Project:' + project)
        logging.debug("New Client Window: Save button pressed.")

        try:
            db_operations.add_client(name, website, project)
            logging.debug("Client details successfully added to database")
        except sqlite3.OperationalError as err:
            logging.error(err)
            db_operations.create_database()
            logging.debug("New client database created")
            db_operations.add_client(name, website, project)
            logging.debug("Client details successfully added to database")

        self.update_clients_list()
        self.client_info_window_close(self)
Пример #4
0
 def setUpClass(cls):
     db_operations.create_database()
Пример #5
0
class TestUI(unittest.TestCase):
    fake = Faker()

    db_operations.DATABASE = "client_data/test.db"
    db_operations.database_name = "test.db"
    TEST_DB = db_operations.DATABASE
    TEST_DB_NAME = db_operations.database_name
    name, website, project = fake.name(), fake.domain_name(), fake.bs().split(
    )[2]
    db_operations.create_database()
    db_operations.add_client(name, website, project)
    app = toils_gui.TimeTracker()

    @classmethod
    def setUpClass(cls):

        filename = "client_data/test.db"
        #db_operations.create_database()
        #db_operations.add_client(cls.name, cls.website, cls.project)
        #self.app = toils_gui.TimeTracker()

    def test_client_combo_box_is_not_empty(self):
        pass

    def test_that_time_label_does_not_display_time_on_startup(self):
        self.assertEqual(self.app.lbl_time.get_text(), "Current time")

    def test_start_button_is_disabled_on_startup(self):
        self.assertFalse(self.app.btn_start.get_sensitive())

    def test_stop_button_is_disabled_on_startup(self):
        self.assertFalse(self.app.btn_stop.get_sensitive())

    def test_client_combo_box_displays_nothing_on_startup(self):
        self.assertEqual(self.app.combo_client.get_active(), -1)

    def test_project_combo_box_is_updated_when_client_selected(self):
        self.app.combo_client.set_active(1)
        self.assertTrue(self.app.combo_project.get_sensitive())

    def test_start_button_gets_activated_when_client_selected(self):
        self.app.combo_client.set_active(0)
        self.assertTrue(self.app.btn_start.get_sensitive())

    def test_client_combo_displays_correct_tooltip(self):
        self.assertEqual(self.app.combo_client.get_tooltip_text(),
                         "List of clients you do work for.")

    def test_that_combo_project_shows_correct_project_for_each_client(self):
        self.app.combo_client.set_active(0)
        client_name = self.app.combo_client.get_active_text()
        project = self.app.combo_project.get_active_text()
        self.assertEqual(client_name, self.name)
        self.assertEqual(project, self.project)

    def tearDown(self):
        self.app.btn_start.set_sensitive(False)
        self.app.combo_client.set_active(-1)

    @classmethod
    def tearDownClass(cls):
        try:
            os.remove(cls.TEST_DB)
        except FileNotFoundError as err:
            print(err)