コード例 #1
0
    def new_config_btn_clicked(self):
        """ Open the Config Entry dialog window. If database is not connected, display error message. """
        if not db_connected():
            QMessageBox.critical(
                self, 'Database connection required',
                'Database connection is required to edit the PV configuration.',
                QMessageBox.Ok)
            return

        self.config_entry_w.show()
        self.config_entry_w.activateWindow()
コード例 #2
0
    def update_db_connection_status(self):
        if db_connected():
            set_colored_text(self.db_connection_status, 'connected',
                             QColor('green'))

        else:
            set_colored_text(self.db_connection_status, 'not connected',
                             QColor('red'))
        self.db_connection_last_checked.setText(
            f"Connection status last updated on: "
            f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S:%f')}")
コード例 #3
0
 def connect_to_db(self):
     db_models.initialize_database(name=self.HeliumDB.name,
                                   host=self.HeliumDB.host,
                                   user=self.HeliumDB.user,
                                   password=self.HeliumDB.password)
     try:
         db_connect()
     except DBConnectionError:
         log_exception(*sys.exc_info())
     finally:
         return db_connected()
コード例 #4
0
    def edit_config_btn_clicked(self):
        """ On Edit, open Config Entry dialog window as normal with object selected and PV config loaded. """
        if not db_connected():
            QMessageBox.critical(
                self, 'Database connection required',
                'Database connection is required to edit the PV configuration.',
                QMessageBox.Ok)
            return
        self.config_entry_w.show()

        selected_row_items = self.config_table.selectedItems()
        if selected_row_items:
            selected_object_name = selected_row_items[1].text()
            self.config_entry_w.edit_object_config(
                obj_name=selected_object_name)

        self.config_entry_w.activateWindow()
コード例 #5
0
 def test_get_max_object_id_WHEN_not_present_THEN_returns_zero(self):
     with mock_database.Database():
         self.assertTrue(db_func.db_connected())
         self.assertEqual(db_func.get_max_object_id(), 0)
コード例 #6
0
 def test_db_connected_WHEN_db_not_connected_THEN_returns_false(
         self, mock_func):
     mock_func.return_value = False
     self.assertFalse(db_func.db_connected())
     mock_func.assert_called()
コード例 #7
0
 def test_db_connected_WHEN_db_connected_THEN_returns_true(self, mock_func):
     mock_func.return_value = True
     self.assertTrue(db_func.db_connected())
     mock_func.assert_called()