Пример #1
0
    def __init__(self):
        self._happi_db_dirs = [happi_site_dir, happi_user_dir]
        self._device_view = HappiClientTreeView()
        self._client_model = HappiClientModel()
        self._device_view.setModel(self._client_model)
        for db_dir in self._happi_db_dirs:
            for db_file in Path(db_dir).glob('*.json'):
                client = Client(path=str(db_file))
                self._client_model.add_client(client)
        try:
            mongo_client = Client(
                MongoBackend(host='127.0.0.1',
                             db='happi',
                             collection='labview_static',
                             user=USER_MONGO,
                             pw=PW_MONGO,
                             timeout=None))
            self._client_model.add_client(mongo_client)
        except Exception as e:  #TODO catch exception properly
            msg.logError(e)

        widget = QWidget()
        layout = QVBoxLayout()
        layout.addWidget(self._device_view)
        widget.setLayout(layout)

        icon = QIcon(str(static.path('icons/calibrate.png')))
        name = "Devices"
        super(HappiSettingsPlugin, self).__init__(icon, name, widget)
        self._device_view.expandAll()
        self.restore()
Пример #2
0
def mockmongoclient(item_info: Dict[str, Any]):
    with patch('happi.backends.mongo_db.MongoClient') as mock_mongo:
        mc = MongoClient()
        mc['test_db'].create_collection('test_collect')
        mock_mongo.return_value = mc
        # Client
        backend = MongoBackend(db='test_db', collection='test_collect')
        client = Client(database=backend)
        # Insert a single device
        client.backend._collection.insert_one(item_info)
        return client