Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sssoleileraaa committed Mar 20, 2019
1 parent ff56a3b commit 253ddd9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
12 changes: 7 additions & 5 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import arrow
import html
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtGui import QIcon, QPalette, QBrush, QColor
from PyQt5.QtGui import QIcon, QPalette, QBrush, QColor, QFont
from PyQt5.QtWidgets import QListWidget, QLabel, QWidget, QListWidgetItem, QHBoxLayout, \
QPushButton, QVBoxLayout, QLineEdit, QScrollArea, QDialog, QAction, QMenu, QMessageBox, \
QToolButton, QSizePolicy, QTextEdit, QStatusBar
Expand Down Expand Up @@ -95,17 +95,18 @@ def __init__(self, parent: QWidget):
palette = QPalette()
palette.setBrush(QPalette.Background, QBrush(load_image('hexes.svg')))
self.setPalette(palette)

self.user_icon = QLabel()
self.user_icon.setFont(QFont("Helvetica [Cronyx]", 16, QFont.Bold))
self.user_icon.hide()
self.user_state = QLabel()
self.user_state.setFont(QFont("Helvetica [Cronyx]", 12, QFont.Bold))
self.user_state.hide()
self.user_menu = JournalistMenuButton(self)
self.user_menu.hide()

self.login = QPushButton(_('SIGN IN'))
self.login.setFont(QFont("Helvetica [Cronyx]", 10))
self.login.setMinimumSize(200, 40)
self.login.setStyleSheet('{ border: none; }')
button_palette = self.login.palette()
button_palette.setColor(QPalette.Button, QColor('#eee'))
button_palette.setColor(QPalette.ButtonText, QColor('#000'))
Expand Down Expand Up @@ -150,13 +151,13 @@ def set_logged_in_as(self, username):
"""
self.login.hide()

self.user_icon.setText(_('<h3>jo</h3>'))
self.user_icon.setText(_('jo'))
self.user_icon.setStyleSheet('''
QLabel { background-color: #045fb4; color: cyan; padding: 10; border: 1px solid gray; }
''')
self.user_icon.show()

self.user_state.setText(_('<h3>{}</h3>').format(html.escape(username)))
self.user_state.setText(_('{}').format(html.escape(username)))
self.user_state.show()

self.user_menu.show()
Expand Down Expand Up @@ -952,6 +953,7 @@ class JournalistMenu(QMenu):
def __init__(self, parent):
super().__init__()
self.logout = QAction(_('SIGN OUT'))
self.logout.setFont(QFont("Helvetica [Cronyx]", 10))
self.addAction(self.logout)
self.logout.triggered.connect(parent.on_logout_clicked)

Expand Down
2 changes: 1 addition & 1 deletion tests/gui/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,4 @@ def test_set_status(mocker):
w = Window('mock')
w.status_bar = mocker.MagicMock()
w.set_status('hello', 100)
w.status_bar.showMessage.assert_called_once_with('hello', 100)
w.status_bar.set_message.assert_called_once_with('hello', 100)
65 changes: 33 additions & 32 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from securedrop_client import logic
from securedrop_client.gui.widgets import ToolBar, MainView, SourceList, SourceWidget, \
LoginDialog, SpeechBubble, ConversationWidget, MessageWidget, ReplyWidget, FileWidget, \
ConversationView, DeleteSourceMessageBox, DeleteSourceAction, SourceMenu, \
ConversationView, DeleteSourceMessageBox, DeleteSourceAction, SourceMenu, StatusBar, \
SourceConversationWrapper, ReplyBoxWidget


Expand All @@ -20,7 +20,10 @@ def test_ToolBar_init():
Ensure the ToolBar instance is correctly set up.
"""
tb = ToolBar(None)
assert "Signed out." in tb.user_state.text()
assert not tb.login.isHidden()
assert tb.user_icon.isHidden()
assert tb.user_state.isHidden()
assert tb.user_menu.isHidden()


def test_ToolBar_setup(mocker):
Expand All @@ -29,7 +32,6 @@ def test_ToolBar_setup(mocker):
them becoming attributes of self.
"""
tb = ToolBar(None)

mock_window = mocker.MagicMock()
mock_controller = mocker.MagicMock()

Expand All @@ -40,41 +42,40 @@ def test_ToolBar_setup(mocker):


def test_ToolBar_set_logged_in_as(mocker):
"""Given a username, the user_state is updated and login/logout
buttons, and refresh buttons, are in the correct state.
"""
When a user is logged in check that buttons and menus are in the correct state.
"""
tb = ToolBar(None)

tb.user_state = mocker.MagicMock()
tb.login = mocker.MagicMock()
tb.logout = mocker.MagicMock()
tb.refresh = mocker.MagicMock()
tb.user_icon = mocker.MagicMock()
tb.user_state = mocker.MagicMock()
tb.user_menu = mocker.MagicMock()

tb.set_logged_in_as('test')

tb.user_state.setText.assert_called_once_with('test')
tb.login.setVisible.assert_called_once_with(False)
tb.logout.setVisible.assert_called_once_with(True)
tb.refresh.setVisible.assert_called_once_with(True)
tb.login.hide.assert_called_once_with()
tb.user_icon.show.assert_called_once_with()
tb.user_state.show.assert_called_once_with()
tb.user_menu.show.assert_called_once_with()


def test_ToolBar_set_logged_out(mocker):
"""
Ensure the UI reverts to the logged out state.
When a user is logged out check that buttons and menus are in the correct state.
"""
tb = ToolBar(None)

tb.user_state = mocker.MagicMock()
tb.login = mocker.MagicMock()
tb.logout = mocker.MagicMock()
tb.refresh = mocker.MagicMock()
tb.user_icon = mocker.MagicMock()
tb.user_state = mocker.MagicMock()
tb.user_menu = mocker.MagicMock()

tb.set_logged_out()

tb.user_state.setText.assert_called_once_with('Signed out.')
tb.login.setVisible.assert_called_once_with(True)
tb.logout.setVisible.assert_called_once_with(False)
tb.refresh.setVisible.assert_called_once_with(False)
tb.login.show.assert_called_once_with()
tb.user_icon.hide.assert_called_once_with()
tb.user_state.hide.assert_called_once_with()
tb.user_menu.hide.assert_called_once_with()


def test_ToolBar_on_login_clicked(mocker):
Expand All @@ -97,25 +98,25 @@ def test_ToolBar_on_logout_clicked(mocker):
tb.controller.logout.assert_called_once_with()


def test_ToolBar_on_refresh_clicked(mocker):
def test_StatusBar_on_refresh_clicked(mocker):
"""
When refresh is clicked, the refresh logic from the controller is stated.
"""
tb = ToolBar(None)
tb.controller = mocker.MagicMock()
tb.on_refresh_clicked()
tb.controller.sync_api.assert_called_once_with()
sb = StatusBar()
sb.controller = mocker.MagicMock()
sb.on_refresh_clicked()
sb.controller.sync_api.assert_called_once_with()


def test_ToolBar_sync_event():
def test_StatusBar_sync_event():
"""Toggles refresh button when syncing
"""
tb = ToolBar(None)
tb._on_sync_event('syncing')
assert not tb.refresh.isEnabled()
sb = StatusBar()
sb._on_sync_event('syncing')
assert not sb.refresh.isEnabled()

tb._on_sync_event('synced')
assert tb.refresh.isEnabled()
sb._on_sync_event('synced')
assert sb.refresh.isEnabled()


def test_MainView_init():
Expand Down

0 comments on commit 253ddd9

Please sign in to comment.