def show_login(self): """ Show the login form. """ self.login_dialog = LoginDialog(self) self.login_dialog.setup(self.controller) self.login_dialog.reset() self.login_dialog.exec()
def test_LoginDialog_setup(): """ The LoginView is correctly initialised. """ mock_controller = mock.MagicMock() ld = LoginDialog(None) ld.setup(mock_controller) assert ld.controller == mock_controller assert ld.title.text() == '<h1>Sign in</h1>'
def test_LoginDialog_error(): """ Any error message passed in is assigned as the text for the error label. """ mock_controller = mock.MagicMock() ld = LoginDialog(None) ld.setup(mock_controller) ld.error_label = mock.MagicMock() ld.error('foo') ld.error_label.setText.assert_called_once_with('foo')
def show_login(self): """ Show the login form. """ self.login_dialog = LoginDialog(self) self.login_dialog.move( QApplication.desktop().screen().rect().center() - self.rect().center()) self.login_dialog.setup(self.controller) self.login_dialog.reset() self.login_dialog.exec()
def setup(self, controller): """ Create references to the controller logic and instantiate the various views used in the UI. """ self.controller = controller # Reference the Client logic instance. self.tool_bar.setup(self, controller) self.status_bar = QStatusBar(self) self.setStatusBar(self.status_bar) self.set_status('Started SecureDrop Client. Please sign in.', 20000) self.login_dialog = LoginDialog(self) self.main_view.setup(self.controller)
def test_login_ensure_errors_displayed(qtbot, mocker): """ We see an error if incomplete credentials are supplied to the login dialog. """ w = Window() login_dialog = LoginDialog(w) login_dialog.show() assert login_dialog.error_bar.error_status_bar.text() == "" qtbot.keyClicks(login_dialog.username_field, "journalist") qtbot.mouseClick(login_dialog.submit, Qt.LeftButton) expected = "Please enter a username, passphrase and two-factor code." actual = login_dialog.error_bar.error_status_bar.text() assert actual == expected
def test_LoginDialog_validate_no_input(): """ If the user doesn't provide input, tell them and give guidance. """ mock_controller = mock.MagicMock() ld = LoginDialog(None) ld.setup(mock_controller) ld.username_field.text = mock.MagicMock(return_value='') ld.password_field.text = mock.MagicMock(return_value='') ld.tfa_field.text = mock.MagicMock(return_value='') ld.setDisabled = mock.MagicMock() ld.error = mock.MagicMock() ld.validate() assert ld.setDisabled.call_count == 2 assert ld.error.call_count == 1
def test_LoginDialog_validate_input_ok(): """ Valid input from the user causes a call to the controller's login method. """ mock_controller = mock.MagicMock() ld = LoginDialog(None) ld.setup(mock_controller) ld.username_field.text = mock.MagicMock(return_value='foo') ld.password_field.text = mock.MagicMock(return_value='bar') ld.tfa_field.text = mock.MagicMock(return_value='123456') ld.setDisabled = mock.MagicMock() ld.error = mock.MagicMock() ld.validate() assert ld.setDisabled.call_count == 1 assert ld.error.call_count == 0 mock_controller.login.assert_called_once_with('foo', 'bar', '123456')
def show_login(self): """ Show the login form. """ self.login_dialog = LoginDialog(self) # Always display the login dialog centered in the screen. screen_size = QDesktopWidget().screenGeometry() login_dialog_size = self.login_dialog.geometry() x_center = (screen_size.width() - login_dialog_size.width()) / 2 y_center = (screen_size.height() - login_dialog_size.height()) / 2 self.login_dialog.move(x_center, y_center) self.login_dialog.setup(self.controller) self.login_dialog.reset() self.login_dialog.exec()
def test_LoginDialog_reset(): """ Ensure the state of the login view is returned to the correct state. """ mock_controller = mock.MagicMock() ld = LoginDialog(None) ld.setup(mock_controller) ld.username_field = mock.MagicMock() ld.password_field = mock.MagicMock() ld.tfa_field = mock.MagicMock() ld.setDisabled = mock.MagicMock() ld.error_label = mock.MagicMock() ld.reset() ld.username_field.setText.assert_called_once_with('') ld.password_field.setText.assert_called_once_with('') ld.tfa_field.setText.assert_called_once_with('') ld.setDisabled.assert_called_once_with(False) ld.error_label.setText.assert_called_once_with('')
def test_LoginDialog_validate_too_short_password(mocker): """ If the password is too small, we show an informative error message. """ mock_controller = mocker.MagicMock() ld = LoginDialog(None) ld.setup(mock_controller) ld.username_field.text = mocker.MagicMock(return_value='foo') ld.password_field.text = mocker.MagicMock(return_value='bar') ld.tfa_field.text = mocker.MagicMock(return_value='123456') ld.setDisabled = mocker.MagicMock() ld.error = mocker.MagicMock() ld.validate() assert ld.setDisabled.call_count == 2 assert ld.error.call_count == 1 assert mock_controller.login.call_count == 0
def test_LoginDialog_validate_input_non_numeric_2fa(mocker): """ If the user doesn't provide numeric 2fa input, tell them and give guidance. """ mock_controller = mocker.MagicMock() ld = LoginDialog(None) ld.setup(mock_controller) ld.username_field.text = mocker.MagicMock(return_value='foo') ld.password_field.text = mocker.MagicMock(return_value='nicelongpassword') ld.tfa_field.text = mocker.MagicMock(return_value='baz') ld.setDisabled = mocker.MagicMock() ld.error = mocker.MagicMock() ld.validate() assert ld.setDisabled.call_count == 2 assert ld.error.call_count == 1 assert mock_controller.login.call_count == 0