def __init__(self): """ Create the default start state. The window contains a root widget into which is placed: * A status bar widget at the top, containing curent user / status information. * A main-view widget, itself containing a list view for sources and a place for details / message contents / forms. """ super().__init__() self.setWindowTitle(_("SecureDrop Client {}").format(__version__)) self.setWindowIcon(load_icon(self.icon)) self.widget = QWidget() widget_layout = QVBoxLayout() self.widget.setLayout(widget_layout) self.tool_bar = ToolBar(self.widget) self.main_view = MainView(self.widget) self.main_view.source_list.itemSelectionChanged.\ connect(self.on_source_changed) widget_layout.addWidget(self.tool_bar, 1) widget_layout.addWidget(self.main_view, 6) self.setCentralWidget(self.widget) self.show() self.autosize_window()
def test_ToolBar_on_refresh_clicked(): """ When refresh is clicked, the refresh logic from the controller is stated. """ tb = ToolBar(None) tb.controller = mock.MagicMock() tb.on_refresh_clicked() tb.controller.sync_api.assert_called_once_with()
def test_ToolBar_on_logout_clicked(): """ When logout is clicked, the logout logic from the controller is started. """ tb = ToolBar(None) tb.controller = mock.MagicMock() tb.on_logout_clicked() tb.controller.logout.assert_called_once_with()
def test_ToolBar_on_login_clicked(): """ When login button is clicked, the window activates the login form. """ tb = ToolBar(None) tb.window = mock.MagicMock() tb.on_login_clicked() tb.window.show_login.assert_called_once_with()
def test_ToolBar_sync_event(): """Toggles refresh button when syncing """ tb = ToolBar(None) tb._on_sync_event('syncing') assert not tb.refresh.isEnabled() tb._on_sync_event('synced') assert tb.refresh.isEnabled()
def test_ToolBar_setup(): """ Calling setup with references to a window and controller object results in them becoming attributes of self. """ tb = ToolBar(None) mock_window = mock.MagicMock() mock_controller = mock.MagicMock() tb.setup(mock_window, mock_controller) assert tb.window == mock_window assert tb.controller == mock_controller
def test_ToolBar_set_logged_out(): """ Ensure the UI reverts to the logged out state. """ tb = ToolBar(None) tb.user_state = mock.MagicMock() tb.login = mock.MagicMock() tb.logout = mock.MagicMock() tb.set_logged_out() tb.user_state.setText.assert_called_once_with('Logged out.') tb.login.setVisible.assert_called_once_with(True) tb.logout.setVisible.assert_called_once_with(False)
def test_ToolBar_set_logged_in_as(): """ Given a username, the user_state is updated and login/logout buttons are in the correct state. """ tb = ToolBar(None) tb.user_state = mock.MagicMock() tb.login = mock.MagicMock() tb.logout = mock.MagicMock() tb.set_logged_in_as('test') tb.user_state.setText.assert_called_once_with('Logged in as: test') tb.login.setVisible.assert_called_once_with(False) tb.logout.setVisible.assert_called_once_with(True)
def __init__(self, sdc_home: str): """ Create the default start state. The window contains a root widget into which is placed: * A status bar widget at the top, containing curent user / status information. * A main-view widget, itself containing a list view for sources and a place for details / message contents / forms. """ super().__init__() self.sdc_home = sdc_home self.setWindowTitle(_("SecureDrop Client {}").format(__version__)) self.setWindowIcon(load_icon(self.icon)) self.widget = QWidget() widget_layout = QVBoxLayout() self.widget.setLayout(widget_layout) self.setCentralWidget(self.widget) self.tool_bar = ToolBar(self.widget) self.main_view = MainView(self.widget) self.main_view.source_list.itemSelectionChanged.connect( self.on_source_changed) widget_layout.addWidget(self.tool_bar, 1) widget_layout.addWidget(self.main_view, 6) # Cache a dict of source.uuid -> SourceConversationWrapper # We do this to not create/destroy widgets constantly (because it causes UI "flicker") self.conversations = {} # Tracks which source is shown self.current_source = None self.autosize_window() self.show()
def test_ToolBar_init(): """ Ensure the ToolBar instance is correctly set up. """ tb = ToolBar(None) assert "Signed out." in tb.user_state.text()