Beispiel #1
0
class BaseTestCase(TestCase):
    def setUp(self):
        self.db = Database('sqlite://', echo=False)  # in memory database
        self.db.create()
        self.ck = CryptoKey()
        self.hosts = Hosts(self.db, self.ck)

    def tearDown(self):
        self.db.drop()
Beispiel #2
0
class HostsTestCase(TestCase):
    def setUp(self):
        self.db = Database('sqlite://')  # in memory database
        self.db.create()
        self.ck = CryptoKey()
        self.hosts = Hosts(self.db, self.ck)

    def tearDown(self):
        self.db.drop()

    def test_password(self):
        self.hosts.create("first host", "address", "user", "password")
        host1 = self.hosts.get("first host")
        self.assertEqual(host1.password, "password")

        self.hosts.create("second host",
                          "address",
                          "user",
                          password="******")
        host1 = self.hosts.get("first host")
        self.assertEqual(host1.password, "password")

        host2 = self.hosts.get("second host")
        self.assertEqual(host2.password, "differentpassword")

    def test_nonePassword(self):
        self.hosts.create("host", "address", None, None)
        host = self.hosts.get("host")
        self.assertIsNone(host.password)

    def test_updatePassword(self):
        host = self.hosts.create("host", "address", None, None)
        self.hosts.updateHostValues(host, {"password": "******"})
        host = self.hosts.get("host")
        self.assertEqual(host.password, "abc")

        self.hosts.updateHostValues(host, {"password": "******"})
        host = self.hosts.get("host")
        self.assertEqual(host.password, "def")

        self.hosts.updateHostValues(host, {"password": None})
        host = self.hosts.get("host")
        self.assertIsNone(host.password)
Beispiel #3
0
    def init(self):
        app = Flask(__name__)
        app.config.from_object(Config)
        app.register_blueprint(
            api_blueprint,
            url_prefix='{prefix}'.format(prefix=app.config['REST_URL_PREFIX']))

        db_conn = Database()
        db_conn.create(app.config['DB_FILE'])

        @app.before_request
        def before_request():
            g.connection = db_conn.connect()

        @app.after_request
        def after_request(response):
            db_conn.close(g.connection)
            return response

        return app
Beispiel #4
0
if __name__ == "__main__":
    app = QApplication(sys.argv)

    styleFile = QFile(":/style/style.qss")
    styleFile.open(QFile.ReadOnly)
    byteArrayData = styleFile.readAll()
    app.setStyleSheet(byteArrayData.data().decode('utf8'))

    # show icons in menus
    app.setAttribute(Qt.AA_DontShowIconsInMenus, False)
    app.setQuitOnLastWindowClosed(False)

    # finish app with ctrl+c
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    app.focusChanged.connect(focusChanged)

    config = Config()
    config.setLogLevel()

    db = Database(config.getConnectionString())
    db.create()
    db.update()

    mw = MainWindow()

    app.exec_()
    app.deleteLater()
    sys.exit(0)
Beispiel #5
0
if __name__ == "__main__":   
    app = QApplication(sys.argv)

    styleFile = QFile(":/style/style.qss")
    styleFile.open(QFile.ReadOnly)
    data = styleFile.readAll()
    app.setStyleSheet(unicode(data))

    # show icons in menus
    app.setAttribute(Qt.AA_DontShowIconsInMenus, False)
    app.setQuitOnLastWindowClosed(False)

    # finish app with ctrl+c
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    app.focusChanged.connect(focusChanged)

    config = Config()
    config.setLogLevel()

    db = Database(config.getConnectionString())
    db.create()
    db.update()

    mw = MainWindow()

    app.exec_()
    app.deleteLater()
    sys.exit(0)
Beispiel #6
0
    def __init__(self, config):
        super(MainWindow, self).__init__()
        self.config = Config(config)
        db = Database(self.config.getConnectionString())
        db.create()
        self.hosts = Hosts(db)

        # menu used for each host
        self.hostMenu = QMenu()
        self.hostMenu.addAction(QIcon(":/ico/edit.svg"), "Edit", self.editHost)
        self.hostMenu.addAction(QIcon(":/ico/remove.svg"), "Delete", self.deleteHost)
        actions.addActionWithScreenChose(
            self.hostMenu, self.connectFrameless, ":/ico/frameless.svg", "Connect frameless"
        )

        # setup main window
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # when top level changed, we changing dock title bar
        self.dockWidgetTileBar = DockWidgetTitleBar()
        self.ui.hostsDock.setTitleBarWidget(self.dockWidgetTileBar)
        self.ui.hostsDock.topLevelChanged.connect(self.dockLevelChanged)

        # set global menu
        self.globalMenu = QMenu()
        self.globalMenu.addAction(QIcon(":/ico/add.svg"), "Add host", self.addHost)
        # disable menu indicator
        self.ui.menu.setStyleSheet("QPushButton::menu-indicator {image: none;}")
        self.positionMenu = QMenu("Dock position")
        self.positionMenu.addAction("Left", lambda: self.setDockPosition(Qt.LeftDockWidgetArea))
        self.positionMenu.addAction("Right", lambda: self.setDockPosition(Qt.RightDockWidgetArea))
        self.positionMenu.addAction("Float", self.setDockFloat)
        self.globalMenu.addMenu(self.positionMenu)
        self.globalMenu.addAction("Change tray icon visibility", self.changeTrayIconVisibility)
        self.globalMenu.addAction("Quit", self.close)
        self.ui.menu.setMenu(self.globalMenu)

        # set events on hosts list
        self.ui.hostsList.itemDoubleClicked.connect(self.slotConnectHost)
        self.ui.hostsList.itemClicked.connect(self.slotShowHost)
        self.ui.hostsList.customContextMenuRequested.connect(self.slotShowHostContextMenu)

        # set tab widget
        self.tabWidget = MyTabWidget()
        self.setCentralWidget(self.tabWidget)

        # set tray icon
        self.tray = QSystemTrayIcon(QIcon(":/ico/myrdp.svg"))
        self.tray.activated.connect(self.trayActivated)

        self.trayMenu = QMenu()
        self.trayMenu.addAction("Hide tray icon", self.changeTrayIconVisibility)
        self.trayMenu.addAction("Quit", self.close)

        self.tray.setContextMenu(self.trayMenu)

        # host list
        self.ui.filter.textChanged.connect(self.setHostList)
        self.setHostList()
        self.restoreSettings()