Add tests for Chat, and fix the server_status message bar when in Chat mode

This commit is contained in:
Miguel Jacq 2021-05-10 15:05:16 +10:00
parent e067fc2963
commit b39162f33c
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
6 changed files with 124 additions and 11 deletions

View File

@ -101,6 +101,10 @@
"gui_status_indicator_receive_working": "Starting…", "gui_status_indicator_receive_working": "Starting…",
"gui_status_indicator_receive_scheduled": "Scheduled…", "gui_status_indicator_receive_scheduled": "Scheduled…",
"gui_status_indicator_receive_started": "Receiving", "gui_status_indicator_receive_started": "Receiving",
"gui_status_indicator_chat_stopped": "Ready to chat",
"gui_status_indicator_chat_working": "Starting…",
"gui_status_indicator_chat_scheduled": "Scheduled…",
"gui_status_indicator_chat_started": "Chatting",
"gui_file_info": "{} files, {}", "gui_file_info": "{} files, {}",
"gui_file_info_single": "{} file, {}", "gui_file_info_single": "{} file, {}",
"history_in_progress_tooltip": "{} in progress", "history_in_progress_tooltip": "{} in progress",
@ -198,4 +202,4 @@
"error_port_not_available": "OnionShare port not available", "error_port_not_available": "OnionShare port not available",
"history_receive_read_message_button": "Read Message", "history_receive_read_message_button": "Read Message",
"error_tor_protocol_error": "There was an error with Tor: {}" "error_tor_protocol_error": "There was an error with Tor: {}"
} }

View File

@ -452,20 +452,20 @@ class Tab(QtWidgets.QWidget):
# Chat mode # Chat mode
if self.chat_mode.server_status.status == ServerStatus.STATUS_STOPPED: if self.chat_mode.server_status.status == ServerStatus.STATUS_STOPPED:
self.set_server_status_indicator_stopped( self.set_server_status_indicator_stopped(
strings._("gui_status_indicator_receive_stopped") strings._("gui_status_indicator_chat_stopped")
) )
elif self.chat_mode.server_status.status == ServerStatus.STATUS_WORKING: elif self.chat_mode.server_status.status == ServerStatus.STATUS_WORKING:
if self.settings.get("general", "autostart_timer"): if self.settings.get("general", "autostart_timer"):
self.set_server_status_indicator_working( self.set_server_status_indicator_working(
strings._("gui_status_indicator_receive_scheduled") strings._("gui_status_indicator_chat_scheduled")
) )
else: else:
self.set_server_status_indicator_working( self.set_server_status_indicator_working(
strings._("gui_status_indicator_receive_working") strings._("gui_status_indicator_chat_working")
) )
elif self.chat_mode.server_status.status == ServerStatus.STATUS_STARTED: elif self.chat_mode.server_status.status == ServerStatus.STATUS_STARTED:
self.set_server_status_indicator_started( self.set_server_status_indicator_started(
strings._("gui_status_indicator_receive_started") strings._("gui_status_indicator_chat_started")
) )
def set_server_status_indicator_stopped(self, label_text): def set_server_status_indicator_stopped(self, label_text):

View File

@ -14,6 +14,7 @@ from onionshare import Application, MainWindow, GuiCommon
from onionshare.tab.mode.share_mode import ShareMode from onionshare.tab.mode.share_mode import ShareMode
from onionshare.tab.mode.receive_mode import ReceiveMode from onionshare.tab.mode.receive_mode import ReceiveMode
from onionshare.tab.mode.website_mode import WebsiteMode from onionshare.tab.mode.website_mode import WebsiteMode
from onionshare.tab.mode.chat_mode import ChatMode
from onionshare import strings from onionshare import strings
@ -133,6 +134,17 @@ class GuiBaseTest(unittest.TestCase):
return tab return tab
def new_chat_tab(self):
tab = self.gui.tabs.widget(0)
self.verify_new_tab(tab)
# Chat
tab.chat_button.click()
self.assertFalse(tab.new_tab.isVisible())
self.assertTrue(tab.chat_mode.isVisible())
return tab
def close_all_tabs(self): def close_all_tabs(self):
for _ in range(self.gui.tabs.count()): for _ in range(self.gui.tabs.count()):
tab = self.gui.tabs.widget(0) tab = self.gui.tabs.widget(0)
@ -361,6 +373,7 @@ class GuiBaseTest(unittest.TestCase):
and not tab.settings.get("share", "autostop_sharing") and not tab.settings.get("share", "autostop_sharing")
) )
or (type(tab.get_mode()) == WebsiteMode) or (type(tab.get_mode()) == WebsiteMode)
or (type(tab.get_mode()) == ChatMode)
): ):
tab.get_mode().server_status.server_button.click() tab.get_mode().server_status.server_button.click()
self.assertEqual(tab.get_mode().server_status.status, 0) self.assertEqual(tab.get_mode().server_status.status, 0)

View File

@ -2,4 +2,5 @@
pytest -v tests/test_gui_tabs.py && \ pytest -v tests/test_gui_tabs.py && \
pytest -v tests/test_gui_share.py && \ pytest -v tests/test_gui_share.py && \
pytest -v tests/test_gui_receive.py && \ pytest -v tests/test_gui_receive.py && \
pytest -v tests/test_gui_website.py pytest -v tests/test_gui_website.py && \
pytest -v tests/test_gui_chat.py

View File

@ -0,0 +1,75 @@
import requests
from PySide2 import QtTest
from .gui_base_test import GuiBaseTest
class TestChat(GuiBaseTest):
# Shared test methods
def view_chat(self, tab):
"""Test that we can view the chat room"""
url = f"http://127.0.0.1:{tab.app.port}/"
if tab.settings.get("general", "public"):
r = requests.get(url)
else:
r = requests.get(
url,
auth=requests.auth.HTTPBasicAuth(
"onionshare", tab.get_mode().server_status.web.password
),
)
QtTest.QTest.qWait(500, self.gui.qtapp)
self.assertTrue("Chat <b>requires JavaScript</b>" in r.text)
cookies_dict = requests.utils.dict_from_cookiejar(r.cookies)
self.assertTrue("session" in cookies_dict.keys())
def change_username(self, tab):
"""Test that we can change our username"""
url = f"http://127.0.0.1:{tab.app.port}/update-session-username"
data = {"username":"oniontest"}
if tab.settings.get("general", "public"):
r = requests.post(url, json=data)
else:
r = requests.post(
url,
json=data,
auth=requests.auth.HTTPBasicAuth(
"onionshare", tab.get_mode().server_status.web.password
),
)
QtTest.QTest.qWait(500, self.gui.qtapp)
jsonResponse = r.json()
self.assertTrue(jsonResponse["success"])
self.assertEqual(jsonResponse["username"], "oniontest")
def run_all_chat_mode_tests(self, tab):
"""Tests in chat mode after starting a chat"""
self.server_working_on_start_button_pressed(tab)
self.server_status_indicator_says_starting(tab)
self.server_is_started(tab, startup_time=500)
self.web_server_is_running(tab)
self.have_a_password(tab)
self.url_description_shown(tab)
self.have_copy_url_button(tab)
self.have_show_qr_code_button(tab)
self.server_status_indicator_says_started(tab)
self.view_chat(tab)
self.change_username(tab)
self.server_is_stopped(tab)
self.web_server_is_stopped(tab)
self.server_status_indicator_says_closed(tab)
# Tests
def test_chat(self):
"""
Test chat mode
"""
tab = self.new_chat_tab()
self.run_all_chat_mode_tests(tab)
self.close_all_tabs()

View File

@ -153,11 +153,21 @@ class TestTabs(GuiBaseTest):
self.gui.status_bar.server_status_label.text(), "Ready to share" self.gui.status_bar.server_status_label.text(), "Ready to share"
) )
# New tab, chat mode
self.gui.tabs.new_tab_button.click()
self.gui.tabs.widget(4).chat_button.click()
self.assertFalse(self.gui.tabs.widget(4).new_tab.isVisible())
self.assertTrue(self.gui.tabs.widget(4).chat_mode.isVisible())
self.assertEqual(
self.gui.status_bar.server_status_label.text(), "Ready to chat"
)
# Close tabs # Close tabs
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click() self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click() self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click() self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click() self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide).click()
def test_07_close_share_tab_while_server_started_should_warn(self): def test_07_close_share_tab_while_server_started_should_warn(self):
"""Closing a share mode tab when the server is running should throw a warning""" """Closing a share mode tab when the server is running should throw a warning"""
@ -165,7 +175,7 @@ class TestTabs(GuiBaseTest):
self.close_tab_with_active_server(tab) self.close_tab_with_active_server(tab)
def test_08_close_receive_tab_while_server_started_should_warn(self): def test_08_close_receive_tab_while_server_started_should_warn(self):
"""Closing a recieve mode tab when the server is running should throw a warning""" """Closing a receive mode tab when the server is running should throw a warning"""
tab = self.new_receive_tab() tab = self.new_receive_tab()
self.close_tab_with_active_server(tab) self.close_tab_with_active_server(tab)
@ -174,22 +184,32 @@ class TestTabs(GuiBaseTest):
tab = self.new_website_tab_with_files() tab = self.new_website_tab_with_files()
self.close_tab_with_active_server(tab) self.close_tab_with_active_server(tab)
def test_10_close_persistent_share_tab_shows_warning(self): def test_10_close_chat_tab_while_server_started_should_warn(self):
"""Closing a chat mode tab when the server is running should throw a warning"""
tab = self.new_chat_tab()
self.close_tab_with_active_server(tab)
def test_11_close_persistent_share_tab_shows_warning(self):
"""Closing a share mode tab that's persistent should show a warning""" """Closing a share mode tab that's persistent should show a warning"""
tab = self.new_share_tab_with_files() tab = self.new_share_tab_with_files()
self.close_persistent_tab(tab) self.close_persistent_tab(tab)
def test_11_close_persistent_receive_tab_shows_warning(self): def test_12_close_persistent_receive_tab_shows_warning(self):
"""Closing a receive mode tab that's persistent should show a warning""" """Closing a receive mode tab that's persistent should show a warning"""
tab = self.new_receive_tab() tab = self.new_receive_tab()
self.close_persistent_tab(tab) self.close_persistent_tab(tab)
def test_12_close_persistent_website_tab_shows_warning(self): def test_13_close_persistent_website_tab_shows_warning(self):
"""Closing a website mode tab that's persistent should show a warning""" """Closing a website mode tab that's persistent should show a warning"""
tab = self.new_website_tab_with_files() tab = self.new_website_tab_with_files()
self.close_persistent_tab(tab) self.close_persistent_tab(tab)
def test_13_quit_with_server_started_should_warn(self): def test_14_close_persistent_chat_tab_shows_warning(self):
"""Closing a chat mode tab that's persistent should show a warning"""
tab = self.new_chat_tab()
self.close_persistent_tab(tab)
def test_15_quit_with_server_started_should_warn(self):
"""Quitting OnionShare with any active servers should show a warning""" """Quitting OnionShare with any active servers should show a warning"""
tab = self.new_share_tab() tab = self.new_share_tab()